6.12.112-rc1 review
Greg Kroah-Hartman
maintainerPATCH 805/877 smb: client: fix use-after-free of iface in cifs_try_adding_channels()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit d034e836eefd7ce75e588f7031cffbeec594f5ac ]
cifs_try_adding_channels() iterates ses->iface_list with list_for_each_entry_safe_from(), which captures the next entry (niface) under iface_lock. The loop body then drops iface_lock for the whole duration of cifs_ses_add_channel().
A concurrent interface refresh (SMB3_request_interfaces() -> parse_server_interfaces()) marks all ifaces inactive and removes and frees any that are not re-advertised via list_del() + kref_put(), where release_iface() is a bare kfree(). Since niface typically has no channel holding a reference, the list reference is its last and it can be freed inside the unlocked window. On continue, the iterator advance step then dereferences niface->iface_head.next, and the loop body reads iface->rdma_capable/is_active, both on freed memory.
Fix this by never keeping an unreferenced list pointer across the unlocked window. Each channel attempt now re-scans the list from the head under iface_lock, takes a kref on the selected candidate, and passes only that referenced candidate to cifs_ses_add_channel(). weight_fulfilled still tracks selection progress, so restarting the scan preserves the original weighted distribution and the weight_fulfilled-before-kref_put ordering on the failure path.
Add a per-pass attempts cap so a flapping interface refresh cannot keep the inner loop spinning within a single tries increment.
--- fs/smb/client/sess.c | 106 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 42 deletions(-)
fs/smb/client/sess.c +64 -42
@@ -175,9 +175,9 @@ int cifs_try_adding_channels(struct cifsint old_chan_count, new_chan_count;int left;int rc =0 ; -int tries =0 ; +int tries =0 , attempts;size_t iface_weight =0 , iface_min_speed =0 ; -struct cifs_server_iface *iface =NULL , *niface =NULL ; +struct cifs_server_iface *iface =NULL , *candidate =NULL ;struct cifs_server_iface *last_iface =NULL ;spin_lock (&ses->chan_lock);
@@ -223,67 +223,89 @@ int cifs_try_adding_channels(struct cifsbreak ; } -if (!iface) - iface = list_first_entry(&ses->iface_list, struct cifs_server_iface, - iface_head); last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface, iface_head); iface_min_speed = last_iface->speed; +spin_unlock (&ses->iface_lock); -list_for_each_entry_safe_from (iface, niface, &ses->iface_list, - iface_head) { -/* do not mix rdma and non-rdma interfaces */ -if (iface->rdma_capable != ses->server->rdma) -continue ; - -/* skip ifaces that are unusable */ -if (!iface->is_active || - (is_ses_using_iface (ses, iface) && - !iface->rss_capable)) -continue ; + attempts =0 ; +while (left >0 ) { +spin_lock (&ses->iface_lock); -/* check if we already allocated enough channels */ - iface_weight = iface->speed / iface_min_speed; +/* +* iface_lock must be dropped while opening a channel, +* and a concurrent interface refresh may remove and +* free entries during that window, so no list entry +* may be kept across it without a reference. Scan +* the list from the beginning each time and only pass +* a referenced candidate to cifs_ses_add_channel(); +* weight_fulfilled tracks the progress so that no +* iface is selected beyond its weight. +*/ + candidate =NULL ; +list_for_each_entry (iface, &ses->iface_list, iface_head) { +/* do not mix rdma and non-rdma interfaces */ +if (iface->rdma_capable != ses->server->rdma) +continue ; + +/* skip ifaces that are unusable */ +if (!iface->is_active || + (is_ses_using_iface (ses, iface) && + !iface->rss_capable)) +continue ; + +/* check if we already allocated enough channels */ + iface_weight = iface->speed / iface_min_speed; + +if (iface->weight_fulfilled >= iface_weight) +continue ; + +/* take ref before unlock */ +kref_get (&iface->refcount); + candidate = iface; +break ; + } -if (iface->weight_fulfilled >= iface_weight) -continue ; +if (!candidate) { +/* no usable iface. reset weight_fulfilled and start over */ +list_for_each_entry (iface, &ses->iface_list, iface_head) + iface->weight_fulfilled =0 ; +spin_unlock (&ses->iface_lock); +break ; + } -/* take ref before unlock */ -kref_get (&iface->refcount); + attempts++; +if (attempts >3 * ses->chan_max) { +kref_put (&candidate->refcount, release_iface); +spin_unlock (&ses->iface_lock); +break ; + }spin_unlock (&ses->iface_lock); - rc =cifs_ses_add_channel (ses, iface); + rc =cifs_ses_add_channel (ses, candidate);spin_lock (&ses->iface_lock);if (rc) {cifs_dbg (VFS ,"failed to open extra channel on iface:%pIS rc=%d\n" , - &iface->sockaddr, + &candidate->sockaddr, rc);/* failure to add chan should increase weight */ - iface->weight_fulfilled++; -kref_put (&iface->refcount, release_iface); + candidate->weight_fulfilled++; +kref_put (&candidate->refcount, release_iface); +spin_unlock (&ses->iface_lock);continue ; } - iface->num_channels++; - iface->weight_fulfilled++; + candidate->num_channels++; + candidate->weight_fulfilled++;cifs_info ("successfully opened new channel on iface:%pIS\n" , - &iface->sockaddr); -break ; - } - -/* reached end of list. reset weight_fulfilled and start over */ -if (list_entry_is_head (iface, &ses->iface_list, iface_head)) { -list_for_each_entry (iface, &ses->iface_list, iface_head) - iface->weight_fulfilled =0 ; + &candidate->sockaddr);spin_unlock (&ses->iface_lock); - iface =NULL ; -continue ; - } -spin_unlock (&ses->iface_lock); - left--; - new_chan_count++; + left--; + new_chan_count++; +break ; + } }return new_chan_count - old_chan_count;
Greg Kroah-Hartman
maintainerPATCH 806/877 drm/amdgpu: Failed to check various return code
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Martin <[email protected]>
[ Upstream commit 357ef5b3b7e98b4d21cb0abc1bde1140332c7eb8 ]
Clean up code to quiet the compiler on us failing to check the return code.
Stable-dep-of: 5155002b03b2 ("drm/amdgpu: fix rmmio iounmap skipped on device removal")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
@@ -368,7 +368,7 @@ void amdgpu_amdkfd_free_gtt_mem(struct a {struct amdgpu_bo **bo = (struct amdgpu_bo **) mem_obj; -amdgpu_bo_reserve (*bo, true); + (void )amdgpu_bo_reserve (*bo, true);amdgpu_bo_kunmap (*bo);amdgpu_bo_unpin (*bo);amdgpu_bo_unreserve (*bo);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7 -7
@@ -722,7 +722,7 @@ kfd_mem_dmaunmap_userptr(struct kgd_memreturn ;amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_CPU ); -ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); + (void )ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);dma_unmap_sgtable (adev->dev, ttm->sg, direction,0 );sg_free_table (ttm->sg);
@@ -771,7 +771,7 @@ kfd_mem_dmaunmap_sg_bo(struct kgd_mem *m }amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_CPU ); -ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); + (void )ttm_bo_validate (&bo->tbo, &bo->placement, &ctx); dir = mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ?DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;
@@ -981,7 +981,7 @@ unwind:if (!attachment[i])continue ;if (attachment[i]->bo_va) { -amdgpu_bo_reserve (bo[i], true); + (void )amdgpu_bo_reserve (bo[i], true);if (--attachment[i]->bo_va->ref_count ==0 )amdgpu_vm_bo_del (adev, attachment[i]->bo_va);amdgpu_bo_unreserve (bo[i]);
@@ -1251,11 +1251,11 @@ static int unmap_bo_from_gpuvm(struct kgreturn -EBUSY ; } -amdgpu_vm_bo_unmap (adev, bo_va, entry->va); + (void )amdgpu_vm_bo_unmap (adev, bo_va, entry->va); -amdgpu_vm_clear_freed (adev, vm, &bo_va->last_pt_update); + (void )amdgpu_vm_clear_freed (adev, vm, &bo_va->last_pt_update); -amdgpu_sync_fence (sync, bo_va->last_pt_update); + (void )amdgpu_sync_fence (sync, bo_va->last_pt_update);return 0 ; }
@@ -2358,7 +2358,7 @@ void amdgpu_amdkfd_gpuvm_unmap_gtt_bo_fr {struct amdgpu_bo *bo = mem->bo; -amdgpu_bo_reserve (bo, true); + (void )amdgpu_bo_reserve (bo, true);amdgpu_bo_kunmap (bo);amdgpu_bo_unpin (bo);amdgpu_bo_unreserve (bo);
Greg Kroah-Hartman
maintainerPATCH 807/877 drm/amdgpu: set the VM pointer to NULL in amdgpu_job_prepare
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian König <[email protected]>
[ Upstream commit 26c95e838e6301b0230430ec2fadeabfcb07aeda ]
As soon as the prepare phase is completed the VM might be released, better set it to NULL.
Stable-dep-of: 5155002b03b2 ("drm/amdgpu: fix rmmio iounmap skipped on device removal")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +7 -0
@@ -368,6 +368,13 @@ amdgpu_job_prepare_job(struct drm_sched_dev_err (ring->adev->dev,"Error getting VM ID (%d)\n" , r); goto error; } +/* +* The VM structure might be released after the VMID is +* assigned, we had multiple problems with people trying to use +* the VM pointer so better set it to NULL. +*/ +if (!fence) + job->vm =NULL ; }return fence;
Greg Kroah-Hartman
maintainerPATCH 808/877 drm/amdgpu/umsch: remove vpe test from umsch
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Saleemkhan Jamadar <[email protected]>
[ Upstream commit b0bebbe4ea2a25937d341fa1f2ab2cd8ce339cad ]
current test is more intrusive for user queue test
Stable-dep-of: 5155002b03b2 ("drm/amdgpu: fix rmmio iounmap skipped on device removal")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c | 459 --------------------------- 1 file changed, 1 insertion(+), 458 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c +1 -458
@@ -32,463 +32,6 @@#include "amdgpu_umsch_mm.h" #include "umsch_mm_v4_0.h" -struct umsch_mm_test_ctx_data { -uint8_t process_csa[PAGE_SIZE ]; -uint8_t vpe_ctx_csa[PAGE_SIZE ]; -uint8_t vcn_ctx_csa[PAGE_SIZE ]; -}; - -struct umsch_mm_test_mqd_data { -uint8_t vpe_mqd[PAGE_SIZE ]; -uint8_t vcn_mqd[PAGE_SIZE ]; -}; - -struct umsch_mm_test_ring_data { -uint8_t vpe_ring[PAGE_SIZE ]; -uint8_t vpe_ib[PAGE_SIZE ]; -uint8_t vcn_ring[PAGE_SIZE ]; -uint8_t vcn_ib[PAGE_SIZE ]; -}; - -struct umsch_mm_test_queue_info { -uint64_t mqd_addr; -uint64_t csa_addr; -uint32_t doorbell_offset_0; -uint32_t doorbell_offset_1; -enum UMSCH_SWIP_ENGINE_TYPE engine; -}; - -struct umsch_mm_test { -struct amdgpu_bo *ctx_data_obj; -uint64_t ctx_data_gpu_addr; -uint32_t *ctx_data_cpu_addr; - -struct amdgpu_bo *mqd_data_obj; -uint64_t mqd_data_gpu_addr; -uint32_t *mqd_data_cpu_addr; - -struct amdgpu_bo *ring_data_obj; -uint64_t ring_data_gpu_addr; -uint32_t *ring_data_cpu_addr; - - -struct amdgpu_vm *vm; -struct amdgpu_bo_va *bo_va; -uint32_t pasid; -uint32_t vm_cntx_cntl; -uint32_t num_queues; -}; - -static int map_ring_data (struct amdgpu_device *adev,struct amdgpu_vm *vm, -struct amdgpu_bo *bo,struct amdgpu_bo_va **bo_va, -uint64_t addr,uint32_t size) -{ -struct amdgpu_sync sync; -struct drm_exec exec; -int r; - -amdgpu_sync_create (&sync); - -drm_exec_init (&exec,0 ,0 ); - drm_exec_until_all_locked(&exec) { - r =drm_exec_lock_obj (&exec, &bo->tbo.base); -drm_exec_retry_on_contention (&exec); -if (unlikely (r)) - goto error_fini_exec; - - r =amdgpu_vm_lock_pd (vm, &exec,0 ); -drm_exec_retry_on_contention (&exec); -if (unlikely (r)) - goto error_fini_exec; - } - - *bo_va =amdgpu_vm_bo_add (adev, vm, bo); -if (!*bo_va) { - r = -ENOMEM ; - goto error_fini_exec; - } - - r =amdgpu_vm_bo_map (adev, *bo_va, addr,0 , size, -AMDGPU_PTE_READABLE |AMDGPU_PTE_WRITEABLE | -AMDGPU_PTE_EXECUTABLE ); - -if (r) - goto error_del_bo_va; - - - r =amdgpu_vm_bo_update (adev, *bo_va, false); -if (r) - goto error_del_bo_va; - -amdgpu_sync_fence (&sync, (*bo_va)->last_pt_update); - - r =amdgpu_vm_update_pdes (adev, vm, false); -if (r) - goto error_del_bo_va; - -amdgpu_sync_fence (&sync, vm->last_update); - -amdgpu_sync_wait (&sync, false); -drm_exec_fini (&exec); - -amdgpu_sync_free (&sync); - -return 0 ; - -error_del_bo_va: -amdgpu_vm_bo_del (adev, *bo_va); -amdgpu_sync_free (&sync); - -error_fini_exec: -drm_exec_fini (&exec); -amdgpu_sync_free (&sync); -return r; -} - -static int unmap_ring_data (struct amdgpu_device *adev,struct amdgpu_vm *vm, -struct amdgpu_bo *bo,struct amdgpu_bo_va *bo_va, -uint64_t addr) -{ -struct drm_exec exec; -long r; - -drm_exec_init (&exec,0 ,0 ); - drm_exec_until_all_locked(&exec) { - r =drm_exec_lock_obj (&exec, &bo->tbo.base); -drm_exec_retry_on_contention (&exec); -if (unlikely (r)) - goto out_unlock; - - r =amdgpu_vm_lock_pd (vm, &exec,0 ); -drm_exec_retry_on_contention (&exec); -if (unlikely (r)) - goto out_unlock; - } - - - r =amdgpu_vm_bo_unmap (adev, bo_va, addr); -if (r) - goto out_unlock; - -amdgpu_vm_bo_del (adev, bo_va); - -out_unlock: -drm_exec_fini (&exec); - -return r; -} - -static void setup_vpe_queue (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -struct MQD_INFO *mqd = (struct MQD_INFO *)test->mqd_data_cpu_addr; -uint64_t ring_gpu_addr = test->ring_data_gpu_addr; - - mqd->rb_base_lo = (ring_gpu_addr >>8 ); - mqd->rb_base_hi = (ring_gpu_addr >>40 ); - mqd->rb_size =PAGE_SIZE /4 ; - mqd->wptr_val =0 ; - mqd->rptr_val =0 ; - mqd->unmapped =1 ; - -if (adev->vpe.collaborate_mode) -memcpy (++mqd, test->mqd_data_cpu_addr,sizeof (struct MQD_INFO )); - - qinfo->mqd_addr = test->mqd_data_gpu_addr; - qinfo->csa_addr = test->ctx_data_gpu_addr + - offsetof(struct umsch_mm_test_ctx_data , vpe_ctx_csa); - qinfo->doorbell_offset_0 =0 ; - qinfo->doorbell_offset_1 =0 ; -} - -static void setup_vcn_queue (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -} - -static int add_test_queue (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -struct umsch_mm_add_queue_input queue_input = {}; -int r; - - queue_input.process_id = test->pasid; - queue_input.page_table_base_addr =amdgpu_gmc_pd_addr (test->vm->root.bo); - - queue_input.process_va_start =0 ; - queue_input.process_va_end = (adev->vm_manager.max_pfn -1 ) <<AMDGPU_GPU_PAGE_SHIFT ; - - queue_input.process_quantum =100000 ;/* 10ms */ - queue_input.process_csa_addr = test->ctx_data_gpu_addr + - offsetof(struct umsch_mm_test_ctx_data , process_csa); - - queue_input.context_quantum =10000 ;/* 1ms */ - queue_input.context_csa_addr = qinfo->csa_addr; - - queue_input.inprocess_context_priority =CONTEXT_PRIORITY_LEVEL_NORMAL ; - queue_input.context_global_priority_level =CONTEXT_PRIORITY_LEVEL_NORMAL ; - queue_input.doorbell_offset_0 = qinfo->doorbell_offset_0; - queue_input.doorbell_offset_1 = qinfo->doorbell_offset_1; - - queue_input.engine_type = qinfo->engine; - queue_input.mqd_addr = qinfo->mqd_addr; - queue_input.vm_context_cntl = test->vm_cntx_cntl; - -amdgpu_umsch_mm_lock (&adev->umsch_mm); - r = adev->umsch_mm.funcs->add_queue (&adev->umsch_mm, &queue_input); -amdgpu_umsch_mm_unlock (&adev->umsch_mm); -if (r) -return r; - -return 0 ; -} - -static int remove_test_queue (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -struct umsch_mm_remove_queue_input queue_input = {}; -int r; - - queue_input.doorbell_offset_0 = qinfo->doorbell_offset_0; - queue_input.doorbell_offset_1 = qinfo->doorbell_offset_1; - queue_input.context_csa_addr = qinfo->csa_addr; - -amdgpu_umsch_mm_lock (&adev->umsch_mm); - r = adev->umsch_mm.funcs->remove_queue (&adev->umsch_mm, &queue_input); -amdgpu_umsch_mm_unlock (&adev->umsch_mm); -if (r) -return r; - -return 0 ; -} - -static int submit_vpe_queue (struct amdgpu_device *adev,struct umsch_mm_test *test) -{ -struct MQD_INFO *mqd = (struct MQD_INFO *)test->mqd_data_cpu_addr; -uint32_t *ring = test->ring_data_cpu_addr + - offsetof(struct umsch_mm_test_ring_data , vpe_ring) /4 ; -uint32_t *ib = test->ring_data_cpu_addr + - offsetof(struct umsch_mm_test_ring_data , vpe_ib) /4 ; -uint64_t ib_gpu_addr = test->ring_data_gpu_addr + - offsetof(struct umsch_mm_test_ring_data , vpe_ib); -uint32_t *fence = ib +2048 /4 ; -uint64_t fence_gpu_addr = ib_gpu_addr +2048 ; -const uint32_t test_pattern =0xdeadbeef ; -int i; - - ib[0 ] =VPE_CMD_HEADER (VPE_CMD_OPCODE_FENCE ,0 ); - ib[1 ] =lower_32_bits (fence_gpu_addr); - ib[2 ] =upper_32_bits (fence_gpu_addr); - ib[3 ] = test_pattern; - - ring[0 ] =VPE_CMD_HEADER (VPE_CMD_OPCODE_INDIRECT ,0 ); - ring[1 ] = (ib_gpu_addr &0xffffffe0 ); - ring[2 ] =upper_32_bits (ib_gpu_addr); - ring[3 ] =4 ; - ring[4 ] =0 ; - ring[5 ] =0 ; - - mqd->wptr_val = (6 <<2 ); -if (adev->vpe.collaborate_mode) - (++mqd)->wptr_val = (6 <<2 ); - -WDOORBELL32 (adev->umsch_mm.agdb_index[CONTEXT_PRIORITY_LEVEL_NORMAL ], mqd->wptr_val); - -for (i =0 ; i < adev->usec_timeout; i++) { -if (*fence == test_pattern) -return 0 ; -udelay (1 ); - } - -dev_err (adev->dev,"vpe queue submission timeout\n" ); - -return -ETIMEDOUT ; -} - -static int submit_vcn_queue (struct amdgpu_device *adev,struct umsch_mm_test *test) -{ -return 0 ; -} - -static int setup_umsch_mm_test (struct amdgpu_device *adev, -struct umsch_mm_test *test) -{ -struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_MMHUB0 (0 )]; -int r; - - test->vm_cntx_cntl = hub->vm_cntx_cntl; - - test->vm =kzalloc (sizeof (*test->vm),GFP_KERNEL ); -if (!test->vm) { - r = -ENOMEM ; -return r; - } - - r =amdgpu_vm_init (adev, test->vm,-1 ); -if (r) - goto error_free_vm; - - r =amdgpu_pasid_alloc (16 ); -if (r <0 ) - goto error_fini_vm; - test->pasid = r; - - r =amdgpu_bo_create_kernel (adev,sizeof (struct umsch_mm_test_ctx_data ), -PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GTT , - &test->ctx_data_obj, - &test->ctx_data_gpu_addr, - (void **)&test->ctx_data_cpu_addr); -if (r) - goto error_free_pasid; - -memset (test->ctx_data_cpu_addr,0 ,sizeof (struct umsch_mm_test_ctx_data )); - - r =amdgpu_bo_create_kernel (adev,PAGE_SIZE , -PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GTT , - &test->mqd_data_obj, - &test->mqd_data_gpu_addr, - (void **)&test->mqd_data_cpu_addr); -if (r) - goto error_free_ctx_data_obj; - -memset (test->mqd_data_cpu_addr,0 ,PAGE_SIZE ); - - r =amdgpu_bo_create_kernel (adev,sizeof (struct umsch_mm_test_ring_data ), -PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GTT , - &test->ring_data_obj, -NULL , - (void **)&test->ring_data_cpu_addr); -if (r) - goto error_free_mqd_data_obj; - -memset (test->ring_data_cpu_addr,0 ,sizeof (struct umsch_mm_test_ring_data )); - - test->ring_data_gpu_addr =AMDGPU_VA_RESERVED_BOTTOM ; - r =map_ring_data (adev, test->vm, test->ring_data_obj, &test->bo_va, - test->ring_data_gpu_addr,sizeof (struct umsch_mm_test_ring_data )); -if (r) - goto error_free_ring_data_obj; - -return 0 ; - -error_free_ring_data_obj: -amdgpu_bo_free_kernel (&test->ring_data_obj,NULL , - (void **)&test->ring_data_cpu_addr); -error_free_mqd_data_obj: -amdgpu_bo_free_kernel (&test->mqd_data_obj, &test->mqd_data_gpu_addr, - (void **)&test->mqd_data_cpu_addr); -error_free_ctx_data_obj: -amdgpu_bo_free_kernel (&test->ctx_data_obj, &test->ctx_data_gpu_addr, - (void **)&test->ctx_data_cpu_addr); -error_free_pasid: -amdgpu_pasid_free (test->pasid); -error_fini_vm: -amdgpu_vm_fini (adev, test->vm); -error_free_vm: -kfree (test->vm); - -return r; -} - -static void cleanup_umsch_mm_test (struct amdgpu_device *adev, -struct umsch_mm_test *test) -{ -unmap_ring_data (adev, test->vm, test->ring_data_obj, - test->bo_va, test->ring_data_gpu_addr); -amdgpu_bo_free_kernel (&test->mqd_data_obj, &test->mqd_data_gpu_addr, - (void **)&test->mqd_data_cpu_addr); -amdgpu_bo_free_kernel (&test->ring_data_obj,NULL , - (void **)&test->ring_data_cpu_addr); -amdgpu_bo_free_kernel (&test->ctx_data_obj, &test->ctx_data_gpu_addr, - (void **)&test->ctx_data_cpu_addr); -amdgpu_pasid_free (test->pasid); -amdgpu_vm_fini (adev, test->vm); -kfree (test->vm); -} - -static int setup_test_queues (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -int i, r; - -for (i =0 ; i < test->num_queues; i++) { -if (qinfo[i].engine ==UMSCH_SWIP_ENGINE_TYPE_VPE ) -setup_vpe_queue (adev, test, &qinfo[i]); -else -setup_vcn_queue (adev, test, &qinfo[i]); - - r =add_test_queue (adev, test, &qinfo[i]); -if (r) -return r; - } - -return 0 ; -} - -static int submit_test_queues (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -int i, r; - -for (i =0 ; i < test->num_queues; i++) { -if (qinfo[i].engine ==UMSCH_SWIP_ENGINE_TYPE_VPE ) - r =submit_vpe_queue (adev, test); -else - r =submit_vcn_queue (adev, test); -if (r) -return r; - } - -return 0 ; -} - -static void cleanup_test_queues (struct amdgpu_device *adev, -struct umsch_mm_test *test, -struct umsch_mm_test_queue_info *qinfo) -{ -int i; - -for (i =0 ; i < test->num_queues; i++) -remove_test_queue (adev, test, &qinfo[i]); -} - -static int umsch_mm_test (struct amdgpu_device *adev) -{ -struct umsch_mm_test_queue_info qinfo[] = { - { .engine =UMSCH_SWIP_ENGINE_TYPE_VPE }, - }; -struct umsch_mm_test test = { .num_queues =ARRAY_SIZE (qinfo) }; -int r; - - r =setup_umsch_mm_test (adev, &test); -if (r) -return r; - - r =setup_test_queues (adev, &test, qinfo); -if (r) - goto cleanup; - - r =submit_test_queues (adev, &test, qinfo); -if (r) - goto cleanup; - -cleanup_test_queues (adev, &test, qinfo); -cleanup_umsch_mm_test (adev, &test); - -return 0 ; - -cleanup: -cleanup_test_queues (adev, &test, qinfo); -cleanup_umsch_mm_test (adev, &test); -return r; -} -int amdgpu_umsch_mm_submit_pkt (struct amdgpu_umsch_mm *umsch,void *pkt,int ndws) {struct amdgpu_ring *ring = &umsch->ring;
@@ -791,7 +334,7 @@ static int umsch_mm_late_init(void *handif (amdgpu_in_reset (adev) || adev->in_s0ix || adev->in_suspend)return 0 ; -return umsch_mm_test (adev); +return 0 ; }static int umsch_mm_sw_init (void *handle)
Greg Kroah-Hartman
maintainerPATCH 809/877 drm/amdgpu: use GFP_NOWAIT for memory allocations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian König <[email protected]>
[ Upstream commit 16590745b571c07869ef8958e0bbe44ab6f08d1f ]
In the critical submission path memory allocations can't wait for reclaim since that can potentially wait for submissions to finish.
Finally clean that up and mark most memory allocations in the critical path with GFP_NOWAIT. The only exception left is the dma_fence_array() used when no VMID is available, but that will be cleaned up later on.
Stable-dep-of: 5155002b03b2 ("drm/amdgpu: fix rmmio iounmap skipped on device removal")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 18 +++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 11 +++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 ++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h | 3 ++- 6 files changed, 32 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -4
@@ -491,7 +491,7 @@ static int vm_update_pds(struct amdgpu_vif (ret)return ret; -return amdgpu_sync_fence (sync, vm->last_update); +return amdgpu_sync_fence (sync, vm->last_update,GFP_KERNEL ); }static uint64_t get_pte_flags (struct amdgpu_device *adev,struct kgd_mem *mem)
@@ -1255,7 +1255,7 @@ static int unmap_bo_from_gpuvm(struct kg (void )amdgpu_vm_clear_freed (adev, vm, &bo_va->last_pt_update); - (void )amdgpu_sync_fence (sync, bo_va->last_pt_update); + (void )amdgpu_sync_fence (sync, bo_va->last_pt_update,GFP_KERNEL );return 0 ; }
@@ -1279,7 +1279,7 @@ static int update_gpuvm_pte(struct kgd_mreturn ret; } -return amdgpu_sync_fence (sync, bo_va->last_pt_update); +return amdgpu_sync_fence (sync, bo_va->last_pt_update,GFP_KERNEL ); } static int map_bo_to_gpuvm(struct kgd_mem *mem,
@@ -2971,7 +2971,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_ }dma_resv_for_each_fence (&cursor, bo->tbo.base.resv,DMA_RESV_USAGE_KERNEL , fence) { - ret =amdgpu_sync_fence (&sync_obj, fence); + ret =amdgpu_sync_fence (&sync_obj, fence,GFP_KERNEL );if (ret) {pr_debug ("Memory eviction: Sync BO fence failed. Try again\n" ); goto validate_map_fail;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +11 -7
@@ -462,7 +462,7 @@ static int amdgpu_cs_p2_dependencies(strdma_fence_put (old); } - r =amdgpu_sync_fence (&p->sync, fence); + r =amdgpu_sync_fence (&p->sync, fence,GFP_KERNEL );dma_fence_put (fence);if (r)return r;
@@ -484,7 +484,7 @@ static int amdgpu_syncobj_lookup_and_addreturn r; } - r =amdgpu_sync_fence (&p->sync, fence); + r =amdgpu_sync_fence (&p->sync, fence,GFP_KERNEL );dma_fence_put (fence);return r; }
@@ -1157,7 +1157,8 @@ static int amdgpu_cs_vm_handling(structif (r)return r; - r =amdgpu_sync_fence (&p->sync, fpriv->prt_va->last_pt_update); + r =amdgpu_sync_fence (&p->sync, fpriv->prt_va->last_pt_update, +GFP_KERNEL );if (r)return r;
@@ -1168,7 +1169,8 @@ static int amdgpu_cs_vm_handling(structif (r)return r; - r =amdgpu_sync_fence (&p->sync, bo_va->last_pt_update); + r =amdgpu_sync_fence (&p->sync, bo_va->last_pt_update, +GFP_KERNEL );if (r)return r; }
@@ -1187,7 +1189,8 @@ static int amdgpu_cs_vm_handling(structif (r)return r; - r =amdgpu_sync_fence (&p->sync, bo_va->last_pt_update); + r =amdgpu_sync_fence (&p->sync, bo_va->last_pt_update, +GFP_KERNEL );if (r)return r; }
@@ -1200,7 +1203,7 @@ static int amdgpu_cs_vm_handling(structif (r)return r; - r =amdgpu_sync_fence (&p->sync, vm->last_update); + r =amdgpu_sync_fence (&p->sync, vm->last_update,GFP_KERNEL );if (r)return r;
@@ -1267,7 +1270,8 @@ static int amdgpu_cs_sync_rings(struct acontinue ; } - r =amdgpu_sync_fence (&p->gang_leader->explicit_sync, fence); + r =amdgpu_sync_fence (&p->gang_leader->explicit_sync, fence, +GFP_KERNEL );dma_fence_put (fence);if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +7 -4
@@ -220,7 +220,7 @@ static int amdgpu_vmid_grab_idle(structreturn 0 ; } - fences =kmalloc_array (id_mgr->num_ids,sizeof (void *),GFP_KERNEL ); + fences =kmalloc_array (id_mgr->num_ids,sizeof (void *),GFP_NOWAIT );if (!fences)return -ENOMEM ;
@@ -337,7 +337,8 @@ static int amdgpu_vmid_grab_reserved(str/* Good we can use this VMID. Remember this submission as * user of the VMID. */ - r =amdgpu_sync_fence (&(*id)->active, &job->base.s_fence->finished); + r =amdgpu_sync_fence (&(*id)->active, &job->base.s_fence->finished, +GFP_NOWAIT );if (r)return r;
@@ -398,7 +399,8 @@ static int amdgpu_vmid_grab_used(struct* user of the VMID. */ r =amdgpu_sync_fence (&(*id)->active, - &job->base.s_fence->finished); + &job->base.s_fence->finished, +GFP_NOWAIT );if (r)return r;
@@ -450,7 +452,8 @@ int amdgpu_vmid_grab(struct amdgpu_vm *v/* Remember this submission as user of the VMID */ r =amdgpu_sync_fence (&id->active, - &job->base.s_fence->finished); + &job->base.s_fence->finished, +GFP_NOWAIT );if (r) goto error;
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +2 -2
@@ -1354,14 +1354,14 @@ int amdgpu_mes_ctx_map_meta_data(structDRM_ERROR ("failed to do vm_bo_update on meta data\n" ); goto error_del_bo_va; } -amdgpu_sync_fence (&sync, bo_va->last_pt_update); +amdgpu_sync_fence (&sync, bo_va->last_pt_update,GFP_KERNEL ); r =amdgpu_vm_update_pdes (adev, vm, false);if (r) {DRM_ERROR ("failed to update pdes on meta data\n" ); goto error_del_bo_va; } -amdgpu_sync_fence (&sync, vm->last_update); +amdgpu_sync_fence (&sync, vm->last_update,GFP_KERNEL );amdgpu_sync_wait (&sync, false);drm_exec_fini (&exec);
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +6 -5
@@ -152,7 +152,8 @@ static bool amdgpu_sync_add_later(struct* * Add the fence to the sync object. */ -int amdgpu_sync_fence (struct amdgpu_sync *sync,struct dma_fence *f) +int amdgpu_sync_fence (struct amdgpu_sync *sync,struct dma_fence *f, +gfp_t flags) {struct amdgpu_sync_entry *e;
@@ -162,7 +163,7 @@ int amdgpu_sync_fence(struct amdgpu_syncif (amdgpu_sync_add_later (sync, f))return 0 ; - e =kmem_cache_alloc (amdgpu_sync_slab,GFP_KERNEL ); + e =kmem_cache_alloc (amdgpu_sync_slab, flags);if (!e)return -ENOMEM ;
@@ -249,7 +250,7 @@ int amdgpu_sync_resv(struct amdgpu_devicstruct dma_fence *tmp =dma_fence_chain_contained (f);if (amdgpu_sync_test_fence (adev, mode, owner, tmp)) { - r =amdgpu_sync_fence (sync, f); + r =amdgpu_sync_fence (sync, f,GFP_KERNEL );dma_fence_put (f);if (r)return r;
@@ -281,7 +282,7 @@ int amdgpu_sync_kfd(struct amdgpu_sync *if (fence_owner !=AMDGPU_FENCE_OWNER_KFD )continue ; - r =amdgpu_sync_fence (sync, f); + r =amdgpu_sync_fence (sync, f,GFP_KERNEL );if (r)break ; }
@@ -388,7 +389,7 @@ int amdgpu_sync_clone(struct amdgpu_synchash_for_each_safe (source->fences, i, tmp, e, node) { f = e->fence;if (!dma_fence_is_signaled (f)) { - r =amdgpu_sync_fence (clone, f); + r =amdgpu_sync_fence (clone, f,GFP_KERNEL );if (r)return r; }else {
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h +2 -1
@@ -47,7 +47,8 @@ struct amdgpu_sync { };void amdgpu_sync_create (struct amdgpu_sync *sync); -int amdgpu_sync_fence (struct amdgpu_sync *sync,struct dma_fence *f); +int amdgpu_sync_fence (struct amdgpu_sync *sync,struct dma_fence *f, +gfp_t flags);int amdgpu_sync_resv (struct amdgpu_device *adev,struct amdgpu_sync *sync,struct dma_resv *resv,enum amdgpu_sync_mode mode,void *owner);
Greg Kroah-Hartman
maintainerPATCH 810/877 drm/amdgpu: fix rmmio iounmap skipped on device removal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengjun Yao <[email protected]>
[ Upstream commit 5155002b03b24ba3ef91c5c313b8cf0171b24904 ]
amdgpu_pci_remove() calls drm_dev_unplug() before fini_sw(), so drm_dev_enter() is already false there and the iounmap() guarded by it is skipped. This .remove path runs on both hot-unplug and plain rmmod, so the register BAR ioremap mapping leaks one instance per unload.
Unmap rmmio unconditionally (guard only on non-NULL) and drop the now unused idx.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -4
@@ -4776,7 +4776,6 @@ void amdgpu_device_fini_hw(struct amdgpuvoid amdgpu_device_fini_sw (struct amdgpu_device *adev) { -int idx;bool px;amdgpu_device_ip_fini (adev);
@@ -4814,11 +4813,9 @@ void amdgpu_device_fini_sw(struct amdgpuif ((adev->pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )vga_client_unregister (adev->pdev); -if (drm_dev_enter (adev_to_drm (adev), &idx)) { - +if (adev->rmmio) {iounmap (adev->rmmio); adev->rmmio =NULL ; -drm_dev_exit (idx); }if (IS_ENABLED (CONFIG_PERF_EVENTS ))
Greg Kroah-Hartman
maintainerPATCH 811/877 smb: client: fix OOB struct field reads in move_smb2_ea_to_cifs()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
[ Upstream commit eeb5ef6083e1cefa2ef75041b5597ff228b8d7bb ]
In move_smb2_ea_to_cifs(), the while (src_size > 0) loop condition is insufficient. It allows iteration to continue even if the remaining src_size is too small to contain a complete smb2_ea_info structure. Consequently, reads of ea_name_length and ea_value_length can occur out-of-bounds.
Fix this by ensuring src_size >= sizeof(*src) before attempting to read any structure fields. Additionally, reject any next_entry_offset that is smaller than sizeof(*src) or that would advance the pointer beyond the available buffer.
Note that for calls where the server returns a malformed EA list, the error returned to userspace changes from -ENODATA (getxattr) or -ERANGE (listxattr) to -EIO. This correctly signals a server protocol error rather than misleadingly indicating "attribute not present" or "output buffer too small".
--- fs/smb/client/smb2ops.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
fs/smb/client/smb2ops.c +16 -8
@@ -1057,8 +1057,9 @@ move_smb2_ea_to_cifs(char *dst, size_t dchar *name, *value;size_t buf_size = dst_size;size_t name_len, value_len, user_name_len; +u32 next_off; -while (src_size >0 ) { +while (src_size >=sizeof (*src)) { name_len = (size_t )src->ea_name_length; value_len = (size_t )le16_to_cpu (src->ea_value_length);
@@ -1113,14 +1114,21 @@ move_smb2_ea_to_cifs(char *dst, size_t dif (!src->next_entry_offset)break ; -if (src_size <le32_to_cpu (src->next_entry_offset)) { -/* stop before overrun buffer */ - rc = -ERANGE ; -break ; + next_off =le32_to_cpu (src->next_entry_offset); +if (next_off <sizeof (*src) || src_size < next_off) { +cifs_dbg (FYI ,"EA next_entry_offset %u out of range [%zu, %zu]\n" , + next_off,sizeof (*src), src_size); + rc = -EIO ; + goto out; + } + src_size -= next_off; + src = (void *)((char *)src + next_off); +if (src_size >0 && src_size <sizeof (*src)) { +cifs_dbg (FYI ,"EA next_entry_offset %u left truncated entry (%zu bytes)\n" , + next_off, src_size); + rc = -EIO ; + goto out; } - src_size -=le32_to_cpu (src->next_entry_offset); - src = (void *)((char *)src + -le32_to_cpu (src->next_entry_offset)); }/* didn't find the named attribute */
Greg Kroah-Hartman
maintainerPATCH 812/877 drm: add drm_memory_stats_is_zero
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunxiang Li <[email protected]>
[ Upstream commit fd265d9e0c3358e6b9fe244d8f5d2824fda1c0dc ]
Add a helper to check if the memory stats is zero, this will be used to check for memory accounting errors.
Stable-dep-of: 636139603b99 ("drm/amdgpu: hold a runtime PM reference for P2P dma-buf attachments")
--- drivers/gpu/drm/drm_file.c | 10 ++++++++++ include/drm/drm_file.h | 1 + 2 files changed, 11 insertions(+)
drivers/gpu/drm/drm_file.c +10 -0
@@ -840,6 +840,16 @@ static void print_size(struct drm_printedrm_printf (p,"drm-%s-%s:\t%llu%s\n" , stat, region, sz, units[u]); } +int drm_memory_stats_is_zero (const struct drm_memory_stats *stats) +{ +return (stats->shared ==0 && + stats->private ==0 && + stats->resident ==0 && + stats->purgeable ==0 && + stats->active ==0 ); +} +EXPORT_SYMBOL (drm_memory_stats_is_zero); +/** * drm_print_memory_stats - A helper to print memory stats * @p: The printer to print output to
include/drm/drm_file.h +1 -0
@@ -485,6 +485,7 @@ struct drm_memory_stats {enum drm_gem_object_status ; +int drm_memory_stats_is_zero (const struct drm_memory_stats *stats); void drm_print_memory_stats(struct drm_printer *p, const struct drm_memory_stats *stats, enum drm_gem_object_status supported_status,
Greg Kroah-Hartman
maintainerPATCH 813/877 drm/amdgpu: hold a runtime PM reference for P2P dma-buf attachments
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Lothian <[email protected]>
[ Upstream commit 636139603b99d2e3a18a46cf3f8d39313ce8042e ]
amdgpu_dma_buf_map() adds VRAM to the allowed domains for a peer2peer attachment. GTT is only a fallback placement when VRAM is preferred, so ttm_bo_validate() migrates the buffer from GTT into VRAM. While the exporting device is runtime suspended its SDMA rings are down and the move fails:
amdgpu: Move buffer fallback to memcpy unavailable
An importer on a second GPU reaches this holding no runtime PM reference on the exporter, e.g. a compositor on the APU submitting a frame that references a buffer exported by an idle dGPU:
amdgpu_cs_ioctl -> amdgpu_cs_parser_bos -> amdgpu_cs_bo_validate
-> ttm_bo_validate -> amdgpu_bo_move -> dma_buf_map_attachment
-> amdgpu_dma_buf_map -> ttm_bo_validate -> amdgpu_bo_movePinning a dma-buf into VRAM has the same requirement, which commit 030631e97b20 ("drm/amdgpu: revert "take runtime pm reference when we attach a buffer" v2") called out as the one case that would need the reference back.
Take it in attach and drop it in detach. pm_runtime_get_if_active() never resumes the device, so it cannot deadlock against the reservation taken during resume, which is why the old pm_runtime_get_sync() had to go. If the device is not active, clear peer2peer instead: the buffer then stays in GTT, which remains accessible while the GPU is powered down. If runtime PM is disabled, take a plain reference so the put in detach stays balanced.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +36 -0
@@ -41,6 +41,7 @@#include <linux/dma-buf.h> #include <linux/dma-fence-array.h> #include <linux/pci-p2pdma.h> +#include <linux/pm_runtime.h> static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops;
@@ -97,10 +98,44 @@ static int amdgpu_dma_buf_attach(struct pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0) attach->peer2peer = false; +/* +* Only allow P2P while the exporter is active, and keep it active +* until detach. With runtime PM disabled take a plain reference so +* the put in detach stays balanced. +*/ +if (attach->peer2peer) { +struct device *dev =adev_to_drm (adev)->dev; +int ret =pm_runtime_get_if_active (dev); + +if (!ret) + attach->peer2peer = false; +else if (ret <0 ) +pm_runtime_get_noresume (dev); + } +return 0 ; }/** +* amdgpu_dma_buf_detach - &dma_buf_ops.detach implementation +* +* @dmabuf: DMA-buf where we remove the attachment from +* @attach: the attachment to remove +* +* Drop the runtime PM reference taken in amdgpu_dma_buf_attach(). +*/ +static void amdgpu_dma_buf_detach (struct dma_buf *dmabuf, +struct dma_buf_attachment *attach) +{ +struct drm_gem_object *obj = dmabuf->priv; +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +if (attach->peer2peer) +pm_runtime_put_autosuspend (adev_to_drm (adev)->dev); +} + +/** * amdgpu_dma_buf_pin - &dma_buf_ops.pin implementation * * @attach: attachment to pin down
@@ -270,6 +305,7 @@ static int amdgpu_dma_buf_begin_cpu_acceconst struct dma_buf_ops amdgpu_dmabuf_ops = { .attach = amdgpu_dma_buf_attach, + .detach = amdgpu_dma_buf_detach, .pin = amdgpu_dma_buf_pin, .unpin = amdgpu_dma_buf_unpin, .map_dma_buf = amdgpu_dma_buf_map,
Greg Kroah-Hartman
maintainerPATCH 814/877 smb: client: fix reparse buffer bounds in cifs_query_reparse_point()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
[ Upstream commit 5f0306e731e2f46e91419eae57eee3a241c055e0 ]
In cifs_query_reparse_point(), the start >= end check before casting to struct reparse_data_buffer * only ensures the start pointer is within the response. It fails to verify that there is enough space remaining for the fixed 8-byte header of the structure.
If a server provides a DataOffset that leaves less than 8 bytes remaining, the check passes, but subsequent reads of ReparseTag and ReparseDataLength will occur out-of-bounds.
Fix this by ensuring the remaining space is at least the size of the reparse_data_buffer structure before accessing its fields.
--- fs/smb/client/cifssmb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifssmb.c +1 -1
@@ -2829,7 +2829,7 @@ int cifs_query_reparse_point(const unsig end =2 +get_bcc (&io_rsp->hdr) + (__u8 *)&io_rsp->ByteCount; start = (__u8 *)&io_rsp->hdr.Protocol + data_offset; -if (start >= end) { +if (start >= end || (size_t )(end - start) <sizeof (*buf)) { rc = -EIO ; goto error; }
Greg Kroah-Hartman
maintainerPATCH 815/877 smb/client: send lease break ACKs thru correct session for multiuser mounts
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: April Cardenas <[email protected]>
[ Upstream commit ebc5660132ddd244b57f03ed324922013a3d7363 ]
Currently, when cifs_oplock_break handles a break request from the server it searches for the appropriate tlink to handle the request but incorrectly uses the current fsuid as the search key, eventually causing read errors for users with multiuser mounts on NetApp. Fix this by using the tlink from the cfile struct instead to respond through the correct session.
As breaks are handled in a worker thread, the current fsuid isn't guaranteed to match the session that the break is intended for. This means that cifs_sb_tlink may search the rbtree using the wrong fsuid, and return a tlink with an incorrect session than
the lease break was intended for. As a result, the breaks
may be ACKed through an incorrect session.
While it seems that Samba/Windows Servers 2016-2025 ignore this as long as the lease key is correct, we ran into a case where if you're using NetApp ONTAP or Azure NetApp Files they will reject the ACK and return STATUS_LOCK_NOT_GRANTED errors on any future read requests a user may initiate through their still held open file handle, and the server will eventually close the file.
In the dmesg logs, the user may see errors like these:
CIFS: Status code returned 0xc0000128 STATUS_FILE_CLOSED
CIFS: VFS: Send error in read = -9
With a multiuser mount using NetApp, this issue is really easy for users to hit on a wide variety of kernel versions by attempting to copy a file from the share
to the local machine through GNOME Files/Nautilus.
This copy will always result in Nautilus throwing
a Bad File Descriptor error to the user and fail. With this fix, you can copy files through Nautilus without issue.
Quoted 1 line
Quoted 1 line
From looking at the traces, it seems that glib will
open the file first, and call listxattr before actually attempting to copy the file data. The listxattr call always triggers a break, causing the copy to fail.
The proposed fix returns to the way the client grabbed the tlink before commit e8f5f849ffce2 ("cifs: fix potential oops in cifs_oplock_break").
The bulk of that commit (checking for list empty) remains untouched, and I think the change to using cifs_sb_tlink was intended to avoid a NULL/ERR deference on the tlink as well as update the reference count.
I believe this fix should preserve those safety properties, but of course I'd appreciate any corrections here.
--- fs/smb/client/file.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/smb/client/file.c +2 -4
@@ -3067,8 +3067,6 @@ void cifs_oplock_break(struct work_struc struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo, oplock_break);struct inode *inode =d_inode (cfile->dentry); -struct super_block *sb = inode->i_sb; -struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifsInodeInfo *cinode =CIFS_I (inode);struct cifs_tcon *tcon;struct TCP_Server_Info *server;
@@ -3081,8 +3079,8 @@ void cifs_oplock_break(struct work_strucwait_on_bit (&cinode->flags,CIFS_INODE_PENDING_WRITERS ,TASK_UNINTERRUPTIBLE ); - tlink =cifs_sb_tlink (cifs_sb); -if (IS_ERR (tlink)) { + tlink =cifs_get_tlink (cfile->tlink); +if (IS_ERR_OR_NULL (tlink)) {/* drop the reference taken when the break was queued */ _cifsFileInfo_put (cfile, false/* do not wait for ourself */ , false); goto out;
Greg Kroah-Hartman
maintainerPATCH 816/877 arm64/boot: Disable trapping of PMZR_EL0 writes to EL2
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
commit 2bc6b218717b9d08f466f88209251d54bc09b207 upstream.
__init_el2_fgt2() writes one mask to both HDFGRTR2_EL2 and HDFGWTR2_EL2. PMZR_EL0 is write-only, so its trap bit, nPMZR_EL0, exists only in HDFGWTR2_EL2 and is therefore never set: a PMZR_EL0 write from the host traps to EL2, where the nVHE hypervisor has no handler and BUG()s. The kernel never writes PMZR_EL0, but kernel.perf_user_access=1 has the PMU driver set PMUSERENR_EL0.UEN for a task with a user-read event, so a write from EL0 reaches the trap and takes the host down without a panic message.
Accumulate the HDFGWTR2_EL2 bits separately, as __init_el2_fgt() already does for HDFGWTR_EL2, and set nPMZR_EL0 with the other FEAT_PMUv3p9 bits.
--- Documentation/arch/arm64/booting.rst | 1 + arch/arm64/include/asm/el2_setup.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
Documentation/arch/arm64/booting.rst +1 -0
@@ -400,6 +400,7 @@ Before jumping into the kernel, the foll - HDFGWTR2_EL2.nPMICNTR_EL0 (bit 2) must be initialised to 0b1. - HDFGWTR2_EL2.nPMICFILTR_EL0 (bit 3) must be initialised to 0b1. - HDFGWTR2_EL2.nPMUACR_EL1 (bit 4) must be initialised to 0b1. + - HDFGWTR2_EL2.nPMZR_EL0 (bit 21) must be initialised to 0b1. For CPUs with Memory Copy and Memory Set instructions (FEAT_MOPS):
arch/arm64/include/asm/el2_setup.h +7 -1
@@ -274,6 +274,7 @@ b.lt .Lskip_fgt2_\@mov x0, xzr + mov x2, xzr mrs x1, id_aa64dfr0_el1 ubfx x1, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 cmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9
@@ -282,9 +283,14 @@ orr x0, x0, #HDFGRTR2_EL2_nPMICNTR_EL0 orr x0, x0, #HDFGRTR2_EL2_nPMICFILTR_EL0 orr x0, x0, #HDFGRTR2_EL2_nPMUACR_EL1 + orr x2, x2, #HDFGWTR2_EL2_nPMICNTR_EL0 + orr x2, x2, #HDFGWTR2_EL2_nPMICFILTR_EL0 + orr x2, x2, #HDFGWTR2_EL2_nPMUACR_EL1 +/* PMZR_EL0 is write-only, so it has no read trap to disable */ + orr x2, x2, #HDFGWTR2_EL2_nPMZR_EL0 .Lskip_pmuv3p9_\@: msr_s SYS_HDFGRTR2_EL2, x0 - msr_s SYS_HDFGWTR2_EL2, x0 + msr_s SYS_HDFGWTR2_EL2, x2 msr_s SYS_HFGRTR2_EL2, xzr msr_s SYS_HFGWTR2_EL2, xzr msr_s SYS_HFGITR2_EL2, xzr
Greg Kroah-Hartman
maintainerPATCH 817/877 vlan: require the MAC header to be present in __vlan_insert_inner_tag()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit ab888242fce4f16f6c4d4c6ec53939ad36aa3b3a ]
__vlan_insert_inner_tag() only guarantees head room via skb_cow_head(), never that mac_len bytes of MAC header are present. Its ETH_HLEN wrappers - __vlan_insert_tag() under skb_vlan_push(), and vlan_insert_tag() under validate_xmit_vlan() on the generic transmit path - therefore rewrite the first 16 bytes at skb->data: a 12-byte memmove plus two 2-byte stores at +12 and +14. No caller supplies the bound, while the pop helpers use skb_ensure_writable()/pskb_may_pull().
An IFF_TUN device has hard_header_len == 0, so packet_snd() accepts a one-byte AF_PACKET/SOCK_RAW frame. The first vlan push only sets a hwaccel tag; the next - clsact "action vlan push" or bpf_skb_vlan_push() - enters the helper with skb->len still 1. The head comes from skbuff_small_head without __GFP_ZERO, so each push drags bytes from beyond skb->tail into the frame. After three the one-byte send leaves as 13 bytes carrying 11 bytes of uninitialised slab:
0000: 5a b3 62 12 80 88 ff ff 00 b3 62 12 81
`------------------------------'
only 0x5a was sent; the rest is slab, here the top 56 bits of a linear-map address
Require the MAC header the helper rewrites to be present, so such a frame is dropped rather than transmitted.
--- include/linux/if_vlan.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/if_vlan.h +3 -0
@@ -356,6 +356,9 @@ static inline int __vlan_insert_inner_ta {struct vlan_ethhdr *veth; +if (unlikely (!pskb_may_pull (skb, mac_len))) +return -EINVAL ; +if (skb_cow_head (skb,VLAN_HLEN ) <0 )return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 818/877 gpio: cdev: fix kernel stack leak to user-space in error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 1feb5d39b05afd902ed9fc902ec5b15be03a4bdb ]
If we fail to acquire the GPIO chip guard in gpio_desc_to_lineinfo(), we return immediately before zeroing the info struct we'll end up passing to the user-space later in lineinfo_get_v1(). This may leak the kernel stack contents. Make gpio_desc_to_lineinfo() return int so that the -ENODEV returned on failure to acquire the guard can be propagated to the callers.
While not strictly necessary: move the memset() before trying to acquire the SRCU read lock too for good measure.
--- drivers/gpio/gpiolib-cdev.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib-cdev.c +23 -7
@@ -2365,17 +2365,18 @@ static void gpio_v2_line_info_changed_to#endif /* CONFIG_GPIO_CDEV_V1 */ -static void gpio_desc_to_lineinfo (struct gpio_desc *desc, -struct gpio_v2_line_info *info) +static int gpio_desc_to_lineinfo (struct gpio_desc *desc, +struct gpio_v2_line_info *info) {unsigned long dflags;const char *label; +memset (info,0 ,sizeof (*info)); +CLASS (gpio_chip_guard, guard)(desc);if (!guard.gc) -return ; +return -ENODEV ; -memset (info,0 ,sizeof (*info)); info->offset =gpio_chip_hwgpio (desc);if (desc->name)
@@ -2440,6 +2441,8 @@ static void gpio_desc_to_lineinfo(struct info->flags |=GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME ; else if (test_bit(FLAG_EVENT_CLOCK_HTE, &dflags)) info->flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE; + +return 0 ; }struct gpio_chardev_data {
@@ -2490,6 +2493,7 @@ static int lineinfo_get_v1(struct gpio_cstruct gpio_desc *desc;struct gpioline_info lineinfo;struct gpio_v2_line_info lineinfo_v2; +int ret;if (copy_from_user (&lineinfo, ip,sizeof (lineinfo)))return -EFAULT ;
@@ -2507,7 +2511,10 @@ static int lineinfo_get_v1(struct gpio_creturn -EBUSY ; } -gpio_desc_to_lineinfo (desc, &lineinfo_v2); + ret =gpio_desc_to_lineinfo (desc, &lineinfo_v2); +if (ret) +return ret; +gpio_v2_line_info_to_v1 (&lineinfo_v2, &lineinfo);if (copy_to_user (ip, &lineinfo,sizeof (lineinfo))) {
@@ -2525,6 +2532,7 @@ static int lineinfo_get(struct gpio_char {struct gpio_desc *desc;struct gpio_v2_line_info lineinfo; +int ret;if (copy_from_user (&lineinfo, ip,sizeof (lineinfo)))return -EFAULT ;
@@ -2544,7 +2552,11 @@ static int lineinfo_get(struct gpio_charif (test_and_set_bit (lineinfo.offset, cdev->watched_lines))return -EBUSY ; } -gpio_desc_to_lineinfo (desc, &lineinfo); + + ret =gpio_desc_to_lineinfo (desc, &lineinfo); +if (ret) +return ret; +supinfo_to_lineinfo (desc, &lineinfo);if (copy_to_user (ip, &lineinfo,sizeof (lineinfo))) {
@@ -2637,7 +2649,11 @@ static int lineinfo_changed_notify(strucmemset (&chg,0 ,sizeof (chg)); chg.event_type = action; chg.timestamp_ns =ktime_get_ns (); -gpio_desc_to_lineinfo (desc, &chg.info); + + ret =gpio_desc_to_lineinfo (desc, &chg.info); +if (ret) +return NOTIFY_DONE ; +supinfo_to_lineinfo (desc, &chg.info); ret =kfifo_in_spinlocked (&cdev->events, &chg,1 , &cdev->wait.lock);
Greg Kroah-Hartman
maintainerPATCH 819/877 ipe: fix use-after-free when auditing a newly loaded policy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 9814077275eca36ebf8d510d2f076d235ff9f51a ]
new_policy() audits the policy after ipe_new_policyfs_node() publishes it and drops the new directory's inode lock. A concurrent delete can free the policy while ipe_audit_policy_load() is still using it.
Audit the successful load under that lock.
--- security/ipe/fs.c | 4 ---- security/ipe/policy_fs.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-)
security/ipe/fs.c +0 -4
@@ -155,10 +155,6 @@ static ssize_t new_policy(struct file *f } rc =ipe_new_policyfs_node (p); -if (rc) - goto out; - -ipe_audit_policy_load (p); out:if (rc <0 )
security/ipe/policy_fs.c +4 -0
@@ -12,6 +12,7 @@#include "policy.h" #include "eval.h" #include "fs.h" +#include "audit.h" #define MAX_VERSION_SIZE ARRAY_SIZE("65535.65535.65535")
@@ -463,6 +464,9 @@ int ipe_new_policyfs_node(struct ipe_polinode_lock (root); p->policyfs = policyfs; root->i_private = p; +/* Only audit signed policies from userspace */ +if (p->pkcs7) +ipe_audit_policy_load (p);inode_unlock (root);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 820/877 bna: prevent IOC timer rearm during teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 77b1718e39e5c9f6956fb60807326af20baf889d ]
bna: prevent IOC timer rearm during teardown
bnad_pci_remove() and the probe disable_ioceth path call timer_delete_sync() for ioc_timer, sem_timer and hb_timer, but not for iocpf_timer. bnad_iocpf_timeout() then takes bnad->bna_lock after free_netdev() has freed the struct bnad.
Deleting iocpf_timer last does not fix this. sem_timer and iocpf_timer rearm each other: bnad_iocpf_sem_timeout() can arm iocpf_timer, and bnad_iocpf_timeout() arms sem_timer from bfa_ioc_hw_sem_get() when the semaphore is busy. timer_delete_sync() only waits out its own callback. bnad_ioceth_disable() can time out and leave that callback live.
Shut all four IOC timers down with timer_shutdown_sync() on both paths, so a later mod_timer() is ignored.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/net/ethernet/brocade/bna/bnad.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/brocade/bna/bnad.c +10 -6
@@ -3725,9 +3725,11 @@ probe_uninit:bnad_res_free (bnad, &bnad->mod_res_info[0 ],BNA_MOD_RES_T_MAX ); disable_ioceth:bnad_ioceth_disable (bnad); -del_timer_sync (&bnad->bna.ioceth.ioc.ioc_timer); -del_timer_sync (&bnad->bna.ioceth.ioc.sem_timer); -del_timer_sync (&bnad->bna.ioceth.ioc.hb_timer); +/* The IOC timers rearm one another. Shut down all of them. */ +timer_shutdown_sync (&bnad->bna.ioceth.ioc.ioc_timer); +timer_shutdown_sync (&bnad->bna.ioceth.ioc.sem_timer); +timer_shutdown_sync (&bnad->bna.ioceth.ioc.hb_timer); +timer_shutdown_sync (&bnad->bna.ioceth.ioc.iocpf_timer);spin_lock_irqsave (&bnad->bna_lock, flags);bna_uninit (bna);spin_unlock_irqrestore (&bnad->bna_lock, flags);
@@ -3768,9 +3770,11 @@ bnad_pci_remove(struct pci_dev *pdev)mutex_lock (&bnad->conf_mutex);bnad_ioceth_disable (bnad); -del_timer_sync (&bnad->bna.ioceth.ioc.ioc_timer); -del_timer_sync (&bnad->bna.ioceth.ioc.sem_timer); -del_timer_sync (&bnad->bna.ioceth.ioc.hb_timer); +/* The IOC timers rearm one another. Shut down all of them. */ +timer_shutdown_sync (&bnad->bna.ioceth.ioc.ioc_timer); +timer_shutdown_sync (&bnad->bna.ioceth.ioc.sem_timer); +timer_shutdown_sync (&bnad->bna.ioceth.ioc.hb_timer); +timer_shutdown_sync (&bnad->bna.ioceth.ioc.iocpf_timer);spin_lock_irqsave (&bnad->bna_lock, flags);bna_uninit (bna);spin_unlock_irqrestore (&bnad->bna_lock, flags);
Greg Kroah-Hartman
maintainerPATCH 821/877 i2c: qcom-geni: Fix hardcoded clock index in SE_GENI_CLK_SEL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viken Dadhaniya <[email protected]>
[ Upstream commit cb97bf3d4f91453b881acaf8e9f0cc47bb40b604 ]
qcom_geni_i2c_conf() writes a hardcoded 0 to SE_GENI_CLK_SEL, which selects an index from the hardware clock performance table. This always picks the first table entry regardless of the actual source clock configuration. On platforms where the matching entry is not at index 0, the wrong source clock divider is active and the I2C bus runs at an incorrect frequency.
Use geni_se_clk_freq_match() in geni_i2c_clk_map_idx() to find the performance table index for the source clock (32 MHz or 19.2 MHz). Store the resolved index in a new clk_idx field in geni_i2c_dev and write it to SE_GENI_CLK_SEL instead of the hardcoded 0.
--- drivers/i2c/busses/i2c-qcom-geni.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-qcom-geni.c +28 -5
@@ -77,6 +77,8 @@ enum geni_i2c_err_code {#define XFER_TIMEOUT HZ#define RST_TIMEOUT HZ +#define GENI_SE_CLK_19P2MHZ 19200000UL +struct geni_i2c_dev {struct geni_se se;u32 tx_wm;
@@ -91,6 +93,7 @@ struct geni_i2c_dev {struct clk *core_clk;u32 clk_freq_out;const struct geni_i2c_clk_fld *clk_fld; +u32 clk_idx;int suspended;void *dma_buf;size_t xfer_len;
@@ -157,13 +160,36 @@ static int geni_i2c_clk_map_idx(struct g {int i;const struct geni_i2c_clk_fld *itr = geni_i2c_clk_map; +unsigned long res_freq; + +/* +* Frequency counters are calibrated for a 19.2 MHz source clock +* and are not valid for any multiple of it (e.g. 38.4 MHz). +* Use exact=true and verify res_freq matches req_freq literally +* to reject harmonics that would produce an incorrect I2C frequency. +* ACPI systems have firmware-managed clocks and retain the default index. +*/ +if (!has_acpi_companion (gi2c->se.dev) && + (geni_se_clk_freq_match (&gi2c->se,GENI_SE_CLK_19P2MHZ , + &gi2c->clk_idx, &res_freq, true) || + res_freq !=GENI_SE_CLK_19P2MHZ )) { +dev_err (gi2c->se.dev, +"Unsupported SE source clock: must be exactly 19.2 MHz\n" ); +return -EINVAL ; + }for (i =0 ; i <ARRAY_SIZE (geni_i2c_clk_map); i++, itr++) {if (itr->clk_freq_out == gi2c->clk_freq_out) { gi2c->clk_fld = itr; +dev_dbg (gi2c->se.dev, +"I2C clk selected: freq: %u Hz, clk_idx: %u\n" , + gi2c->clk_freq_out, gi2c->clk_idx);return 0 ; } } + +dev_err (gi2c->se.dev,"Unsupported I2C output frequency %u Hz\n" , gi2c->clk_freq_out); +return -EINVAL ; }
@@ -172,7 +198,7 @@ static void qcom_geni_i2c_conf(struct geconst struct geni_i2c_clk_fld *itr = gi2c->clk_fld;u32 val; -writel_relaxed (0 , gi2c->se.base +SE_GENI_CLK_SEL ); +writel_relaxed (gi2c->clk_idx, gi2c->se.base +SE_GENI_CLK_SEL ); val = (itr->clk_div <<CLK_DIV_SHFT ) |SER_CLK_EN ;writel_relaxed (val, gi2c->se.base +GENI_SER_M_CLK_CFG );
@@ -809,11 +835,8 @@ static int geni_i2c_probe(struct platforreturn gi2c->irq; ret =geni_i2c_clk_map_idx (gi2c); -if (ret) { -dev_err (dev,"Invalid clk frequency %d Hz: %d\n" , - gi2c->clk_freq_out, ret); +if (ret)return ret; - } gi2c->adap.algo = &geni_i2c_algo;init_completion (&gi2c->done);
Greg Kroah-Hartman
maintainerPATCH 822/877 drm/amdgpu: Fix acpi device leak in amdgpu_acpi_enumerate_xcc()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit a997baa61179b450bd55c4810c7ccfed3b753a54 ]
amdgpu_acpi_enumerate_xcc() looks up each XCC ACPI device with acpi_dev_get_first_match_dev(), which takes a reference to the device. The reference is dropped with acpi_dev_put() after the XCC info is initialized, but if the kzalloc_obj() allocation of the XCC info fails the function returns -ENOMEM without releasing the reference, leaking the last reference to the ACPI device.
Drop the ACPI device reference on the allocation failure path before returning.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +1 -0
@@ -1114,6 +1114,7 @@ static int amdgpu_acpi_enumerate_xcc(voi GFP_KERNEL);if (!xcc_info) {DRM_ERROR ("Failed to allocate memory for xcc info\n" ); +acpi_dev_put (acpi_dev);return -ENOMEM ; }
Greg Kroah-Hartman
maintainerPATCH 823/877 drm/client: Pass force parameter to client restore
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit 943240d342f148896733eb6c7b223a08aa1f520a ]
Add force parameter to client restore and pass value through the layers. The only currently used value is false.
If force is true, the client should restore its display even if it does not hold the DRM master lock. This is be required for emergency output, such as sysrq.
While at it, inline drm_fb_helper_lastclose(), which is a trivial wrapper around drm_fb_helper_restore_fbdev_mode_unlocked().
Backport to 6.12: client event handling is still in drm_client.c and its declarations are in drm_client.h, so apply the force changes there without introducing the later drm_client_event files. Keep the fbdev client at its existing path.
Propagate force through the older DMA, shmem, TTM, Armada, Exynos, GMA500, i915, MSM, OMAP, Radeon and Tegra restore callbacks, including i915's restore helper and the existing !DRM_FBDEV_EMULATION stub. Inline lastclose calls in the older clients using dev->fb_helper to preserve their existing helper selection and initialization checks. No functions are added.
The generic fbdev restore callback now has the upstream context needed by 1fca688e9443003e33cf30453e7a7560367656c9.
[ sashal: Reduced backport -- upstream 943240d342f14 touches 7 file(s), this
backport carries 17. Not backported here:
drivers/gpu/drm/clients/drm_fbdev_client.c drivers/gpu/drm/drm_client_event.c include/drm/drm_client_event.h
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 1fca688e9443 ("drm/client: fix restore of partially initialized client")
--- drivers/gpu/drm/armada/armada_fbdev.c | 4 ++-- drivers/gpu/drm/drm_client.c | 4 ++-- drivers/gpu/drm/drm_fb_helper.c | 24 ++++++------------------ drivers/gpu/drm/drm_fbdev_client.c | 6 ++++-- drivers/gpu/drm/drm_fbdev_dma.c | 4 ++-- drivers/gpu/drm/drm_fbdev_shmem.c | 4 ++-- drivers/gpu/drm/drm_fbdev_ttm.c | 4 ++-- drivers/gpu/drm/drm_file.c | 2 +- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 4 ++-- drivers/gpu/drm/gma500/fbdev.c | 4 ++-- drivers/gpu/drm/i915/display/intel_fbdev.c | 8 ++++---- drivers/gpu/drm/msm/msm_fbdev.c | 4 ++-- drivers/gpu/drm/omapdrm/omap_fbdev.c | 4 ++-- drivers/gpu/drm/radeon/radeon_fbdev.c | 4 ++-- drivers/gpu/drm/tegra/fbdev.c | 4 ++-- include/drm/drm_client.h | 10 ++++++---- include/drm/drm_fb_helper.h | 11 ++++------- 17 files changed, 47 insertions(+), 58 deletions(-)
drivers/gpu/drm/armada/armada_fbdev.c +2 -2
@@ -137,9 +137,9 @@ static void armada_fbdev_client_unregist } } -static int armada_fbdev_client_restore (struct drm_client_dev *client) +static int armada_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/drm_client.c +2 -2
@@ -244,7 +244,7 @@ void drm_client_dev_hotplug(struct drm_d }EXPORT_SYMBOL (drm_client_dev_hotplug); -void drm_client_dev_restore (struct drm_device *dev) +void drm_client_dev_restore (struct drm_device *dev,bool force) {struct drm_client_dev *client;int ret;
@@ -257,7 +257,7 @@ void drm_client_dev_restore(struct drm_dif (!client->funcs || !client->funcs->restore)continue ; - ret = client->funcs->restore (client); + ret = client->funcs->restore (client, force);drm_dbg_kms (dev,"%s: ret=%d\n" , client->name, ret);if (!ret)/* The first one to return zero gets the privilege to restore */ break ;
drivers/gpu/drm/drm_fb_helper.c +6 -18
@@ -249,6 +249,7 @@ __drm_fb_helper_restore_fbdev_mode_unloc/** * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration * @fb_helper: driver-allocated fbdev helper, can be NULL +* @force: ignore present DRM master * * This helper should be called from fbdev emulation's &drm_client_funcs.restore * callback. It ensures that the user isn't greeted with a black screen when the
@@ -257,9 +258,9 @@ __drm_fb_helper_restore_fbdev_mode_unloc* Returns: * 0 on success, or a negative errno code otherwise. */ -int drm_fb_helper_restore_fbdev_mode_unlocked (struct drm_fb_helper *fb_helper) +int drm_fb_helper_restore_fbdev_mode_unlocked (struct drm_fb_helper *fb_helper,bool force) { -return __drm_fb_helper_restore_fbdev_mode_unlocked (fb_helper, false); +return __drm_fb_helper_restore_fbdev_mode_unlocked (fb_helper, force); }EXPORT_SYMBOL (drm_fb_helper_restore_fbdev_mode_unlocked);
@@ -1306,9 +1307,9 @@ int drm_fb_helper_set_par(struct fb_info* the KDSET IOCTL with KD_TEXT, and only after that drops the master * status when exiting. * -* In the past this was caught by drm_fb_helper_lastclose(), but on -* modern systems where logind always keeps a drm fd open to orchestrate -* the vt switching, this doesn't work. +* In the past this was caught by drm_fb_helper_restore_fbdev_mode_unlocked(), +* but on modern systems where logind always keeps a drm fd open to +* orchestrate the vt switching, this doesn't work. * * To not break the userspace ABI we have this special case here, which * is only used for the above case. Everything else uses the normal
@@ -1936,16 +1937,3 @@ int drm_fb_helper_hotplug_event(struct dreturn 0 ; }EXPORT_SYMBOL (drm_fb_helper_hotplug_event); - -/** -* drm_fb_helper_lastclose - DRM driver lastclose helper for fbdev emulation -* @dev: DRM device -* -* This function is obsolete. Call drm_fb_helper_restore_fbdev_mode_unlocked() -* instead. -*/ -void drm_fb_helper_lastclose (struct drm_device *dev) -{ -drm_fb_helper_restore_fbdev_mode_unlocked (dev->fb_helper); -} -EXPORT_SYMBOL (drm_fb_helper_lastclose);
drivers/gpu/drm/drm_fbdev_client.c +4 -2
@@ -25,9 +25,11 @@ static void drm_fbdev_client_unregister( } } -static int drm_fbdev_client_restore (struct drm_client_dev *client) +static int drm_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +struct drm_fb_helper *fb_helper =drm_fb_helper_from_client (client); + +drm_fb_helper_restore_fbdev_mode_unlocked (fb_helper, force);return 0 ; }
drivers/gpu/drm/drm_fbdev_dma.c +2 -2
@@ -350,9 +350,9 @@ static void drm_fbdev_dma_client_unregis } } -static int drm_fbdev_dma_client_restore (struct drm_client_dev *client) +static int drm_fbdev_dma_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/drm_fbdev_shmem.c +2 -2
@@ -216,9 +216,9 @@ static void drm_fbdev_shmem_client_unreg } } -static int drm_fbdev_shmem_client_restore (struct drm_client_dev *client) +static int drm_fbdev_shmem_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/drm_fbdev_ttm.c +2 -2
@@ -257,9 +257,9 @@ static void drm_fbdev_ttm_client_unregis } } -static int drm_fbdev_ttm_client_restore (struct drm_client_dev *client) +static int drm_fbdev_ttm_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/drm_file.c +1 -1
@@ -388,7 +388,7 @@ EXPORT_SYMBOL(drm_open);static void drm_lastclose (struct drm_device *dev) { -drm_client_dev_restore (dev); +drm_client_dev_restore (dev, false);if (dev_is_pci (dev->dev))vga_switcheroo_process_delayed_switch ();
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +2 -2
@@ -149,9 +149,9 @@ static void exynos_drm_fbdev_client_unre } } -static int exynos_drm_fbdev_client_restore (struct drm_client_dev *client) +static int exynos_drm_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/gma500/fbdev.c +2 -2
@@ -214,9 +214,9 @@ static void psb_fbdev_client_unregister( } } -static int psb_fbdev_client_restore (struct drm_client_dev *client) +static int psb_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/i915/display/intel_fbdev.c +4 -4
@@ -555,7 +555,7 @@ static int intel_fbdev_output_poll_changreturn 0 ; } -static int intel_fbdev_restore_mode (struct drm_i915_private *dev_priv) +static int intel_fbdev_restore_mode (struct drm_i915_private *dev_priv,bool force) {struct intel_fbdev *ifbdev = dev_priv->display.fbdev.fbdev;int ret;
@@ -566,7 +566,7 @@ static int intel_fbdev_restore_mode(struif (!ifbdev->vma)return -ENOMEM ; - ret =drm_fb_helper_restore_fbdev_mode_unlocked (&ifbdev->helper); + ret =drm_fb_helper_restore_fbdev_mode_unlocked (&ifbdev->helper, force);if (ret)return ret;
@@ -592,12 +592,12 @@ static void intel_fbdev_client_unregiste } } -static int intel_fbdev_client_restore (struct drm_client_dev *client) +static int intel_fbdev_client_restore (struct drm_client_dev *client,bool force) {struct drm_i915_private *dev_priv =to_i915 (client->dev);int ret; - ret =intel_fbdev_restore_mode (dev_priv); + ret =intel_fbdev_restore_mode (dev_priv, force);if (ret)return ret;
drivers/gpu/drm/msm/msm_fbdev.c +2 -2
@@ -173,9 +173,9 @@ static void msm_fbdev_client_unregister( } } -static int msm_fbdev_client_restore (struct drm_client_dev *client) +static int msm_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/omapdrm/omap_fbdev.c +2 -2
@@ -289,9 +289,9 @@ static void omap_fbdev_client_unregister } } -static int omap_fbdev_client_restore (struct drm_client_dev *client) +static int omap_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
drivers/gpu/drm/radeon/radeon_fbdev.c +2 -2
@@ -300,9 +300,9 @@ static void radeon_fbdev_client_unregist } } -static int radeon_fbdev_client_restore (struct drm_client_dev *client) +static int radeon_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);vga_switcheroo_process_delayed_switch ();return 0 ;
drivers/gpu/drm/tegra/fbdev.c +2 -2
@@ -154,9 +154,9 @@ static void tegra_fbdev_client_unregiste } } -static int tegra_fbdev_client_restore (struct drm_client_dev *client) +static int tegra_fbdev_client_restore (struct drm_client_dev *client,bool force) { -drm_fb_helper_lastclose (client->dev); +drm_fb_helper_restore_fbdev_mode_unlocked (client->dev->fb_helper, force);return 0 ; }
include/drm/drm_client.h +6 -4
@@ -47,12 +47,14 @@ struct drm_client_funcs {* * Note that the core does not guarantee exclusion against concurrent * drm_open(). Clients need to ensure this themselves, for example by -* using drm_master_internal_acquire() and -* drm_master_internal_release(). +* using drm_master_internal_acquire() and drm_master_internal_release(). +* +* If the caller passes force, the client should ignore any present DRM +* master and restore the display anyway. * * This callback is optional. */ -int (*restore)(struct drm_client_dev *client); +int (*restore)(struct drm_client_dev *client,bool force);/** * @hotplug:
@@ -123,7 +125,7 @@ void drm_client_register(struct drm_clievoid drm_client_dev_unregister (struct drm_device *dev);void drm_client_dev_hotplug (struct drm_device *dev); -void drm_client_dev_restore (struct drm_device *dev); +void drm_client_dev_restore (struct drm_device *dev,bool force);/** * struct drm_client_buffer - DRM client buffer
include/drm/drm_fb_helper.h +4 -7
@@ -244,7 +244,8 @@ int drm_fb_helper_set_par(struct fb_infoint drm_fb_helper_check_var (struct fb_var_screeninfo *var,struct fb_info *info); -int drm_fb_helper_restore_fbdev_mode_unlocked (struct drm_fb_helper *fb_helper); +int drm_fb_helper_restore_fbdev_mode_unlocked (struct drm_fb_helper *fb_helper, +bool force);void drm_fb_helper_unregister_info (struct drm_fb_helper *fb_helper); void drm_fb_helper_fill_info(struct fb_info *info,
@@ -269,7 +270,6 @@ int drm_fb_helper_hotplug_event(struct dint drm_fb_helper_initial_config (struct drm_fb_helper *fb_helper);int drm_fb_helper_debug_enter (struct fb_info *info);int drm_fb_helper_debug_leave (struct fb_info *info); -void drm_fb_helper_lastclose (struct drm_device *dev);#else static inline void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
@@ -321,7 +321,8 @@ static inline int drm_fb_helper_check_va }static inline int -drm_fb_helper_restore_fbdev_mode_unlocked (struct drm_fb_helper *fb_helper) +drm_fb_helper_restore_fbdev_mode_unlocked (struct drm_fb_helper *fb_helper, +bool force) {return 0 ; }
@@ -383,10 +384,6 @@ static inline int drm_fb_helper_debug_le {return 0 ; } - -static inline void drm_fb_helper_lastclose (struct drm_device *dev) -{ -}#endif #endif
Greg Kroah-Hartman
maintainerPATCH 824/877 drm/client: fix restore of partially initialized client
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: shechenglong <[email protected]>
[ Upstream commit 1fca688e9443003e33cf30453e7a7560367656c9 ]
I got a null-ptr-deref report when closing a DRM file descriptor:
WARNING: drivers/gpu/drm/drm_atomic.c:2031 at __drm_atomic_helper_set_config+0x18e/0x1b0 [drm] Call Trace: drm_client_modeset_commit_atomic+0x16b/0x220 [drm] drm_client_modeset_commit_locked+0x56/0x160 [drm] drm_client_modeset_commit+0x21/0x40 [drm] __drm_fb_helper_restore_fbdev_mode_unlocked.part.0+0x7b/0x80 drm_fbdev_client_restore+0xe/0x20 [drm_client_lib] drm_client_dev_restore+0x9f/0xc0 [drm] drm_release+0xc5/0xe0 [drm]
The warning is followed by a NULL pointer dereference:
BUG: kernel NULL pointer dereference, address: 0000000000000008
RIP:
__drm_fb_helper_restore_fbdev_mode_unlocked.part.0+0x41/0x80 [drm_kms_helper]
Call Trace: drm_fbdev_client_restore+0xe/0x20 [drm_client_lib] drm_client_dev_restore+0x9f/0xc0 [drm] drm_release+0xc5/0xe0 [drm] __fput+0xdc/0x2b0 __x64_sys_close+0x39/0x80 do_syscall_64+0x8d/0x460 entry_SYSCALL_64_after_hwframe+0x76/0x7e
drm_client_register() adds the DRM client to the device client list before invoking the initial hotplug callback. If the hotplug callback fails, the client remains registered.
For the fbdev client, a failure during drm_fb_helper_initial_config() causes the partially initialized fbdev helper to be cleaned up. drm_fb_helper_fini() releases fb_helper->info and leaves it NULL.
The fbdev client therefore remains registered even though there is no fully initialized framebuffer device.
Later, when userspace closes the DRM file descriptor, drm_release() can invoke the restore callbacks of registered DRM clients:
drm_release()drm_client_dev_restore()drm_fbdev_client_restore()drm_fb_helper_restore_fbdev_mode_unlocked()
drm_fbdev_client_restore() currently restores the fbdev state unconditionally. For a partially initialized fbdev client this can submit an incomplete modeset state and subsequently access fbdev state which has not been initialized, resulting in the warning and NULL pointer dereference above.
drm_fbdev_client_unregister() already uses fb_helper->info to distinguish a fully probed framebuffer device from a partially initialized client.
Use the same condition in drm_fbdev_client_restore() and skip restore if no framebuffer device has been successfully initialized.
--- drivers/gpu/drm/drm_fbdev_client.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/drm_fbdev_client.c +8 -0
@@ -29,6 +29,14 @@ static int drm_fbdev_client_restore(stru {struct drm_fb_helper *fb_helper =drm_fb_helper_from_client (client); +/* +* The client is registered before the initial fbdev probe. +* If probing failed, the client remains registered but there +* is no valid fbdev framebuffer to restore. +*/ +if (!fb_helper->info || !fb_helper->fb) +return 0 ; +drm_fb_helper_restore_fbdev_mode_unlocked (fb_helper, force);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 825/877 drm/i915/mst: add mst sub-struct to struct intel_dp
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jani Nikula <[email protected]>
[ Upstream commit abf874a328a885592a6bfe6f7db463974e14b615 ]
Move active_mst_links, mst_encoders[], and mst_mgr members of struct intel_dp under an mst sub-struct to group mst related things together.
Rename them active_links, stream_encoders[] and mgr for clarity.
Note that is_mst and mst_detect are not included, as they're also relevant for non-mst. The sub-struct is for active mst.
[ Backport to 6.12: retain the stable MST implementations, i915
device references, bandwidth calculations and helper signatures. Update the corresponding field accesses in those implementations instead of importing newer upstream refactors.
Fold in the connector MST field grouping from aa389adeaa856 ("drm/i915/mst: add mst sub-struct to struct intel_connector"), including the stable-only users in link training and PSR. This provides connector->mst.dp and connector->mst.port as required by acbe9a3b60b9 ("drm/i915/dp_mst: Fix configuring FEC for a disconnected stream"), so that target applies unchanged. No functions or behavioral changes are introduced here. ]
Stable-dep-of: acbe9a3b60b9 ("drm/i915/dp_mst: Fix configuring FEC for a disconnected stream")
--- drivers/gpu/drm/i915/display/intel_connector.c | 4 drivers/gpu/drm/i915/display/intel_ddi.c | 4 drivers/gpu/drm/i915/display/intel_display_debugfs.c | 8 drivers/gpu/drm/i915/display/intel_display_types.h | 18 +- drivers/gpu/drm/i915/display/intel_dp.c | 36 ++-- drivers/gpu/drm/i915/display/intel_dp_hdcp.c | 6 drivers/gpu/drm/i915/display/intel_dp_link_training.c | 4 drivers/gpu/drm/i915/display/intel_dp_mst.c | 154 +++++++++--------- drivers/gpu/drm/i915/display/intel_hdcp.c | 8 drivers/gpu/drm/i915/display/intel_psr.c | 2 10 files changed, 123 insertions(+), 121 deletions(-)
drivers/gpu/drm/i915/display/intel_connector.c +2 -2
@@ -103,8 +103,8 @@ void intel_connector_destroy(struct drm_drm_connector_cleanup (connector); -if (intel_connector->port) -drm_dp_mst_put_port_malloc (intel_connector->port); +if (intel_connector->mst.port) +drm_dp_mst_put_port_malloc (intel_connector->mst.port);kfree (connector); }
drivers/gpu/drm/i915/display/intel_ddi.c +2 -2
@@ -2585,7 +2585,7 @@ static void mtl_ddi_pre_enable_dp(struct* Train Display Port" step. Note that steps that are specific to * MST will be handled by intel_mst_pre_enable_dp() before/after it * calls into this function. Also intel_mst_pre_enable_dp() only calls -* us when active_mst_links==0, so any steps designated for "single +* us when mst.active_links==0, so any steps designated for "single * stream or multi-stream master transcoder" can just be performed * unconditionally here. *
@@ -2674,7 +2674,7 @@ static void tgl_ddi_pre_enable_dp(struct* Train Display Port" step. Note that steps that are specific to * MST will be handled by intel_mst_pre_enable_dp() before/after it * calls into this function. Also intel_mst_pre_enable_dp() only calls -* us when active_mst_links==0, so any steps designated for "single +* us when mst.active_links==0, so any steps designated for "single * stream or multi-stream master transcoder" can just be performed * unconditionally here. */
drivers/gpu/drm/i915/display/intel_display_debugfs.c +4 -4
@@ -275,7 +275,7 @@ static void intel_connector_info(structswitch (connector->connector_type) {case DRM_MODE_CONNECTOR_DisplayPort:case DRM_MODE_CONNECTOR_eDP: -if (intel_connector->mst_port) +if (intel_connector->mst.dp)intel_dp_mst_info (m, intel_connector);else intel_dp_info (m, intel_connector);
@@ -288,7 +288,7 @@ static void intel_connector_info(struct }seq_puts (m,"\tHDCP version: " ); -if (intel_connector->mst_port) { +if (intel_connector->mst.dp) {intel_hdcp_info (m, intel_connector, true);seq_puts (m,"\tMST Hub HDCP version: " ); }
@@ -766,7 +766,7 @@ static int i915_dp_mst_info(struct seq_fseq_printf (m,"MST Source Port [ENCODER:%d:%s]\n" , dig_port->base.base.base.id, dig_port->base.base.name); -drm_dp_mst_dump_topology (m, &dig_port->dp.mst_mgr); +drm_dp_mst_dump_topology (m, &dig_port->dp.mst.mgr); }drm_connector_list_iter_end (&conn_iter);
@@ -1533,7 +1533,7 @@ void intel_connector_debugfs_add(struct }if (DISPLAY_VER (i915) >=11 && - ((connector_type == DRM_MODE_CONNECTOR_DisplayPort && !connector->mst_port) || + ((connector_type == DRM_MODE_CONNECTOR_DisplayPort && !connector->mst.dp) || connector_type == DRM_MODE_CONNECTOR_eDP)) {debugfs_create_file ("i915_dsc_fec_support" ,0644 , root, connector, &i915_dsc_fec_support_fops);
drivers/gpu/drm/i915/display/intel_display_types.h +10 -8
@@ -647,10 +647,6 @@ struct intel_connector {state of connector->polled in case hotplug storm detection changes it */ u8 polled; -struct drm_dp_mst_port *port; - -struct intel_dp *mst_port; -bool force_bigjoiner_enable;struct {
@@ -662,6 +658,11 @@ struct intel_connector { u8 dsc_decompression_enabled:1; } dp; +struct { +struct drm_dp_mst_port *port; +struct intel_dp *dp; + } mst; +/* Work struct to schedule a uevent on link train failure */ struct work_struct modeset_retry_work;
@@ -1834,7 +1835,6 @@ struct intel_dp {struct intel_pps pps;bool is_mst; -int active_mst_links;enum drm_dp_mst_mode mst_detect;/* connector directly attached - won't be use for modeset in mst world */
@@ -1844,9 +1844,11 @@ struct intel_dp {struct drm_dp_tunnel *tunnel; bool tunnel_suspended:1; -/* mst connector list */ -struct intel_dp_mst_encoder *mst_encoders[I915_MAX_PIPES ]; -struct drm_dp_mst_topology_mgr mst_mgr; +struct { +struct intel_dp_mst_encoder *stream_encoders[I915_MAX_PIPES ]; +struct drm_dp_mst_topology_mgr mgr; +int active_links; + } mst;u32 (*get_aux_clock_divider)(struct intel_dp *dp,int index);/*
drivers/gpu/drm/i915/display/intel_dp.c +18 -18
@@ -1290,7 +1290,7 @@ bool intel_dp_has_dsc(const struct intelif (!HAS_DSC (i915))return false; -if (connector->mst_port && !HAS_DSC_MST (i915)) +if (connector->mst.dp && !HAS_DSC_MST (i915))return false; if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP &&
@@ -3016,7 +3016,7 @@ intel_dp_queue_modeset_retry_for_link(stif (!conn_state->base.crtc)continue ; -if (connector->mst_port == intel_dp) +if (connector->mst.dp == intel_dp)intel_dp_queue_modeset_retry_work (connector); } }
@@ -3236,8 +3236,8 @@ intel_dp_sink_set_dsc_passthrough(const bool enable) {struct drm_i915_private *i915 =to_i915 (connector->base.dev); -struct drm_dp_aux *aux = connector->port ? - connector->port->passthrough_aux :NULL ; +struct drm_dp_aux *aux = connector->mst.port ? + connector->mst.port->passthrough_aux :NULL ;if (!aux)return ;
@@ -3264,7 +3264,7 @@ static int intel_dp_dsc_aux_ref_count(st* On SST the decompression AUX device won't be shared, each connector * uses for this its own AUX targeting the sink device. */ -if (!connector->mst_port) +if (!connector->mst.dp)return connector->dp.dsc_decompression_enabled ?1 :0 ; for_each_oldnew_connector_in_state(&state->base, _connector_iter,
@@ -3272,7 +3272,7 @@ static int intel_dp_dsc_aux_ref_count(stconst struct intel_connector * connector_iter =to_intel_connector (_connector_iter); -if (connector_iter->mst_port != connector->mst_port) +if (connector_iter->mst.dp != connector->mst.dp)continue ;if (!connector_iter->dp.dsc_decompression_enabled)
@@ -4291,7 +4291,7 @@ intel_dp_mst_configure(struct intel_dp *if (intel_dp->is_mst)intel_dp_mst_prepare_probe (intel_dp); -drm_dp_mst_topology_mgr_set_mst (&intel_dp->mst_mgr, intel_dp->is_mst); +drm_dp_mst_topology_mgr_set_mst (&intel_dp->mst.mgr, intel_dp->is_mst);/* Avoid stale info on the next detect cycle. */ intel_dp->mst_detect =DRM_DP_SST ;
@@ -4306,9 +4306,9 @@ intel_dp_mst_disconnect(struct intel_dpreturn ;drm_dbg_kms (&i915->drm,"MST device may have disappeared %d vs %d\n" , - intel_dp->is_mst, intel_dp->mst_mgr.mst_state); + intel_dp->is_mst, intel_dp->mst.mgr.mst_state); intel_dp->is_mst = false; -drm_dp_mst_topology_mgr_set_mst (&intel_dp->mst_mgr, intel_dp->is_mst); +drm_dp_mst_topology_mgr_set_mst (&intel_dp->mst.mgr, intel_dp->is_mst); } static bool
@@ -5154,7 +5154,7 @@ intel_dp_mst_hpd_irq(struct intel_dp *in {bool handled = false; -drm_dp_mst_hpd_irq_handle_event (&intel_dp->mst_mgr, esi, ack, &handled); +drm_dp_mst_hpd_irq_handle_event (&intel_dp->mst.mgr, esi, ack, &handled);if (esi[1 ] &DP_CP_IRQ ) {intel_hdcp_handle_cp_irq (intel_dp->attached_connector);
@@ -5203,7 +5203,7 @@ intel_dp_check_mst_status(struct intel_dbool link_ok = true;bool reprobe_needed = false; -drm_WARN_ON_ONCE (&i915->drm, intel_dp->active_mst_links <0 ); +drm_WARN_ON_ONCE (&i915->drm, intel_dp->mst.active_links <0 );for (;;) {u8 esi[4 ] = {};
@@ -5219,7 +5219,7 @@ intel_dp_check_mst_status(struct intel_ddrm_dbg_kms (&i915->drm,"DPRX ESI: %4ph\n" , esi); -if (intel_dp->active_mst_links >0 && link_ok && +if (intel_dp->mst.active_links >0 && link_ok && esi[3 ] &LINK_STATUS_CHANGED ) {if (!intel_dp_mst_link_status (intel_dp)) link_ok = false;
@@ -5242,7 +5242,7 @@ intel_dp_check_mst_status(struct intel_ddrm_dbg_kms (&i915->drm,"Failed to ack ESI\n" );if (ack[1 ] & (DP_DOWN_REP_MSG_RDY |DP_UP_REQ_MSG_RDY )) -drm_dp_mst_hpd_irq_send_new_request (&intel_dp->mst_mgr); +drm_dp_mst_hpd_irq_send_new_request (&intel_dp->mst.mgr); }if (!link_ok || intel_dp->link.force_retrain)
@@ -5340,7 +5340,7 @@ static bool intel_dp_has_connector(struc/* MST */ for_each_pipe (i915, pipe) { - encoder = &intel_dp->mst_encoders[pipe]->base; + encoder = &intel_dp->mst.stream_encoders[pipe]->base;if (conn_state->best_encoder == &encoder->base)return true; }
@@ -6421,7 +6421,7 @@ static int intel_dp_connector_atomic_chereturn ret;if (intel_dp_mst_source_support (intel_dp)) { - ret =drm_dp_mst_root_conn_atomic_check (conn_state, &intel_dp->mst_mgr); + ret =drm_dp_mst_root_conn_atomic_check (conn_state, &intel_dp->mst.mgr);if (ret)return ret; }
@@ -7000,7 +7000,7 @@ void intel_dp_mst_suspend(struct drm_i91continue ;if (intel_dp->is_mst) -drm_dp_mst_topology_mgr_suspend (&intel_dp->mst_mgr); +drm_dp_mst_topology_mgr_suspend (&intel_dp->mst.mgr); } }
@@ -7023,11 +7023,11 @@ void intel_dp_mst_resume(struct drm_i915if (!intel_dp_mst_source_support (intel_dp))continue ; - ret =drm_dp_mst_topology_mgr_resume (&intel_dp->mst_mgr, + ret =drm_dp_mst_topology_mgr_resume (&intel_dp->mst.mgr, true);if (ret) { intel_dp->is_mst = false; -drm_dp_mst_topology_mgr_set_mst (&intel_dp->mst_mgr, +drm_dp_mst_topology_mgr_set_mst (&intel_dp->mst.mgr, false); } }
drivers/gpu/drm/i915/display/intel_dp_hdcp.c +3 -3
@@ -702,10 +702,10 @@ int intel_dp_hdcp_get_remote_capability( *hdcp_capable = false; *hdcp2_capable = false; -if (!connector->mst_port) +if (!connector->mst.dp)return -EINVAL ; - aux = &connector->port->aux; + aux = &connector->mst.port->aux; ret =_intel_dp_hdcp2_get_capability (aux, hdcp2_capable);if (ret) drm_dbg_kms(&i915->drm,
@@ -881,7 +881,7 @@ int intel_dp_hdcp_init(struct intel_digiif (!is_hdcp_supported (dev_priv, port))return 0 ; -if (intel_connector->mst_port) +if (intel_connector->mst.dp)return intel_hdcp_init (intel_connector, dig_port, &intel_dp_mst_hdcp_shim);else if (!intel_dp_is_edp (intel_dp))
drivers/gpu/drm/i915/display/intel_dp_link_training.c +2 -2
@@ -1692,8 +1692,8 @@ void intel_dp_128b132b_sdp_crc16(structstatic struct intel_dp *intel_connector_to_intel_dp (struct intel_connector *connector) { -if (connector->mst_port) -return connector->mst_port; +if (connector->mst.dp) +return connector->mst.dp;else return enc_to_intel_dp (intel_attached_encoder (connector)); }
drivers/gpu/drm/i915/display/intel_dp_mst.c +77 -77
484 lines not on this page · raw message
drivers/gpu/drm/i915/display/intel_hdcp.c +4 -4
@@ -62,13 +62,13 @@ static int intel_conn_to_vcpi(struct intint vcpi =0 ;/* For HDMI this is forced to be 0x0. For DP SST also this is 0x0. */ -if (!connector->port) +if (!connector->mst.port)return 0 ; - mgr = connector->port->mgr; + mgr = connector->mst.port->mgr;drm_modeset_lock (&mgr->base.lock, state->base.acquire_ctx); mst_state =to_drm_dp_mst_topology_state (mgr->base.state); - payload =drm_atomic_get_mst_payload_state (mst_state, connector->port); + payload =drm_atomic_get_mst_payload_state (mst_state, connector->mst.port);if (drm_WARN_ON (mgr->dev, !payload)) goto out;
@@ -137,7 +137,7 @@ intel_hdcp_required_content_stream(struc data->k++;/* if there is only one active stream */ -if (dig_port->dp.active_mst_links <=1 ) +if (dig_port->dp.mst.active_links <=1 )break ; }drm_connector_list_iter_end (&conn_iter);
drivers/gpu/drm/i915/display/intel_psr.c +1 -1
@@ -3951,7 +3951,7 @@ void intel_psr_connector_debugfs_add(str/* TODO: Add support for MST connectors as well. */ if ((connector->base.connector_type != DRM_MODE_CONNECTOR_eDP && connector->base.connector_type != DRM_MODE_CONNECTOR_DisplayPort) || - connector->mst_port) + connector->mst.dp)return ; debugfs_create_file("i915_psr_sink_status", 0444, root,
Greg Kroah-Hartman
maintainerPATCH 826/877 drm/i915/dp_mst: Fix configuring FEC for a disconnected stream
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Deak <[email protected]>
[ Upstream commit acbe9a3b60b9a6ace8ef11fe898f586251c84592 ]
During an atomic commit after all the MST stream CRTC state is computed the driver ensures that the FEC is configured the same way (enabled or disabled) for all the streams on a given MST topology's link. drm_dp_mst_port_downstream_of_parent() used to determine if a stream is downstream of an MST port will return false if the whole topology is disconnected, since in that case it can't verify that the port/ parent_port passed to it is in the given MST topology. This is a problem during the above FEC configuration check, since intel_dp_mst_check_dsc_change()->get_pipes_downstream_of_mst_ports() will not return all the stream CRTCs/pipes for the topology as expected. Since passing parent_port==NULL to get_pipes_downstream_of_mst_port() is meant to return all the streams for the given topology (i.e. mst_mgr) skip checking if an MST port is downstream of a parent port in this case.
This fixes a problem where the FEC configuration check explained above failed to ensure that all streams' FEC is configured the same way if the topology was disconnected, leading to a FEC state mismatch error.
--- drivers/gpu/drm/i915/display/intel_dp_mst.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_dp_mst.c +2 -1
@@ -739,7 +739,8 @@ static u8 get_pipes_downstream_of_mst_poif (&connector->mst.dp->mst.mgr != mst_mgr)continue ; -if (connector->mst.port != parent_port && +if (parent_port && + connector->mst.port != parent_port && !drm_dp_mst_port_downstream_of_parent (mst_mgr, connector->mst.port, parent_port))
Greg Kroah-Hartman
maintainerPATCH 827/877 mm/rmap: allocate anon_vma_chain objects unlocked when possible
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes <[email protected]>
[ Upstream commit bfc2b13b05a1343bb60a85d840fd8956731866c5 ]
There is no reason to allocate the anon_vma_chain under the anon_vma write lock when cloning - we can in fact assign these to the destination VMA safely as we hold the exclusive mmap lock and therefore preclude anybody else accessing these fields.
We only need take the anon_vma write lock when we link rbtree edges from the anon_vma to the newly established AVCs.
This also allows us to eliminate the weird GFP_NOWAIT, GFP_KERNEL dance introduced in commit dd34739c03f2 ("mm: avoid anon_vma_chain allocation under anon_vma lock"), further simplifying this logic.
This should reduce lock anon_vma contention, and clarifies exactly where the anon_vma lock is required.
We cannot adjust __anon_vma_prepare() in the same way as this is only protected by VMA read lock, so we have to perform the allocation here under the anon_vma write lock and page_table_lock (to protect against racing threads), and we wish to retain the lock ordering.
With this change we can simplify cleanup_partial_anon_vmas() even further
- since we allocate AVC's without any lock taken and do not insert anything into the interval tree until after the allocations are tried, we can remove all logic pertaining to this and just free up AVC's only.
[Stable dependency adaptation for 6.18:
Keep the split of anon_vma_chain_link() into anon_vma_chain_assign() and explicit interval-tree insertion at all three callers. Retain the fork change that assigns the chain before taking the anon_vma write lock; the interval-tree insertion remains protected by that lock.
Drop the two-pass clone allocation and cleanup_partial_anon_vmas() changes. This tree lacks the prerequisite clone assertions, early unfaulted-VMA handling, simplified root locking, and partial-clone cleanup. Preserve the existing GFP_NOWAIT/GFP_KERNEL fallback, root locking, list traversal, reference accounting, and allocation-failure cleanup instead. No new functions are introduced.
The helper split supplies the context needed for b6ac0b3f6013 ("mm/rmap:
fix missing barrier between anon_vma init and vma->anon_vma publish") to merge cleanly while retaining this tree's interval-tree API. The memory barrier fix itself is left to that target commit.]
Stable-dep-of: b6ac0b3f6013 ("mm/rmap: fix missing barrier between anon_vma init and vma->anon_vma publish")
--- mm/rmap.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
mm/rmap.c +10 -7
@@ -148,14 +148,13 @@ static void anon_vma_chain_free(struct akmem_cache_free (anon_vma_chain_cachep, anon_vma_chain); } -static void anon_vma_chain_link (struct vm_area_struct *vma, -struct anon_vma_chain *avc, -struct anon_vma *anon_vma) +static void anon_vma_chain_assign (struct vm_area_struct *vma, +struct anon_vma_chain *avc, +struct anon_vma *anon_vma) { avc->vma = vma; avc->anon_vma = anon_vma;list_add (&avc->same_vma, &vma->anon_vma_chain); -anon_vma_interval_tree_insert (avc, &anon_vma->rb_root); }/**
@@ -212,7 +211,8 @@ int __anon_vma_prepare(struct vm_area_stspin_lock (&mm->page_table_lock);if (likely (!vma->anon_vma)) { vma->anon_vma = anon_vma; -anon_vma_chain_link (vma, avc, anon_vma); +anon_vma_chain_assign (vma, avc, anon_vma); +anon_vma_interval_tree_insert (avc, &anon_vma->rb_root); anon_vma->num_active_vmas++; allocated =NULL ; avc =NULL ;
@@ -296,7 +296,8 @@ int anon_vma_clone(struct vm_area_struct } anon_vma = pavc->anon_vma; root =lock_anon_vma_root (root, anon_vma); -anon_vma_chain_link (dst, avc, anon_vma); +anon_vma_chain_assign (dst, avc, anon_vma); +anon_vma_interval_tree_insert (avc, &anon_vma->rb_root);/* * Reuse existing anon_vma if it has no vma and only one
@@ -380,8 +381,10 @@ int anon_vma_fork(struct vm_area_structget_anon_vma (anon_vma->root);/* Mark this anon_vma as the one where our new (COWed) pages go. */ vma->anon_vma = anon_vma; +anon_vma_chain_assign (vma, avc, anon_vma); +/* Now let rmap see it. */ anon_vma_lock_write (anon_vma); -anon_vma_chain_link (vma, avc, anon_vma); +anon_vma_interval_tree_insert (avc, &anon_vma->rb_root); anon_vma->parent->num_children++;anon_vma_unlock_write (anon_vma);
Greg Kroah-Hartman
maintainerPATCH 828/877 mm/rmap: fix missing barrier between anon_vma init and vma->anon_vma publish
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjiang Tu <[email protected]>
[ Upstream commit b6ac0b3f6013c168f22cad97e79967accacb08e1 ]
On arm64 server, we find that a task trying to grab the anon_vma lock triggers hungtask.
INFO: task main:2354726 blocked for more than 120 seconds.
Tainted: G E 5.10.0-0021.aarch64 #1
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:main state:D stack: 0 pid:2354726 ppid:2350673 flags:0x00000a01
Call trace:
__switch_to+0x7c/0xbc
__schedule+0x3b4/0x8a0
schedule+0x50/0xe0
rwsem_down_write_slowpath+0x3cc/0x6cc
down_write+0x60/0x260
__anon_vma_prepare+0x6c/0x210
do_anonymous_page+0x258/0x660
handle_pte_fault+0x188/0x214
__handle_mm_fault+0x1b0/0x380
handle_mm_fault+0xf4/0x284
do_page_fault+0x19c/0x494
do_translation_fault+0xcc/0xf8
do_mem_abort+0x48/0xac
el0_da+0x44/0x80
el0_sync_handler+0x88/0xb4
el0_sync+0x160/0x180After analyzing the vmcore, we found the anon_vma->root->rwsem.count is -1. There is another anon_vma whose anon_vma->root->rwsem.count is 1, the anon_vma->root->rwsem.owner shows the lock is held, but the stack of the task shows the task doesn't hold the anon_vma lock.
After adding more debugging info, we found __anon_vma_prepare() reuses anon_vma and triggers the UAF of anon_vma->root due to missing memory barrier, leading to locking and unlocking two different anon_vma->root, thus leading to an anon_vma will never be unlocked, and another anon_vma couldn't be locked anymore.
This race requires two adjacent VMAs that are not merged but are anon_vma-compatible (e.g., they differ in VMA_ACCESS_FLAGS that can be changed by mprotect()). Two threads fault on each VMA concurrently, both calling __anon_vma_prepare() with only mmap_lock held for reading.
THREAD A THREAD B__anon_vma_prepare __anon_vma_prepare
find_mergeable_anon_vma() -> NULL
anon_vma = anon_vma_alloc();
anon_vma->root = anon_vma;
// the two stores may be reordered
vma->anon_vma = anon_vma;
// finds A's anon_vma
anon_vma = find_mergeable_anon_vma(vma);
anon_vma_lock_write(anon_vma);
// may still see the old root
down_write(&anon_vma->root->rwsem);
anon_vma_unlock_write(anon_vma);
// see the new root, never unlock old
up_write(&anon_vma->root->rwsem);thread A triggers page fault and calls __anon_vma_prepare() to prepare anon_vma for the faulting vma. __anon_vma_prepare() allocates and initializes a new anon_vma, and then publishes it to the vma with a plain store. anon_vma_prepare() only requires the mmap_lock to be held for reading, so two threads can fault on adjacent VMAs at the same time. While thread A publishes a new anon_vma, thread B could find the anon_vma via find_mergeable_anon_vma() and then locks anon_vma->root->rwsem.
The store to anon_vma->root in anon_vma_alloc() and the store to vma->anon_vma can be reordered. The anon_vma_lock_write() and spin_lock() only provide acquire semantics, which do not prevent prior stores from being reordered after them. The release semantics of the corresponding spin_unlock() and anon_vma_unlock_write() come too late, the store to vma->anon_vma is already published before they take effect. As a result, thread B can observe the following order:
vma->anon_vma = anon_vma;
anon_vma->root = anon_vma;The anon_vma slab is SLAB_TYPESAFE_BY_RCU, so a newly allocated anon_vma may reuse memory from a previously freed one. The constructor (anon_vma_ctor) does not reset anon_vma->root, and __put_anon_vma() doesn't clear it either, so the old root value persists until anon_vma_alloc() overwrites it. If that store isn't visible, thread B reads a root that points to the old anon_vma and locks it.
As a result, thread B can call anon_vma_lock_write() with the old root, and call anon_vma_unlock_write() with the new root, leading to an anon_vma will never be unlocked, and another anon_vma couldn't be locked anymore (its count is dropped from 0 to -1 due to wrong unlock).
To fix it, change the plain store vma->anon_vma = anon_vma to store release, so that the fields of anon_vma are visible before anon_vma is published to vma->anon_vma.
At read side, the load of anon_vma and anon_vma->root have address dependency. According to Documentation/memory-barriers.txt and some investigations, only Alpha needs address-dependency barriers and it has been handled by READ_ONCE() in reusable_anon_vma().
We reproduced this issue in v5.10 with KSM enabled. The kernel doesn't merge commit cf7e7a3503df ("mm: prevent KSM from breaking VMA merging for new VMAs"), so there are many adjacent VMAs that aren't merged but are compatible for anon_vma.
Without this fix, our production environment could reproduce this issue about 2-5 times each month. After adding a smp_mb() before anon_vma_lock_write(anon_vma) in __anon_vma_prepare(), which is different to this patch, this issue hasn't been reproduced for one month.
--- mm/rmap.c | 6 +++++- mm/vma.c | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
mm/rmap.c +5 -1
@@ -210,7 +210,11 @@ int __anon_vma_prepare(struct vm_area_st/* page_table_lock to protect against threads */ spin_lock (&mm->page_table_lock);if (likely (!vma->anon_vma)) { - vma->anon_vma = anon_vma; +/* +* Make anon_vma fields visible before anon_vma is published. +* Paired with an address dependency in reusable_anon_vma(). +*/ +smp_store_release (&vma->anon_vma, anon_vma);anon_vma_chain_assign (vma, avc, anon_vma);anon_vma_interval_tree_insert (avc, &anon_vma->rb_root); anon_vma->num_active_vmas++;
mm/vma.c +8 -0
@@ -1760,6 +1760,13 @@ static int anon_vma_compatible(struct vm* acceptable for merging, so we can do all of this optimistically. But * we do that READ_ONCE() to make sure that we never re-load the pointer. * +* The READ_ONCE() establishes an address dependency between anon_vma and +* any access to its fields, which pairs with the assignment to +* vma->anon_vma performed with release semantics in __anon_vma_prepare(). +* +* This is especially important as anon_vma's are SLAB_TYPESAFE_BY_RCU so +* accessing an uninitialised anon_vma's fields may result in a UAF. +* * IOW: that the "list_is_singular()" test on the anon_vma_chain only * matters for the 'stable anon_vma' case (ie the thing we want to avoid * is to return an anon_vma that is "complex" due to having gone through
@@ -1774,6 +1781,7 @@ static struct anon_vma *reusable_anon_vm struct vm_area_struct *b) {if (anon_vma_compatible (a, b)) { +/* Paired with a memory barrier in __anon_vma_prepare(). */ struct anon_vma *anon_vma =READ_ONCE (old->anon_vma);if (anon_vma &&list_is_singular (&old->anon_vma_chain))
Greg Kroah-Hartman
maintainerPATCH 829/877 drm/xe/vm: nuke PTs only after unlinking contested VMAs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Auld <[email protected]>
[ Upstream commit 24a22fb3c731474b68e986af6804db450fb88617 ]
In xe_vm_close_and_put(), external-BO VMAs are queued on the contested list for deferred destruction via xe_vma_destroy_unlocked(). However, xe_vm_pt_destroy() was previously invoked before processing contested VMAs, destroying vm->pt_root while those VMAs were still linked to their respective buffer objects (vm_bo->list.gpuva).
If a concurrent thread evicts one of those shared buffer objects, xe_bo_trigger_rebind() holding only bo->resv walks the BO's VMAs and, in fault mode, calls xe_vm_invalidate_vma() -> xe_pt_zap_ptes(). Because vm->pt_root[tile->id] is already NULL, dereferencing pt->level causes a NULL ptr deref.
Fix this by deferring xe_vm_free_scratch() and xe_vm_pt_destroy() until after all contested VMAs have been unlinked and destroyed.
User is reporting hitting a NULL ptr deref in xe_pt_zap_ptes(), which could be explained by this race.
--- drivers/gpu/drm/xe/xe_vm.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +13 -16
@@ -1678,13 +1678,21 @@ void xe_vm_close_and_put(struct xe_vm *v vma->gpuva.flags |=XE_VMA_DESTROYED ; } +xe_vm_unlock (vm); +/* -* All vm operations will add shared fences to resv. -* The only exception is eviction for a shared object, -* but even so, the unbind when evicted would still -* install a fence to resv. Hence it's safe to -* destroy the pagetables immediately. +* Unlink and destroy all contested external-BO VMAs before destroying +* the page tables. Otherwise, concurrent eviction holding only bo->resv +* can walk the BO's VMAs and attempt to invalidate/zap page tables that +* have already been freed. */ +list_for_each_entry_safe (vma, next_vma, &contested, + combined_links.destroy) { +list_del_init (&vma->combined_links.destroy); +xe_vma_destroy_unlocked (vma); + } + +xe_vm_lock (vm, false);xe_vm_free_scratch (vm);for_each_tile (tile, xe, id) {
@@ -1695,17 +1703,6 @@ void xe_vm_close_and_put(struct xe_vm *v }xe_vm_unlock (vm); -/* -* VM is now dead, cannot re-add nodes to vm->vmas if it's NULL -* Since we hold a refcount to the bo, we can remove and free -* the members safely without locking. -*/ -list_for_each_entry_safe (vma, next_vma, &contested, - combined_links.destroy) { -list_del_init (&vma->combined_links.destroy); -xe_vma_destroy_unlocked (vma); - } -up_write (&vm->lock);down_write (&xe->usm.lock);
Greg Kroah-Hartman
maintainerPATCH 830/877 mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
[ Upstream commit 39c0ceedd54557bdc1542de08d22b2ed33e534e4 ]
damon_hugetlb_mkold() reads the page table entry into a local variable, unsets the accessed bit in the variable, and updates the page table entry with the updated variable value. If hardware updates the same page table entry in parallel, the hw updates could be lost. For example, hardware-updated dirty bits might be lost.
Avoid the parallel updates by clearing the page table entry when reading it together, using huge_ptep_get_and_clear(). If a parallel write to the memory is made after the clearing, the hw will see the page table entry is cleared, trigger page fault and wait until it is handled. The page fault handling will wait for damon_hugetlb_mkold() due to the page table lock.
Because hugetlbfs is an in-memory file system and hugetlb pages cannot be reclaimed, no critical issue is expected to my best knowledge. But definitely this is a nasty bug that should be fixed sooner rather than later.
The issue was discovered [1] by Sashiko.
--- mm/damon/vaddr.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/vaddr.c +1 -0
@@ -347,6 +347,7 @@ static void damon_hugetlb_mkold(pte_t *pif (pte_young (entry)) { referenced = true; + entry =huge_ptep_get_and_clear (mm, addr, pte, psize); entry =pte_mkold (entry);set_huge_pte_at (mm, addr, pte, entry, psize); }
Greg Kroah-Hartman
maintainerPATCH 831/877 mm/hugetlb: fix surplus pages in dissolve_free_huge_page()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjiang Tu <[email protected]>
[ Upstream commit cb402bbdabcaa5a765068c5b8673bbfc1c264242 ]
In dissolve_free_huge_page(), free huge pages are dissolved without adjusting surplus count. However, free huge pages may be accounted as surplus pages, and will lead to wrong surplus count.
I reproduce this issue on qemu. The steps are:
1) Node1 is memory-less at first. Hot-add memory to node1 by executing the two commands in qemu monitor:
object_add memory-backend-ram,id=mem1,size=1G
device_add pc-dimm,id=dimm1,memdev=mem1,node=1
2) online one memory block of Node1 with:
echo online_movable > /sys/devices/system/node/node1/memoryX/state
3) create 64 huge pages for node1
4) run a program to reserve (don't consume) all the huge pages
5) echo 0 > nr_huge_pages for node1. After this step, free huge pages in Node1 are surplus.
6) create 80 huge pages for node0
7) offline memory of node1, The memory range to offline contains the free surplus huge pages created in step3) ~ step5)
echo offline > /sys/devices/system/node/node1/memoryX/state
8) kill the program in step 4)
The result:
Node0 Node1
total 80 0 free 80 0 surplus 0 61
To fix it, adjust surplus when destroying huge pages if the node has surplus pages in dissolve_free_hugetlb_folio().
The result with this patch:
Node0 Node1
total 80 0 free 80 0 surplus 0 0
Stable-dep-of: a363c62a653c ("mm/hugetlb: do not dissolve gigantic pages without runtime support")
--- mm/hugetlb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/hugetlb.c +6 -2
@@ -2201,6 +2201,8 @@ retry:if (!folio_ref_count (folio)) {struct hstate *h =folio_hstate (folio); +bool adjust_surplus = false; +if (!available_huge_pages (h)) goto out;
@@ -2223,7 +2225,9 @@ retry: goto retry; } -remove_hugetlb_folio (h, folio, false); +if (h->surplus_huge_pages_node[folio_nid (folio)]) + adjust_surplus = true; +remove_hugetlb_folio (h, folio, adjust_surplus); h->max_huge_pages--;spin_unlock_irq (&hugetlb_lock);
@@ -2243,7 +2247,7 @@ retry: rc =hugetlb_vmemmap_restore_folio (h, folio);if (rc) {spin_lock_irq (&hugetlb_lock); -add_hugetlb_folio (h, folio, false); +add_hugetlb_folio (h, folio, adjust_surplus); h->max_huge_pages++; goto out; }
Greg Kroah-Hartman
maintainerPATCH 832/877 mm/hugetlb: create hstate_is_gigantic_no_runtime helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Usama Arif <[email protected]>
[ Upstream commit a743e0af503a633e4ca68a100d9b2a1a071fe8ae ]
This is a common condition used to skip operations that cannot be performed on gigantic pages when runtime support is disabled. This helper is introduced as the condition will exist even more when allowing "overcommit" of gigantic hugepages. No functional change intended with this patch.
Stable-dep-of: a363c62a653c ("mm/hugetlb: do not dissolve gigantic pages without runtime support")
--- mm/hugetlb.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
mm/hugetlb.c +16 -5
@@ -104,6 +104,17 @@ static void hugetlb_free_folio(struct fofolio_put (folio); } +/* +* Check if the hstate represents gigantic pages but gigantic page +* runtime support is not available. This is a common condition used to +* skip operations that cannot be performed on gigantic pages when runtime +* support is disabled. +*/ +static inline bool hstate_is_gigantic_no_runtime (struct hstate *h) +{ +return hstate_is_gigantic (h) && !gigantic_page_runtime_supported (); +} +static inline bool subpool_is_free (struct hugepage_subpool *spool) {if (spool->count)
@@ -1594,7 +1605,7 @@ static void remove_hugetlb_folio(structVM_BUG_ON_FOLIO (hugetlb_cgroup_from_folio_rsvd (folio), folio);lockdep_assert_held (&hugetlb_lock); -if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) +if (hstate_is_gigantic_no_runtime (h))return ;list_del (&folio->lru);
@@ -1656,7 +1667,7 @@ static void __update_and_free_hugetlb_fo {bool clear_flag =folio_test_hugetlb_vmemmap_optimized (folio); -if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) +if (hstate_is_gigantic_no_runtime (h))return ;/*
@@ -2564,7 +2575,7 @@ static void return_unused_surplus_pages(/* Uncommit the reservation */ h->resv_huge_pages -= unused_resv_pages; -if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) +if (hstate_is_gigantic_no_runtime (h)) goto out;/*
@@ -3493,7 +3504,7 @@ static void __init hugetlb_init_hstates(* - If CMA allocation is possible, we can not demote * HUGETLB_PAGE_ORDER or smaller size pages. */ -if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) +if (hstate_is_gigantic_no_runtime (h))continue ;if (hugetlb_cma_size && h->order <=HUGETLB_PAGE_ORDER )continue ;
@@ -3938,7 +3949,7 @@ static ssize_t __nr_hugepages_store_commint err;nodemask_t nodes_allowed, *n_mask; -if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) +if (hstate_is_gigantic_no_runtime (h))return -EINVAL ;if (nid ==NUMA_NO_NODE ) {
Greg Kroah-Hartman
maintainerPATCH 833/877 mm/hugetlb: do not dissolve gigantic pages without runtime support
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longlong Xia <[email protected]>
[ Upstream commit a363c62a653cc8b3e21da9545fa4e028ef50f9c3 ]
dissolve_free_hugetlb_folio() doesn't check hstate_is_gigantic_no_runtime(h) though remove_hugetlb_folio()/ update_and_free_hugetlb_folio() silently bail for such folios, so it frees a still-listed folio and, on vmemmap restore failure, the add_hugetlb_folio() rollback corrupts the free list.
--- mm/hugetlb.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/hugetlb.c +9 -0
@@ -2214,6 +2214,15 @@ retry:struct hstate *h =folio_hstate (folio);bool adjust_surplus = false; +/* +* remove_hugetlb_folio()/update_and_free_hugetlb_folio() bail +* for gigantic hstates without runtime support, so dissolving one +* here would leave it on the free list and, on vmemmap restore +* failure, the add_hugetlb_folio() rollback corrupts that list. +*/ +if (hstate_is_gigantic_no_runtime (h)) + goto out; +if (!available_huge_pages (h)) goto out;
Greg Kroah-Hartman
maintainerPATCH 834/877 super: make iterate_supers_type() deletion-safe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 2d2a2d7aa98741b58f54cacc99b52024e4d865f9 ]
iterate_supers_type() drops sb_lock while invoking the callback and keeps only a passive reference to the current superblock. That reference keeps the object allocated, but does not keep its s_instances node linked.
After the iterator releases s_umount, final teardown can unlink the current s_instances node. The iterator then advances through a reinitialized node. With the current hlist it stops without visiting the remaining superblocks. The unlink moved from generic_shutdown_super() to kill_super_notify(), but the cursor lifetime has been unsafe since the helper was introduced.
The CIFS DFS lookup can consequently miss a matching superblock and return -EINVAL.
Move removal from fs_supers to put_super(), alongside removal from super_blocks, so a passive reference keeps both list nodes linked. Keep the filesystem module reference until then, since unlinking s_instances may touch type->fs_supers.
Make sget_fc() skip SB_DEAD superblocks before invoking test(), and set SB_DEAD under sb_lock to serialize with those callbacks. This allows kernfs to free its private information after kill_anon_super() returns. Keep matching SB_DYING superblocks until SB_DEAD is set so concurrent mounts still wait for teardown before retrying.
--- fs/kernfs/mount.c | 4 ++-- fs/super.c | 43 +++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 22 deletions(-)
fs/kernfs/mount.c +2 -2
@@ -396,8 +396,8 @@ void kernfs_kill_sb(struct super_block *up_write (&root->kernfs_supers_rwsem);/* -* Remove the superblock from fs_supers/s_instances -* so we can't find it, before freeing kernfs_super_info. +* Mark the superblock dead so sget_fc() can't find it, +* before freeing kernfs_super_info. */ kill_anon_super (sb);kfree (info);
fs/super.c +23 -20
88 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 835/877 PCI: Fix Resizable BAR restore order
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilpo Järvinen <[email protected]>
[ Upstream commit 5528fd38f230c906fcebb202cc94fbb8ed8f122a ]
The commit 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path") changed BAR resize to layer rebar code and resource setup/restore code cleanly. Unfortunately, it did not consider how the value of the BAR Size field impacts the read-only bits in the Base Address Register (PCIe7 spec, sec. 7.8.6.3). That is, it very much matters in which order the BAR Size and Base Address Register are restored.
Post-337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path") during BAR resize rollback, pci_do_resource_release_and_resize() attempts to restore the old address to the BAR that was resized, but it can fail to setup the address correctly if the address has low bits set that collide with the bits that are still read-only. As a result, kernel's resource and BAR will be out-of-sync.
Fix this by restoring BAR Size before rolling back the resource changes and restoring the BAR.
[6.12 dependency preparation for d58384c22739848efe14b34e9586e4f1242f33c0:
Keep the existing memory-decoding and supported-size checks in rebar.c. Move BAR size programming and rollback into the resource release helper, so the old size is restored before restoring BAR addresses.
Use the assigned parent window to select resources for release, retaining the old flags-based selection when the resized BAR has no parent. Provide file-local macro mappings for the follow-up's bridge reassignment and resource assignment checks; no functions are added.
Retain the upstream pre-target pci_bus_sem placement to allow the target to apply without conflicts. This preparatory dependency must be applied together with d58384c22739848efe14b34e9586e4f1242f33c0, which takes the lock before releasing resources and assigns released BARs on root buses.]
Stable-dep-of: d58384c22739 ("PCI: Fix BAR resize for devices on a root bus")
--- drivers/pci/rebar.c | 19 +------------------ drivers/pci/setup-bus.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 25 deletions(-)
drivers/pci/rebar.c +1 -18
@@ -156,7 +156,6 @@ int pci_resize_resource(struct pci_dev * int exclude_bars) {struct pci_host_bridge *host; -int old, ret;u32 sizes;u16 cmd;
@@ -176,22 +175,6 @@ int pci_resize_resource(struct pci_dev *if (!(sizes &BIT (size)))return -EINVAL ; - old =pci_rebar_get_current_size (dev, resno); -if (old <0 ) -return old; - - ret =pci_rebar_set_size (dev, resno, size); -if (ret) -return ret; - - ret =pci_do_resource_release_and_resize (dev, resno, size, exclude_bars); -if (ret) - goto error_resize; - -return 0 ; - -error_resize: -pci_rebar_set_size (dev, resno, old); -return ret; +return pci_do_resource_release_and_resize (dev, resno, size, exclude_bars); }EXPORT_SYMBOL (pci_resize_resource);
drivers/pci/setup-bus.c +32 -7
@@ -2368,6 +2368,11 @@ static int pci_reassign_bridge_resourcesreturn 0 ; } +/* Keep the resize follow-up compatible with the 6.12 resource helpers. */ +#define pbus_reassign_bridge_resources (bus, res, saved) \ + pci_reassign_bridge_resources((bus)->self, (res)->flags, (saved)) +#define resource_assigned (res) ((res)->parent != NULL) +int pci_do_resource_release_and_resize (struct pci_dev *pdev,int resno,int size,int exclude_bars) {
@@ -2375,12 +2380,20 @@ int pci_do_resource_release_and_resize(sunsigned long flags = res->flags;struct pci_dev_resource *dev_res;struct pci_bus *bus = pdev->bus; -struct resource *r; +struct resource *b_win, *r;LIST_HEAD (saved);unsigned int i; -int ret =0 ; +int old, ret; -down_read (&pci_bus_sem); + b_win = res->parent; + + old =pci_rebar_get_current_size (pdev, resno); +if (old <0 ) +return old; + + ret =pci_rebar_set_size (pdev, resno, size); +if (ret) +return ret;pci_dev_for_each_resource (pdev, r, i) {if (i >=PCI_BRIDGE_RESOURCES )
@@ -2389,7 +2402,10 @@ int pci_do_resource_release_and_resize(sif (exclude_bars &BIT (i))continue ; -if (!pci_resource_len (pdev, i) || r->flags != flags) +if (!pci_resource_len (pdev, i)) +continue ; + +if (b_win ? r->parent != b_win : r->flags != flags)continue ; ret =add_to_list (&saved, pdev, r,0 ,0 );
@@ -2403,7 +2419,8 @@ int pci_do_resource_release_and_resize(sif (!bus->self) goto out; - ret =pci_reassign_bridge_resources (bus->self, res->flags, &saved); +down_read (&pci_bus_sem); + ret =pbus_reassign_bridge_resources (bus, res, &saved);if (ret) goto restore;
@@ -2413,14 +2430,22 @@ out:return ret; restore: -/* Revert to the old configuration */ +/* +* Revert to the old configuration. +* +* BAR Size must be restored first because it affects the read-only +* bits in BAR (the old address might not be restorable otherwise +* due to low address bits). +*/ +pci_rebar_set_size (pdev, resno, old); +list_for_each_entry (dev_res, &saved, list) {struct resource *res = dev_res->res;struct pci_dev *dev = dev_res->dev; i = res - dev->resource; -if (res->parent) { +if (resource_assigned (res)) {release_child_resources (res);pci_release_resource (dev, i); }
Greg Kroah-Hartman
maintainerPATCH 836/877 PCI: Fix BAR resize for devices on a root bus
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liz Fong-Jones <[email protected]>
[ Upstream commit d58384c22739848efe14b34e9586e4f1242f33c0 ]
pci_do_resource_release_and_resize() releases device BARs that share a bridge window with the BAR being resized, but when the device sits directly on a root bus (pdev->bus->self == NULL) it then skips resource assignment entirely and returns success, leaving the BARs it just released unassigned (IORESOURCE_UNSET).
Skipping pbus_reassign_bridge_resources() is correct in that case -- there is no bridge window to adjust -- but the device BARs still have to be reassigned. Before the BAR release was consolidated into the PCI core, this case worked for amdgpu because the driver released the BARs itself and then called pci_assign_unassigned_bus_resources() unconditionally after the resize, which assigns unassigned device BARs also on a root bus. Commit db92e3fef53e ("drm/amdgpu: Remove driver side BAR release before resize") removed that call, so nothing assigns the released BARs anymore.
This breaks amdgpu completely on the SolidRun HoneyComb LX2K (NXP LX2160A, arm64, ACPI), where ACPI doesn't expose the Root Port so the GPU endpoint appears directly on a "root bus" of its segment:
amdgpu 0004:01:00.0: BAR 0 [mem 0xa400000000-0xa40fffffff 64bit pref]: releasing amdgpu 0004:01:00.0: BAR 2 [mem 0xa410000000-0xa4101fffff 64bit pref]: releasing amdgpu 0004:01:00.0: sw_init of IP block <gmc_v8_0> failed -19 amdgpu 0004:01:00.0: amdgpu_device_ip_init failed
amdgpu 0004:01:00.0: Fatal error during GPU init
No error is logged because the resize path reports success; amdgpu then finds BAR 0 IORESOURCE_UNSET and bails out with -ENODEV.
When there is no upstream bridge, call pci_bus_assign_resources() on the root bus to place the BARs released above, using the same alignment-sorted algorithm as normal enumeration instead of a manual per-BAR loop. This also walks the rest of the hierarchy under the root bus, as pci_assign_unassigned_bus_resources() used to for amdgpu before commit db92e3fef53e ("drm/amdgpu: Remove driver side BAR release before resize") removed that call -- the core-side fix that commit asked for ("such a problem should be fixed inside pci_resize_resource() instead").
pci_bus_assign_resources() returns void, so failure is detected by checking whether the released BARs are still assigned afterward; if not, roll back as in the bridged case. This is stricter than the bridged path -- it fails on any unplaced resource, not just required ones -- since a root bus typically has one shared window, and failing loudly seemed better than leaving something silently unassigned.
The root bus path also had a locking bug that any fix here necessarily
touches: the old "goto out" jumped to up_read(&pci_bus_sem) without a matching down_read() (as does the "goto restore" taken when pci_dev_res_add_to_list() fails in the release loop). Take pci_bus_sem before the BAR release loop so every path through the function holds it exactly once.
--- drivers/pci/setup-bus.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/pci/setup-bus.c +18 -7
@@ -2380,6 +2380,7 @@ int pci_do_resource_release_and_resize(sunsigned long flags = res->flags;struct pci_dev_resource *dev_res;struct pci_bus *bus = pdev->bus; +struct pci_dev *bridge =pci_upstream_bridge (pdev);struct resource *b_win, *r;LIST_HEAD (saved);unsigned int i;
@@ -2395,6 +2396,8 @@ int pci_do_resource_release_and_resize(sif (ret)return ret; +down_read (&pci_bus_sem); +pci_dev_for_each_resource (pdev, r, i) {if (i >=PCI_BRIDGE_RESOURCES )break ;
@@ -2416,13 +2419,21 @@ int pci_do_resource_release_and_resize(s res->end = res->start +pci_rebar_size_to_bytes (size) -1 ; -if (!bus->self) - goto out; - -down_read (&pci_bus_sem); - ret =pbus_reassign_bridge_resources (bus, res, &saved); -if (ret) - goto restore; +if (bridge) { + ret =pbus_reassign_bridge_resources (bus, res, &saved); +if (ret) + goto restore; + }else { +/* No bridge window to adjust; let the core reassign the bus. */ +pci_bus_assign_resources (bus); + +list_for_each_entry (dev_res, &saved, list) { +if (!resource_assigned (dev_res->res)) { + ret = -ENOSPC ; + goto restore; + } + } + } out:up_read (&pci_bus_sem);
Greg Kroah-Hartman
maintainerPATCH 837/877 packet: use ubuf_info completion for TX_RING packets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 9518405613863d0bf0700927a21367f5942cf058 ]
tpacket_snd sends skbs with frags pointing into its ring slots. Slots are released when skb->destructor is called.
A call to skb_orphan calls skb->destructor before the skb is freed. This can cause the slot to be reused while still linked into the skb.
Switch to standard zerocopy completion (ubuf_info) so the slot is only released once all references to the payload are freed or copied. Restore skb->destructor to standard sock_wfree.
The ubuf_info completion callback can be called with a NULL skb, but only from net_zcopy_put and related API, used by zerocopy implementations that hold their own reference on the uarg, such as MSG_ZEROCOPY. This uarg is only ever completed from skb_zcopy_clear, so skb is always set.
To prevent userspace from aliasing in-flight state on shared ring slots, allocate tpacket_uarg per packet, rather than per slot. This adds a small allocation to the transmit path. Use standard kmalloc to allow backporting to stable kernels.
The uarg holds an sk_wmem_alloc reference, rather than an sk_refcnt reference. packet_free_tx_ring waits on sk_wmem_alloc before freeing the ring pages. Always allocate vec->deferred for tx_ring so page-backed rings also wait on sk_wmem_alloc when skb_copy_ubufs drops page refs before calling tpacket_ubuf_complete.
Drop the tx_ring.pg_vec test that tpacket_destruct_skb performed before accessing the slot. The sk_wmem_alloc reference now guarantees that the slot is valid. The test is also not sufficient by itself, as it reads pg_vec without pg_vec_lock, so it can race with packet_set_ring.
As a result a slot is released when its payload is copied, which can be before transmission (e.g., in skb_orphan_frags_rx). If copied before skb_tx_timestamp() is called, no slot timestamp is recorded, similar to when skb_orphan() was called early in the datapath before this patch.
Revert the now unused previous skb_zcopy_.._nouarg infra.
Depends on commit 992cc9f94ca9 ("net/packet: defer vmalloc TX_RING free until skbs finish").
--- include/linux/skbuff.h | 19 --------- net/packet/af_packet.c | 102 ++++++++++++++++++++++++++++++------------------- 2 files changed, 65 insertions(+), 56 deletions(-)
include/linux/skbuff.h +1 -18
@@ -1807,22 +1807,6 @@ static inline void skb_zcopy_set(struct } } -static inline void skb_zcopy_set_nouarg (struct sk_buff *skb,void *val) -{ -skb_shinfo (skb)->destructor_arg = (void *)((uintptr_t ) val |0x1UL ); -skb_shinfo (skb)->flags |=SKBFL_ZEROCOPY_FRAG ; -} - -static inline bool skb_zcopy_is_nouarg (struct sk_buff *skb) -{ -return (uintptr_t )skb_shinfo (skb)->destructor_arg &0x1UL ; -} - -static inline void *skb_zcopy_get_nouarg (struct sk_buff *skb) -{ -return (void *)((uintptr_t )skb_shinfo (skb)->destructor_arg & ~0x1UL ); -} -static inline void net_zcopy_put (struct ubuf_info *uarg) {if (uarg)
@@ -1845,8 +1829,7 @@ static inline void skb_zcopy_clear(strucstruct ubuf_info *uarg =skb_zcopy (skb);if (uarg) { -if (!skb_zcopy_is_nouarg (skb)) - uarg->ops->complete (skb, uarg, zerocopy_success); + uarg->ops->complete (skb, uarg, zerocopy_success);skb_shinfo (skb)->flags &= ~SKBFL_ALL_ZEROCOPY ; }
net/packet/af_packet.c +64 -38
158 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 838/877 HID: hid-alps: Use pm_ptr instead of #ifdef CONFIG_PM
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bastien Nocera <[email protected]>
[ Upstream commit 5e130f58629a2819c9d053507ad368160d25eb65 ]
This increases build coverage and allows to drop an #ifdef.
Stable-dep-of: aa9dde93e05a ("HID: alps: unregister DualPoint Stick input device on remove")
--- drivers/hid/hid-alps.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hid/hid-alps.c +2 -4
@@ -845,10 +845,8 @@ static struct hid_driver alps_driver = { .raw_event = alps_raw_event, .input_mapping = alps_input_mapping, .input_configured = alps_input_configured, -#ifdef CONFIG_PM - .resume = alps_post_resume, - .reset_resume = alps_post_reset, -#endif + .resume = pm_ptr(alps_post_resume), + .reset_resume = pm_ptr(alps_post_reset), };module_hid_driver (alps_driver);
Greg Kroah-Hartman
maintainerPATCH 839/877 HID: alps: unregister DualPoint Stick input device on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Changcheng <[email protected]>
[ Upstream commit aa9dde93e05a837645fdfd577eea71f0733f0694 ]
alps_input_configured() allocates a second input device ("DualPoint Stick") with input_allocate_device() and registers it, but the alps_driver struct has no .remove handler and input2 is not tracked in hdev->inputs. The default remove path (hid_hw_stop -> hidinput_disconnect) only iterates hdev->inputs, so input2 is never unregistered and leaks on every device removal.
Add a .remove handler that stops the device first (preventing URB callbacks from touching input2 during teardown) and then unregisters input2.
--- drivers/hid/hid-alps.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/hid/hid-alps.c +19 -0
@@ -825,6 +825,24 @@ static int alps_probe(struct hid_devicereturn 0 ; } +static void alps_remove (struct hid_device *hdev) +{ +struct alps_dev *data =hid_get_drvdata (hdev); + +/* +* input2 ("DualPoint Stick") is allocated separately and is not +* tracked in hdev->inputs, so the default remove path +* (hid_hw_stop -> hidinput_disconnect) does not unregister it. +* +* Stop the device first so that no URB callback can touch input2 +* while it is being unregistered, then drop it explicitly. +*/ +hid_hw_stop (hdev); + +if (data->input2) +input_unregister_device (data->input2); +} +static const struct hid_device_id alps_id[] = { {HID_DEVICE (HID_BUS_ANY ,HID_GROUP_ANY ,USB_VENDOR_ID_ALPS_JP ,HID_DEVICE_ID_ALPS_U1_DUAL ) },
@@ -847,6 +865,7 @@ static struct hid_driver alps_driver = { .input_configured = alps_input_configured, .resume = pm_ptr(alps_post_resume), .reset_resume = pm_ptr(alps_post_reset), + .remove = alps_remove, };module_hid_driver (alps_driver);
Greg Kroah-Hartman
maintainerPATCH 840/877 net/sched: act_ct: fix helper UAF due to extensions realloc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
[ Upstream commit dad19b59da050cb60d3f7023dac2a042a84bf0bd ]
While calling the helpers, a raw pointer to the extensions area is wired into expectations list:
-> nf_ct_helper()
-> helper->help()
-> nf_ct_expect_related_report()
-> nf_ct_expect_insert()
-> hlist_add_head_rcu(&exp->lnode, &master_help->expectations)In case the connection is not confirmed yet, more extensions can be added afterwards with *_ext_add() calls reallocating the extension space and leaving the now invalid pointer in the expectations list that is later accessed while removing the expectation.
Make sure that helpers are called at the end after all the other extensions are already added.
Note that the helper rejection now leaves the mark and labels set, but that's not different from how the NAT was handled before or how the mark and the labels were handled on confirmation failure. And there are no atomicity guarantees provided by the API anyway.
--- net/sched/act_ct.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/sched/act_ct.c +12 -6
@@ -1087,19 +1087,25 @@ do_nat: } } -if (nf_ct_is_confirmed (ct) ? ((!cached && !skip_add) || add_helper) : commit) { - err =nf_ct_helper (skb, ct, ctinfo, family); -if (err !=NF_ACCEPT ) - goto nf_error; - } -if (commit) {tcf_ct_act_set_mark (ct, p->mark, p->mark_mask);tcf_ct_act_set_labels (ct, p->labels, p->labels_mask);if (!nf_ct_is_confirmed (ct))nf_conn_act_ct_ext_add (skb, ct, ctinfo); + } +/* Run helpers for the connection if nf_conntrack_in() was executed +* or if we're about to commit. This has to be done after all the +* extensions are already added. +*/ +if (nf_ct_is_confirmed (ct) ? ((!cached && !skip_add) || add_helper) : commit) { + err =nf_ct_helper (skb, ct, ctinfo, family); +if (err !=NF_ACCEPT ) + goto nf_error; + } + +if (commit) {/* This will take care of sending queued events * even if the connection is already confirmed. */
Greg Kroah-Hartman
maintainerPATCH 841/877 net/sched: act_ct: avoid modifying shared unconfirmed ct entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
[ Upstream commit f85009dfcd65e5969526b0db7a49b5413746e630 ]
In a case where skb with an unconfirmed ct entry gets cloned, we may end up processing both again but with different sets of extensions.
The series of events:
1. The first clone wants to commit and runs the helpers wiring up the extension pointer into the expectation list.
2. Then it looses the confirmation keeping the entry unconfirmed.
3. Second clone now wants to commit labels or run NAT and adds the new extension for that breaking the pointer in the expectation list causing UAF on the destruction path later.
While this is possible to trigger, there should be no practical network pipeline where we need to process both clones without modifications in the same zone. So, let's just reset the entry in case for some reason we got an skb with a shared one. This doesn't affect any known use cases, but avoids any potential problems with sharing and modification of the unconfirmed ct entry.
Unlike openvswitch module, act_ct allows for NAT without commit. Changing that would be a uAPI break. So, act_ct needs to reset on NAT regardless of the commit flag to avoid reallocation of the extension space. This, however, doesn't really change the picture for sensible networking cases as there should be no need to run the same packet twice (before and after the clone) through conntrack without packet header or zone changes and without commit.
The fixes tag points to the introduction of helpers, since that's the main UAF trigger for the sharing.
--- net/sched/act_ct.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
net/sched/act_ct.c +16 -2
@@ -977,11 +977,11 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct struct tcf_result *res) {struct net *net =dev_net (skb->dev); +bool cached, commit, clear, nat;enum ip_conntrack_info ctinfo;struct tcf_ct *c =to_ct (a);struct nf_conn *tmpl =NULL ;struct nf_hook_state state; -bool cached, commit, clear;int nh_ofs, err, retval;struct tcf_ct_params *p;bool add_helper = false;
@@ -996,6 +996,7 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct retval = p->action; commit = p->ct_action &TCA_CT_ACT_COMMIT ; clear = p->ct_action &TCA_CT_ACT_CLEAR ; + nat = p->ct_action &TCA_CT_ACT_NAT ; tmpl = p->tmpl;tcf_lastuse_update (&c->tcf_tm);
@@ -1044,6 +1045,19 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct* different zone. */ cached =tcf_ct_skb_nfct_cached (net, skb, p); + +/* If the ct entry is not confirmed and shared with some other skb, +* e.g., a cloned one, we can't just modify it with a commit or nat +* as we must not modify the extension set. Reset. +*/ +if (cached && (commit || nat)) { + ct =nf_ct_get (skb, &ctinfo); +if (ct && !nf_ct_is_confirmed (ct) &&nf_ct_shared (ct)) { +nf_reset_ct (skb); + cached = false; + } + } +if (!cached) {if (tcf_ct_flow_table_lookup (p, skb, family)) { skip_add = true;
@@ -1081,7 +1095,7 @@ do_nat:if (err) goto drop; add_helper = true; -if (p->ct_action &TCA_CT_ACT_NAT && !nfct_seqadj (ct)) { +if (nat && !nfct_seqadj (ct)) {if (!nfct_seqadj_ext_add (ct)) goto drop; }
Greg Kroah-Hartman
maintainerPATCH 842/877 net: ipconfig: Remove outdated comment and indent code block
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit e405b3c9d4aaa10972525fe2ea5cf94224020561 ]
The comment has been around ever since commit 1da177e4c3f4 ("Linux-2.6.12-rc2") and can be removed. Remove it and indent the code block accordingly.
Stable-dep-of: e47a1958e12a ("net: ipconfig: bound DHCP option construction")
--- net/ipv4/ipconfig.c | 89 ++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 47 deletions(-)
net/ipv4/ipconfig.c +42 -47
@@ -679,8 +679,18 @@ static const u8 ic_bootp_cookie[4] = { 9static void __init ic_dhcp_init_options (u8 *options,struct ic_device *d) { -u8 mt = ((ic_servaddr ==NONE ) - ?DHCPDISCOVER :DHCPREQUEST ); +static const u8 ic_req_params[] = { +1 ,/* Subnet mask */ +3 ,/* Default gateway */ +6 ,/* DNS server */ +12 ,/* Host name */ +15 ,/* Domain name */ +17 ,/* Boot path */ +26 ,/* MTU */ +40 ,/* NIS domain name */ +42 ,/* NTP servers */ + }; +u8 mt = (ic_servaddr ==NONE ) ?DHCPDISCOVER :DHCPREQUEST ;u8 *e = options;int len;
@@ -705,51 +715,36 @@ ic_dhcp_init_options(u8 *options, struct e +=4 ; } -/* always? */ - { -static const u8 ic_req_params[] = { -1 ,/* Subnet mask */ -3 ,/* Default gateway */ -6 ,/* DNS server */ -12 ,/* Host name */ -15 ,/* Domain name */ -17 ,/* Boot path */ -26 ,/* MTU */ -40 ,/* NIS domain name */ -42 ,/* NTP servers */ - }; - - *e++ =55 ;/* Parameter request list */ - *e++ =sizeof (ic_req_params); -memcpy (e, ic_req_params,sizeof (ic_req_params)); - e +=sizeof (ic_req_params); - -if (ic_host_name_set) { - *e++ =12 ;/* host-name */ - len =strlen (utsname ()->nodename); - *e++ = len; -memcpy (e,utsname ()->nodename, len); - e += len; - } -if (*vendor_class_identifier) { -pr_info ("DHCP: sending class identifier \"%s\"\n" , - vendor_class_identifier); - *e++ =60 ;/* Class-identifier */ - len =strlen (vendor_class_identifier); - *e++ = len; -memcpy (e, vendor_class_identifier, len); - e += len; - } - len =strlen (dhcp_client_identifier +1 ); -/* the minimum length of identifier is 2, include 1 byte type, -* and can not be larger than the length of options -*/ -if (len >=1 && len <312 - (e - options) -1 ) { - *e++ =61 ; - *e++ = len +1 ; -memcpy (e, dhcp_client_identifier, len +1 ); - e += len +1 ; - } + *e++ =55 ;/* Parameter request list */ + *e++ =sizeof (ic_req_params); +memcpy (e, ic_req_params,sizeof (ic_req_params)); + e +=sizeof (ic_req_params); + +if (ic_host_name_set) { + *e++ =12 ;/* host-name */ + len =strlen (utsname ()->nodename); + *e++ = len; +memcpy (e,utsname ()->nodename, len); + e += len; + } +if (*vendor_class_identifier) { +pr_info ("DHCP: sending class identifier \"%s\"\n" , + vendor_class_identifier); + *e++ =60 ;/* Class-identifier */ + len =strlen (vendor_class_identifier); + *e++ = len; +memcpy (e, vendor_class_identifier, len); + e += len; + } + len =strlen (dhcp_client_identifier +1 ); +/* the minimum length of identifier is 2, include 1 byte type, +* and can not be larger than the length of options +*/ +if (len >=1 && len <312 - (e - options) -1 ) { + *e++ =61 ; + *e++ = len +1 ; +memcpy (e, dhcp_client_identifier, len +1 ); + e += len +1 ; } *e++ =255 ;/* End of the list */
Greg Kroah-Hartman
maintainerPATCH 843/877 net: ipconfig: bound DHCP option construction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuqi Xu <[email protected]>
[ Upstream commit e47a1958e12abc3a17b5231a4f21c8f1bf662e08 ]
ic_dhcp_init_options() appends the hostname (option 12), vendor-class (option 60) and client-ID (option 61) options into the fixed 312-byte bootp_pkt.exten[] buffer. Only the client-ID branch checked the remaining space; the hostname and vendor-class writes were unbounded.
A 64-byte hostname together with the maximum 252-byte dhcpclass= identifier needs 18 + (2 + 64) + (2 + 252) = 338 of the 312 available bytes even before the terminating END marker, so the vendor-class memcpy runs past the end of exten[]. With CONFIG_FORTIFY_SOURCE this is reported as a field-spanning write and, when the kernel is booted with panic_on_warn=1, aborts boot with a panic.
Route the optional options through a common helper that makes sure the option, its 2-byte header and the END marker all fit and drops an option that would not. Configurations with short options keep sending exactly the same bytes as before.
--- net/ipv4/ipconfig.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-)
net/ipv4/ipconfig.c +26 -19
@@ -676,6 +676,24 @@ static const u8 ic_bootp_cookie[4] = { 9#ifdef IPCONFIG_DHCP +static bool __init +ic_dhcp_add_option (u8 **options,const u8 *end,u8 type,const void *value, +int len) +{ +u8 *e = *options; + +/* leave room for the option header and the END marker */ +if (len >U8_MAX || end - e < len +3 ) +return false; + + *e++ = type; + *e++ = len; +memcpy (e, value, len); + *options = e + len; + +return true; +} +static void __init ic_dhcp_init_options (u8 *options,struct ic_device *d) {
@@ -691,6 +709,7 @@ ic_dhcp_init_options(u8 *options, struct 42, /* NTP servers */ };u8 mt = (ic_servaddr ==NONE ) ?DHCPDISCOVER :DHCPREQUEST ; +u8 *end = options +sizeof (((struct bootp_pkt *)0 )->exten);u8 *e = options;int len;
@@ -721,31 +740,19 @@ ic_dhcp_init_options(u8 *options, struct e +=sizeof (ic_req_params);if (ic_host_name_set) { - *e++ =12 ;/* host-name */ len =strlen (utsname ()->nodename); - *e++ = len; -memcpy (e,utsname ()->nodename, len); - e += len; +ic_dhcp_add_option (&e, end,12 ,utsname ()->nodename, len); }if (*vendor_class_identifier) { -pr_info ("DHCP: sending class identifier \"%s\"\n" , - vendor_class_identifier); - *e++ =60 ;/* Class-identifier */ len =strlen (vendor_class_identifier); - *e++ = len; -memcpy (e, vendor_class_identifier, len); - e += len; +if (ic_dhcp_add_option (&e, end,60 , vendor_class_identifier, len)) +pr_info ("DHCP: sending class identifier \"%s\"\n" , + vendor_class_identifier); } len =strlen (dhcp_client_identifier +1 ); -/* the minimum length of identifier is 2, include 1 byte type, -* and can not be larger than the length of options -*/ -if (len >=1 && len <312 - (e - options) -1 ) { - *e++ =61 ; - *e++ = len +1 ; -memcpy (e, dhcp_client_identifier, len +1 ); - e += len +1 ; - } +/* the minimum length of identifier is 2, include 1 byte type */ +if (len >=1 ) +ic_dhcp_add_option (&e, end,61 , dhcp_client_identifier, len +1 ); *e++ =255 ;/* End of the list */ }
Greg Kroah-Hartman
maintainerPATCH 844/877 net: ena: Remove autopolling mode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Dr. David Alan Gilbert" <[email protected]>
[ Upstream commit b356b9170815f822394667010d478d53901ff581 ]
This manually reverts
commit a4e262cde3cd ("net: ena: allow automatic fallback to polling mode")
which is unused.
(I did it manually because there are other minor comment and function changes surrounding it).
Build tested only.
Stable-dep-of: 9476b4468862 ("net: ena: fix MMIO read buffer leak on probe failure")
--- drivers/net/ethernet/amazon/ena/ena_com.c | 25 +++++-------------------- drivers/net/ethernet/amazon/ena/ena_com.h | 14 -------------- 2 files changed, 5 insertions(+), 34 deletions(-)
drivers/net/ethernet/amazon/ena/ena_com.c +5 -20
@@ -763,25 +763,16 @@ static int ena_com_wait_and_process_admiif (comp_ctx->status ==ENA_CMD_COMPLETED ) {netdev_err (admin_queue->ena_dev->net_device, -"The ena device sent a completion but the driver didn't receive a MSI-X interrupt (cmd %d), autopolling mode is %s\n" , - comp_ctx->cmd_opcode, admin_queue->auto_polling ?"ON" :"OFF" ); -/* Check if fallback to polling is enabled */ -if (admin_queue->auto_polling) - admin_queue->polling = true; +"The ena device sent a completion but the driver didn't receive a MSI-X interrupt (cmd %d)\n" , + comp_ctx->cmd_opcode); }else {netdev_err (admin_queue->ena_dev->net_device,"The ena device didn't send a completion for the admin cmd %d status %d\n" , comp_ctx->cmd_opcode, comp_ctx->status); } -/* Check if shifted to polling mode. -* This will happen if there is a completion without an interrupt -* and autopolling mode is enabled. Continuing normal execution in such case -*/ -if (!admin_queue->polling) { - admin_queue->running_state = false; - ret = -ETIME ; - goto err; - } + admin_queue->running_state = false; + ret = -ETIME ; + goto err; } ret =ena_com_comp_status_to_errno (admin_queue, comp_ctx->comp_status);
@@ -1650,12 +1641,6 @@ void ena_com_set_admin_polling_mode(stru ena_dev->admin_queue.polling = polling; } -void ena_com_set_admin_auto_polling_mode (struct ena_com_dev *ena_dev, -bool polling) -{ - ena_dev->admin_queue.auto_polling = polling; -} -int ena_com_mmio_reg_read_request_init (struct ena_com_dev *ena_dev) {struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read;
drivers/net/ethernet/amazon/ena/ena_com.h +0 -14
@@ -224,9 +224,6 @@ struct ena_com_admin_queue {/* Indicate if the admin queue should poll for completion */ bool polling; -/* Define if fallback to polling mode should occur */ -bool auto_polling; -u16 curr_cmd_id;/* Indicate that the ena was initialized and can
@@ -493,17 +490,6 @@ bool ena_com_get_admin_running_state(str*/ void ena_com_set_admin_polling_mode (struct ena_com_dev *ena_dev,bool polling); -/* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode -* @ena_dev: ENA communication layer struct -* @polling: Enable/Disable polling mode -* -* Set the autopolling mode. -* If autopolling is on: -* In case of missing interrupt when data is available switch to polling. -*/ -void ena_com_set_admin_auto_polling_mode (struct ena_com_dev *ena_dev, -bool polling); -/* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler * @ena_dev: ENA communication layer struct *
Greg Kroah-Hartman
maintainerPATCH 845/877 net: ena: fix MMIO read buffer leak on probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 9476b4468862927297c94c440863cd8ed1e7cc83 ]
ena_device_init() initializes the MMIO read mechanism with ena_com_mmio_reg_read_request_init(), which allocates a coherent DMA buffer for MMIO read responses.
The normal removal path releases this buffer through ena_com_mmio_reg_read_request_destroy(). However, if ena_probe() fails after ena_device_init() succeeds, the error path destroys the admin resources and eventually frees ena_dev without destroying the MMIO read request, leaving the coherent DMA buffer allocated.
Call ena_com_mmio_reg_read_request_destroy() in the probe error path before releasing the remaining device resources.
This issue was found by manual code inspection.
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/amazon/ena/ena_netdev.c +1 -0
@@ -4088,6 +4088,7 @@ err_worker_destroy: err_device_destroy:ena_com_delete_host_info (ena_dev);ena_com_admin_destroy (ena_dev); +ena_com_mmio_reg_read_request_destroy (ena_dev); err_metrics_destroy:ena_com_delete_customer_metrics_buffer (ena_dev); err_netdev_destroy:
Greg Kroah-Hartman
maintainerPATCH 846/877 KVM: SVM: Flush cache only on CPUs running SEV guest
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zheyun Shen <[email protected]>
[ Upstream commit 6f38f8c574642a822f2e85f079fa29a49176c49c ]
On AMD CPUs without ensuring cache consistency, each memory page reclamation in an SEV guest triggers a call to do WBNOINVD/WBINVD on all CPUs, thereby affecting the performance of other programs on the host.
Typically, an AMD server may have 128 cores or more, while the SEV guest might only utilize 8 of these cores. Meanwhile, host can use qemu-affinity to bind these 8 vCPUs to specific physical CPUs.
Therefore, keeping a record of the physical core numbers each time a vCPU runs can help avoid flushing the cache for all CPUs every time.
Take care to allocate the cpumask used to track which CPUs have run a vCPU when copying or moving an "encryption context", as nothing guarantees memory in a mirror VM is a strict subset of the ASID owner, and the destination VM for intrahost migration needs to maintain it's own set of CPUs. E.g. for intrahost migration, if a CPU was used for the source VM but not the destination VM, then it can only have cached memory that was accessible to the source VM. And a CPU that was run in the source is also used by the destination is no different than a CPU that was run in the destination only.
Note, KVM is guaranteed to do flush caches prior to sev_vm_destroy(), thanks to kvm_arch_guest_memory_reclaimed for SEV and SEV-ES, and kvm_arch_gmem_invalidate() for SEV-SNP. I.e. it's safe to free the cpumask prior to unregistering encrypted regions and freeing the ASID.
Opportunistically clean up sev_vm_destroy()'s comment regarding what is (implicitly, what isn't) skipped for mirror VMs.
Backport notes for Linux 6.12:
The WBNOINVD prerequisites are not present. Keep WBINVD semantics and implement sev_writeback_caches as a local macro over the existing wbinvd_on_cpu API. This preserves per-VM CPU tracking and the interface needed by 93de2a6a4b91 without adding any functions or x86 cache helpers. An empty mask naturally performs no flush; CPUs are never removed.
Keep the stable tree's sev_mirror_lock protection, relocated sev_free_vcpu and GHCB cleanup, void pre_sev_run signature, do_wbinvd label, and existing all-CPU flush during VM destruction. Add the kvm local needed by tracking.
Allocate the mask after SNP guest-request setup, with matching SNP cleanup on allocation failure, so failed initialization never leaves a freed mask in the VM. Free the mask even for a migrated source that is no longer SEV, as in 12c1f6e03f944, to avoid leaking it on destruction. Destination and mirror VMs receive independent zeroed masks. Keep the migration allocation context so 93de2a6a4b91 applies unchanged.
Stable-dep-of: 93de2a6a4b91 ("KVM: SEV: Do cache maintenance on the source VM during intra-host migration")
--- arch/x86/kvm/svm/sev.c | 67 +++++++++++++++++++++++++++++++++++++++++-------- arch/x86/kvm/svm/svm.h | 1 2 files changed, 58 insertions(+), 10 deletions(-)
arch/x86/kvm/svm/sev.c +57 -10
@@ -458,6 +458,13 @@ static int __sev_guest_init(struct kvm * goto e_free; } +if (!zalloc_cpumask_var (&sev->have_run_cpus,GFP_KERNEL_ACCOUNT )) { + ret = -ENOMEM ; +if (vm_type ==KVM_X86_SNP_VM ) +snp_guest_req_cleanup (kvm); + goto e_free; + } +INIT_LIST_HEAD (&sev->regions_list);INIT_LIST_HEAD (&sev->mirror_vms); sev->need_init = false;
@@ -715,6 +722,19 @@ static void sev_clflush_pages(struct pag } } +/* +* Write back guest-tagged cache entries before returning memory to the host. +* This tree has no WBNOINVD or masked WBINVD helper, so use WBINVD on each CPU +* that has entered the guest. Keep CPUs in the mask to avoid racing concurrent +* flushes and VMRUN; callers must serialize memory reclaim against guest access. +*/ +#define sev_writeback_caches (kvm) do { \ + const struct cpumask *__mask = to_kvm_sev_info(kvm)->have_run_cpus; \ + int __cpu; \ + for_each_cpu(__cpu, __mask) \ + wbinvd_on_cpu(__cpu); \ +} while (0) +static unsigned long get_num_contig_pages (unsigned long idx,struct page **inpages,unsigned long npages) {
@@ -2134,6 +2154,17 @@ int sev_vm_move_enc_context_from(structif (ret) goto out_source_vcpu; +/* +* Allocate a new have_run_cpus for the destination, i.e. don't copy +* the set of CPUs from the source. If a CPU was used to run a vCPU in +* the source VM but is never used for the destination VM, then the CPU +* can only have cached memory that was accessible to the source VM. +*/ +if (!zalloc_cpumask_var (&dst_sev->have_run_cpus,GFP_KERNEL_ACCOUNT )) { + ret = -ENOMEM ; + goto out_source_vcpu; + } +sev_migrate_from (kvm, source_kvm);kvm_vm_dead (source_kvm); cg_cleanup_sev = src_sev;
@@ -2795,12 +2826,7 @@ int sev_mem_enc_unregister_region(struct goto failed; } -/* -* Ensure that all guest tagged cache entries are flushed before -* releasing the pages back to the system for use. CLFLUSH will -* not do this, so issue a WBINVD. -*/ -wbinvd_on_all_cpus (); +sev_writeback_caches (kvm);__unregister_enc_region_locked (kvm, region);
@@ -2843,12 +2869,17 @@ int sev_vm_copy_enc_context_from(struct goto e_unlock; } + mirror_sev =to_kvm_sev_info (kvm); +if (!zalloc_cpumask_var (&mirror_sev->have_run_cpus,GFP_KERNEL_ACCOUNT )) { + ret = -ENOMEM ; + goto e_unlock; + } +/* * The mirror kvm holds an enc_context_owner ref so its asid can't * disappear until we're done with it */ source_sev =to_kvm_sev_info (source_kvm); - mirror_sev =to_kvm_sev_info (kvm);/* Set enc_context_owner and copy its encryption context over */ mutex_lock (&sev_mirror_lock);
@@ -2909,6 +2940,12 @@ void sev_vm_destroy(struct kvm *kvm)struct list_head *head = &sev->regions_list;struct list_head *pos, *q; +/* +* Free the mask even if the VM is not *currently* an SEV VM, as it may +* have been an SEV VM prior to intra-host migration. +*/ +free_cpumask_var (sev->have_run_cpus); +if (!sev_guest (kvm))return ;
@@ -3217,7 +3254,7 @@ static void sev_flush_encrypted_page(strreturn ; do_wbinvd: -wbinvd_on_all_cpus (); +sev_writeback_caches (vcpu->kvm); }void sev_guest_memory_reclaimed (struct kvm *kvm)
@@ -3231,7 +3268,7 @@ void sev_guest_memory_reclaimed(struct kif (!sev_guest (kvm) ||sev_snp_guest (kvm))return ; -wbinvd_on_all_cpus (); +sev_writeback_caches (kvm); }static void dump_ghcb (struct vcpu_svm *svm)
@@ -3550,7 +3587,17 @@ skip_vmsa_free:void pre_sev_run (struct vcpu_svm *svm,int cpu) {struct svm_cpu_data *sd =per_cpu_ptr (&svm_data, cpu); -unsigned int asid =sev_get_asid (svm->vcpu.kvm); +struct kvm *kvm = svm->vcpu.kvm; +unsigned int asid =sev_get_asid (kvm); + +/* +* To optimize cache flushes when memory is reclaimed from an SEV VM, +* track physical CPUs that enter the guest for SEV VMs and thus can +* have encrypted, dirty data in the cache, and flush caches only for +* CPUs that have entered the guest. +*/ +if (!cpumask_test_cpu (cpu,to_kvm_sev_info (kvm)->have_run_cpus)) +cpumask_set_cpu (cpu,to_kvm_sev_info (kvm)->have_run_cpus);/* Assign the asid allocated with this SEV guest */ svm->asid = asid;
arch/x86/kvm/svm/svm.h +1 -0
@@ -113,6 +113,7 @@ struct kvm_sev_info {void *guest_req_buf;/* Bounce buffer for SNP Guest Request input */ void *guest_resp_buf;/* Bounce buffer for SNP Guest Request output */ struct mutex guest_req_mutex;/* Must acquire before using bounce buffers */ +cpumask_var_t have_run_cpus;/* CPUs that have done VMRUN for this VM. */ };struct kvm_svm {
Greg Kroah-Hartman
maintainerPATCH 847/877 KVM: SEV: Do cache maintenance on the source VM during intra-host migration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 93de2a6a4b91b72607136dd656edf03fb399d27f ]
Manually perform cache maintenance on the source VM during intra-host migration to ensure no stale data is left in CPU caches after the VM is destroyed. Because the source VM is "converted" to a non-SEV VM, KVM's memory reclaim flows won't trigger cache maintenance, e.g. when all guest memory is reclaimed in response to detaching from the mmu_notifier.
Note, relying on the destination VM to do cache maintenance isn't an option as KVM doesn't require identical guest memory configurations, i.e. the source VM may have access to memory that the destination VM does not. Enforcing equivalent memory configurations is infeasible, as it would require a *deep* comparison of memslots, e.g. to verify that not only are the memslot identical, but what the memslots point at is also identical.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kvm/svm/sev.c +10 -0
@@ -2020,6 +2020,12 @@ static void sev_migrate_from(struct kvm src->pages_locked =0 ; src->es_active = false; +/* +* Do cache maintenance on the source VM as it is no longer an SEV VM, +* i.e. memory reclaim flows won't trigger cache maintenance on the VM. +*/ +sev_writeback_caches (src_kvm); +list_cut_before (&dst->regions_list, &src->regions_list, &src->regions_list);mutex_lock (&sev_mirror_lock);
@@ -2159,6 +2165,10 @@ int sev_vm_move_enc_context_from(struct* the set of CPUs from the source. If a CPU was used to run a vCPU in * the source VM but is never used for the destination VM, then the CPU * can only have cached memory that was accessible to the source VM. +* Furthermore, KVM *must* perform cache maintenance on the source VM, +* as the source VM may have access to memory that the destination VM +* does not, i.e. KVM could skip flushes if memory is reclaimed from +* the old VM but not the new VM. */ if (!zalloc_cpumask_var (&dst_sev->have_run_cpus,GFP_KERNEL_ACCOUNT )) { ret = -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 848/877 perf/x86/intel: Update event constraints and cache_extra_regsfor LNL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit 331c3e4fa39a87560c09bdd878652090ae040b69 ]
Update perf hard-coded event constraints and cache_extra_regs[] for Lunarlake according to the latest LNL perfmon events (V1.22).
LNL introduces new extra register values for the OCR L3 cache events, so introduce lnc_hw_cache_extra_regs[] and skt_hw_cache_extra_regs[] to reflect the changes.
LNL perfmon events:
https://github.com/intel/perfmon/blob/main/LNL/events/lunarlake_lioncove_core.json
https://github.com/intel/perfmon/blob/main/LNL/events/lunarlake_skymont_core.json
[Backport to 6.18: retain the Lion Cove PEBS constraint additions needed by 7c944595cc43 ("perf/x86/intel: Remove incorrect LionCove PEBS data-source constraints"). Keep the matching regular counter masks for TOPDOWN.MEMORY_BOUND_SLOTS (0x10a4, 0x8) and MEM_INST_RETIRED.ANY (0x87d0, 0x3ff), since that fix removes their PEBS-specific entries and falls back to the regular constraint table.
Omit the unrelated cache extra-register tables and PMU initialization changes, which depend on cache-event refactoring and intel_pmu_init_cmt() absent from 6.18. Also omit the unrelated fixed-counter, non-PEBS OCR, 0x00e0, and Skymont constraint updates. No functions are added.]
Stable-dep-of: 7c944595cc43 ("perf/x86/intel: Remove incorrect LionCove PEBS data-source constraints")
--- arch/x86/events/intel/core.c | 3 ++- arch/x86/events/intel/ds.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +2 -1
@@ -411,11 +411,12 @@ static struct event_constraint intel_lncINTEL_UEVENT_CONSTRAINT (0x0ca3 ,0x4 ),INTEL_UEVENT_CONSTRAINT (0x04a4 ,0x1 ),INTEL_UEVENT_CONSTRAINT (0x08a4 ,0x1 ), -INTEL_UEVENT_CONSTRAINT (0x10a4 ,0x1 ), +INTEL_UEVENT_CONSTRAINT (0x10a4 ,0x8 ),INTEL_UEVENT_CONSTRAINT (0x01b1 ,0x8 ),INTEL_UEVENT_CONSTRAINT (0x01cd ,0x3fc ),INTEL_UEVENT_CONSTRAINT (0x02cd ,0x3 ), +INTEL_UEVENT_CONSTRAINT (0x87d0 ,0x3ff ),INTEL_EVENT_CONSTRAINT_RANGE (0xd0 ,0xdf ,0xf ), INTEL_UEVENT_CONSTRAINT(0x00e0, 0xf),
arch/x86/events/intel/ds.c +8 -0
@@ -1179,6 +1179,13 @@ struct event_constraint intel_lnc_pebs_eINTEL_FLAGS_UEVENT_CONSTRAINT (0x100 ,0x100000000ULL ),/* INST_RETIRED.PREC_DIST */ INTEL_FLAGS_UEVENT_CONSTRAINT (0x0400 ,0x800000000ULL ), +INTEL_FLAGS_UEVENT_CONSTRAINT (0x012a ,0x1 ),/* OCR.* events */ +INTEL_FLAGS_UEVENT_CONSTRAINT (0x012b ,0x1 ),/* OCR.* events */ + +INTEL_FLAGS_UEVENT_CONSTRAINT (0x04a4 ,0x1 ),/* TOPDOWN.BAD_SPEC_SLOTS */ +INTEL_FLAGS_UEVENT_CONSTRAINT (0x08a4 ,0x1 ),/* TOPDOWN.BR_MISPREDICT_SLOTS */ +INTEL_FLAGS_UEVENT_CONSTRAINT (0x10a4 ,0x8 ),/* TOPDOWN.MEMORY_BOUND_SLOTS */ +INTEL_HYBRID_LDLAT_CONSTRAINT (0x1cd ,0x3fc ),INTEL_HYBRID_STLAT_CONSTRAINT (0x2cd ,0x3 ), INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD(0x11d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_LOADS */
@@ -1188,6 +1195,7 @@ struct event_constraint intel_lnc_pebs_eINTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST (0x42d0 ,0xf ),/* MEM_INST_RETIRED.SPLIT_STORES */ INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD (0x81d0 ,0xf ),/* MEM_INST_RETIRED.ALL_LOADS */ INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST (0x82d0 ,0xf ),/* MEM_INST_RETIRED.ALL_STORES */ +INTEL_FLAGS_UEVENT_CONSTRAINT (0x87d0 ,0x3ff ),/* MEM_INST_RETIRED.ANY */ INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_LD_RANGE(0xd1, 0xd4, 0xf),
Greg Kroah-Hartman
maintainerPATCH 849/877 perf/x86/intel: Remove incorrect LionCove PEBS data-source constraints
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit 7c944595cc43a664019edc22505b6d6f6039be5e ]
On Lion Cove, PEBS data source is valid only for these events:
- MEM_TRANS_RETIRED.LOAD_LATENCY (0x1cd)
- MEM_TRANS_RETIRED.STORE_SAMPLE (0x2cd)
The perfmon database (https://github.com/intel/perfmon) previously tagged additional memory events such as MEM_INST_RETIRED.STLB_MISS_LOADS with L1_Hit_Indication, implying PEBS data-source support, which is incorrect. The database has since been fixed, but intel_lnc_pebs_event_constraints[] still follows the old definition and marks those events as data-source capable.
As a result, get_data_src() may decode data-source information for events that do not provide valid PEBS data-source data and mislead users.
Remove those non-data-source memory events from the Lion Cove PEBS constraint table so matching falls back to the regular non-PEBS constraints, which already provide the same counter constraints.
Also update lnc_latency_data() to decode LOAD/STORE flags explicitly when setting memory operation direction, for consistency with other *_latency_data() helpers.
--- arch/x86/events/intel/ds.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
arch/x86/events/intel/ds.c +5 -17
@@ -373,7 +373,11 @@ static u64 lnc_latency_data(struct perf_ val |=P (BLK ,NA ); src.val = val; -if (event->hw.flags &PERF_X86_EVENT_PEBS_ST_HSW ) +if (event->hw.flags & + (PERF_X86_EVENT_PEBS_LDLAT |PERF_X86_EVENT_PEBS_LD_HSW )) + src.mem_op =P (OP ,LOAD ); +if (event->hw.flags & + (PERF_X86_EVENT_PEBS_STLAT |PERF_X86_EVENT_PEBS_ST_HSW )) src.mem_op =P (OP ,STORE );return src.val;
@@ -1182,24 +1186,8 @@ struct event_constraint intel_lnc_pebs_eINTEL_FLAGS_UEVENT_CONSTRAINT (0x012a ,0x1 ),/* OCR.* events */ INTEL_FLAGS_UEVENT_CONSTRAINT (0x012b ,0x1 ),/* OCR.* events */ -INTEL_FLAGS_UEVENT_CONSTRAINT (0x04a4 ,0x1 ),/* TOPDOWN.BAD_SPEC_SLOTS */ -INTEL_FLAGS_UEVENT_CONSTRAINT (0x08a4 ,0x1 ),/* TOPDOWN.BR_MISPREDICT_SLOTS */ -INTEL_FLAGS_UEVENT_CONSTRAINT (0x10a4 ,0x8 ),/* TOPDOWN.MEMORY_BOUND_SLOTS */ -INTEL_HYBRID_LDLAT_CONSTRAINT (0x1cd ,0x3fc ), INTEL_HYBRID_STLAT_CONSTRAINT(0x2cd, 0x3), -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD (0x11d0 ,0xf ),/* MEM_INST_RETIRED.STLB_MISS_LOADS */ -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST (0x12d0 ,0xf ),/* MEM_INST_RETIRED.STLB_MISS_STORES */ -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD (0x21d0 ,0xf ),/* MEM_INST_RETIRED.LOCK_LOADS */ -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD (0x41d0 ,0xf ),/* MEM_INST_RETIRED.SPLIT_LOADS */ -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST (0x42d0 ,0xf ),/* MEM_INST_RETIRED.SPLIT_STORES */ -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD (0x81d0 ,0xf ),/* MEM_INST_RETIRED.ALL_LOADS */ -INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST (0x82d0 ,0xf ),/* MEM_INST_RETIRED.ALL_STORES */ -INTEL_FLAGS_UEVENT_CONSTRAINT (0x87d0 ,0x3ff ),/* MEM_INST_RETIRED.ANY */ - -INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_LD_RANGE (0xd1 ,0xd4 ,0xf ), - -INTEL_FLAGS_EVENT_CONSTRAINT (0xd0 ,0xf ),/* * Everything else is handled by PMU_FL_PEBS_ALL, because we
Greg Kroah-Hartman
maintainerPATCH 850/877 perf/x86/intel: Update event constraints and cache_extra_regsfor ADL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit 4ef863352bcde482d65722ed721c3fd3967a67d6 ]
Update perf hard-coded event constraints and cache_extra_regs[] for Alderlake according to the latest ADL perfmon events (V1.39).
One important note is that ADL has differences on the L3/node related OCR events although it shares same uarch with SPR server, e.g., ADL has different extra MSR values and no node events. So some variants of structures and functions are introduced to reflect these differences, like adl_glc_hw_cache_event_ids[], adl_glc_hw_cache_extra_regs[] and intel_pmu_init_glc_hybrid(), etc.
Please note these changes would temporarily impact other platforms like MTL/ARL-U which shares hard-coded event structures, but it would be fixed soon in subsequent patches.
ADL perfmon events:
https://github.com/intel/perfmon/blob/main/ADL/events/alderlake_goldencove_core.json
https://github.com/intel/perfmon/blob/main/ADL/events/alderlake_gracemont_core.json
[Stable dependency adaptation]
Retain only the Gracemont STORE_LATENCY (event 0x6d0) PEBS counter-mask update from 0xf to 0x3f in intel_grt_pebs_event_constraints[]. This is the preimage required by target 89dc568e8c0be60e05e5fcd0b528c79077d7b84b. The existing latency decoder and LOAD/STORE constraint macros are already available in this stable tree, so no new functions are needed.
Drop all core.c changes: the cache-event tables, offcore MSR masks, fixed-event aliases and hybrid initialization changes are unrelated to the target. Their upstream context includes cache tables absent from 6.18, and retaining them would bring in an unnecessary helper function and broader platform changes.
[ sashal: Reduced backport -- upstream 4ef863352bcde touches 2 file(s), this
backport carries 1. Not backported here:
arch/x86/events/intel/core.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 89dc568e8c0b ("perf/x86/intel: Fix GRT PEBS load/store direction for latency events, to fix sample classification")
--- arch/x86/events/intel/ds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/ds.c +1 -1
@@ -986,7 +986,7 @@ struct event_constraint intel_glm_pebs_estruct event_constraint intel_grt_pebs_event_constraints[] = {/* Allow all events as PEBS with no flags */ INTEL_HYBRID_LAT_CONSTRAINT (0x5d0 ,0x3 ), -INTEL_HYBRID_LAT_CONSTRAINT (0x6d0 ,0xf ), +INTEL_HYBRID_LAT_CONSTRAINT (0x6d0 ,0x3f ),EVENT_CONSTRAINT_END };
Greg Kroah-Hartman
maintainerPATCH 851/877 perf/x86/intel: Fix GRT PEBS load/store direction for latency events, to fix sample classification
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit 89dc568e8c0be60e05e5fcd0b528c79077d7b84b ]
On Gracemont, intel_grt_pebs_event_constraints[] applies LAT_CONSTRAINT constraints to MEM_UOPS_RETIRED.{LOAD,STORE}_LATENCY, but does not set explicit LOAD/STORE flags for those events.
The PEBS latency path (pebs_latency_data(), via __grt_latency_data()) uses the event flags to determine memory operation direction. Without an explicit STORE flag, samples from MEM_UOPS_RETIRED.STORE_LATENCY can be misclassified as LOADs.
Set explicit LOAD/STORE flags in intel_grt_pebs_event_constraints[] for:
- MEM_UOPS_RETIRED.LOAD_LATENCY
- MEM_UOPS_RETIRED.STORE_LATENCY
Also update __grt_latency_data() to explicitly interpret these flags when assigning the sampled memory operation direction.
This fixes incorrect STORE sample classification.
--- arch/x86/events/intel/ds.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
arch/x86/events/intel/ds.c +13 -3
@@ -303,6 +303,7 @@ static inline void pebs_set_tlb_lock(u64static u64 __grt_latency_data (struct perf_event *event,u64 status,u8 dse,bool tlb,bool lock,bool blk) { +union perf_mem_data_src src;u64 val; WARN_ON_ONCE(is_hybrid() &&
@@ -318,7 +319,16 @@ static u64 __grt_latency_data(struct perelse val |=P (BLK ,NA ); -return val; + src.val = val; + +if (event->hw.flags & + (PERF_X86_EVENT_PEBS_LDLAT |PERF_X86_EVENT_PEBS_LD_HSW )) + src.mem_op =P (OP ,LOAD ); +if (event->hw.flags & + (PERF_X86_EVENT_PEBS_STLAT |PERF_X86_EVENT_PEBS_ST_HSW )) + src.mem_op =P (OP ,STORE ); + +return src.val; }u64 grt_latency_data (struct perf_event *event,u64 status)
@@ -985,8 +995,8 @@ struct event_constraint intel_glm_pebs_estruct event_constraint intel_grt_pebs_event_constraints[] = {/* Allow all events as PEBS with no flags */ -INTEL_HYBRID_LAT_CONSTRAINT (0x5d0 ,0x3 ), -INTEL_HYBRID_LAT_CONSTRAINT (0x6d0 ,0x3f ), +INTEL_HYBRID_LDLAT_CONSTRAINT (0x5d0 ,0x3 ), +INTEL_HYBRID_STLAT_CONSTRAINT (0x6d0 ,0x3f ),EVENT_CONSTRAINT_END };
Greg Kroah-Hartman
maintainerPATCH 852/877 RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiakai Xu <[email protected]>
[ Upstream commit aeb1d17d1af5924f7357d7204a293bd8fc06ea13 ]
Add a null pointer check for imsic_state before dereferencing it in kvm_riscv_aia_imsic_rw_attr(). While the function checks that the vcpu exists, it doesn't verify that the vcpu's imsic_state has been initialized, leading to a null pointer dereference when accessed.
The crash manifests as:
Unable to handle kernel paging request at virtual address dfffffff00000006 ... kvm_riscv_aia_imsic_rw_attr+0x2d8/0x854 arch/riscv/kvm/aia_imsic.c:958 aia_set_attr+0x2ee/0x1726 arch/riscv/kvm/aia_device.c:354 kvm_device_ioctl_attr virt/kvm/kvm_main.c:4744 [inline] kvm_device_ioctl+0x296/0x374 virt/kvm/kvm_main.c:4761 vfs_ioctl fs/ioctl.c:51 [inline] ...
The fix adds a check to return -ENODEV if imsic_state is NULL and moves isel assignment after imsic_state NULL check.
Stable-dep-of: 8ae12ccaec6e ("RISC-V: KVM: Serialize IMSIC attributes with vCPU migration")
--- arch/riscv/kvm/aia_imsic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/riscv/kvm/aia_imsic.c +3 -1
@@ -895,8 +895,10 @@ int kvm_riscv_aia_imsic_rw_attr(struct kif (!vcpu)return -ENODEV ; - isel =KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL (type); imsic = vcpu->arch.aia_context.imsic_state; +if (!imsic) +return -ENODEV ; + isel =KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL (type);read_lock_irqsave (&imsic->vsfile_lock, flags);
Greg Kroah-Hartman
maintainerPATCH 853/877 RISC-V: KVM: Serialize IMSIC attributes with vCPU migration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xie Bo <[email protected]>
[ Upstream commit 8ae12ccaec6ec74945d8c1ef39f2c1b8df779abc ]
KVM device ioctls are not serialized against KVM_RUN. As a result, kvm_riscv_aia_imsic_rw_attr() can snapshot the physical CPU and HGEI of an IMSIC VS-file before a concurrent vCPU migration releases it.
The HGEI can then be allocated to another vCPU before imsic_vsfile_rw() uses the stale tuple. A GET or SET attribute may consequently access the new owner's interrupt file.
Serialize the entire IMSIC attribute operation with the target vCPU mutex. This prevents the VS-file from being migrated and recycled until the attribute access completes. Acquire the mutex killably so that the device ioctl remains interruptible while waiting for KVM_RUN to finish.
--- arch/riscv/kvm/aia_imsic.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/riscv/kvm/aia_imsic.c +9 -2
@@ -895,9 +895,14 @@ int kvm_riscv_aia_imsic_rw_attr(struct kif (!vcpu)return -ENODEV ; +if (mutex_lock_killable (&vcpu->mutex)) +return -EINTR ; + imsic = vcpu->arch.aia_context.imsic_state; -if (!imsic) -return -ENODEV ; +if (!imsic) { + rc = -ENODEV ; + goto out_unlock; + } isel =KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL (type);read_lock_irqsave (&imsic->vsfile_lock, flags);
@@ -921,6 +926,8 @@ int kvm_riscv_aia_imsic_rw_attr(struct k rc =imsic_vsfile_rw (vsfile_hgei, vsfile_cpu, imsic->nr_eix, isel, write, val); +out_unlock: +mutex_unlock (&vcpu->mutex);return rc; }
Greg Kroah-Hartman
maintainerPATCH 854/877 rose: fix dev_put() leak in rose_loopback_timer()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit ff91adc54db2b62c7cdf063ff761eceb5adf2215 upstream.
rose_rx_call_request() always consumes or returns the skb but never releases the device reference obtained from rose_dev_get(). When rose_rx_call_request() succeeds (returns non-zero) dev_put() was never called, leaking one reference per loopback CALL_REQUEST.
Move dev_put() outside the conditional so it is called unconditionally after rose_rx_call_request() in all cases.
Also remove the dead check (!rose_loopback_neigh->dev && !rose_loopback_neigh->loopback) that immediately precedes it: the loopback neighbour always has loopback=1 so this condition can never be true.
--- net/rose/rose_loopback.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
net/rose/rose_loopback.c +2 -9
@@ -96,22 +96,15 @@ static void rose_loopback_timer(struct t }if (frametype ==ROSE_CALL_REQUEST ) { -if (!rose_loopback_neigh->dev && - !rose_loopback_neigh->loopback) { -kfree_skb (skb); -continue ; - } - dev =rose_dev_get (dest);if (!dev) {kfree_skb (skb);continue ; } -if (rose_rx_call_request (skb, dev, rose_loopback_neigh, lci_o) ==0 ) { -dev_put (dev); +if (rose_rx_call_request (skb, dev, rose_loopback_neigh, lci_o) ==0 )kfree_skb (skb); - } +dev_put (dev); }else {kfree_skb (skb); }
Greg Kroah-Hartman
maintainerPATCH 855/877 rose: hold loopback neighbour reference across timer callback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit d270a7a5793af84555c40dd1eb80f1d497fdf53c upstream.
rose_loopback_timer() dereferences rose_loopback_neigh throughout its body but holds no reference on it. A concurrent rose_loopback_clear() followed by rose_add_loopback_neigh() could free and reallocate the neighbour while the timer body is running, causing a use-after-free.
Take a reference with rose_neigh_hold() at the start of the callback (bailing out if the pointer is already NULL) and release it with rose_neigh_put() at the single exit point. The neigh cannot be freed while the callback holds a reference.
--- net/rose/rose_loopback.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
net/rose/rose_loopback.c +10 -1
@@ -66,10 +66,15 @@ static void rose_loopback_timer(struct tunsigned int lci_i, lci_o;int count; +if (rose_loopback_neigh) +rose_neigh_hold (rose_loopback_neigh); +else +return ; +for (count =0 ; count <ROSE_LOOPBACK_LIMIT ; count++) { skb =skb_dequeue (&loopback_queue);if (!skb) -return ; + goto out;if (skb->len <ROSE_MIN_LEN ) {kfree_skb (skb);continue ;
@@ -109,6 +114,10 @@ static void rose_loopback_timer(struct tkfree_skb (skb); } } + +out: +rose_neigh_put (rose_loopback_neigh); +if (!skb_queue_empty (&loopback_queue))mod_timer (&loopback_timer, jiffies +1 ); }
Greg Kroah-Hartman
maintainerPATCH 856/877 rose: fix race between loopback timer and module removal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit 47dd6ec1a77d77895afb00aa2e68373a48289108 upstream.
rose_loopback_clear() called timer_delete() which returns immediately without waiting for any running callback to complete. If the timer fired concurrently with module removal, rose_loopback_timer() could re-arm the timer after timer_delete() returned and then access rose_loopback_neigh after it was freed.
Two complementary changes close the race:
1. Add a loopback_stopping atomic flag. rose_loopback_timer() checks it at entry (before acquiring a reference) and again inside the loop; when set it drains the queue and exits without re-arming the timer.
2. Switch rose_loopback_clear() to timer_delete_sync() so it blocks until any in-flight callback has returned before freeing resources.
The smp_mb() between setting the flag and calling timer_delete_sync() ensures the flag is visible to any callback that is about to run.
--- net/rose/rose_loopback.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
net/rose/rose_loopback.c +24 -7
@@ -12,13 +12,15 @@#include <net/rose.h> #include <linux/init.h> -static struct sk_buff_head loopback_queue;#define ROSE_LOOPBACK_LIMIT 1000 -static struct timer_list loopback_timer; +static struct timer_list loopback_timer; +static struct sk_buff_head loopback_queue;static void rose_set_loopback_timer (void );static void rose_loopback_timer (struct timer_list *unused); +static atomic_t loopback_stopping =ATOMIC_INIT (0 ); +void rose_loopback_init (void ) {skb_queue_head_init (&loopback_queue);
@@ -66,6 +68,9 @@ static void rose_loopback_timer(struct tunsigned int lci_i, lci_o;int count; +if (atomic_read (&loopback_stopping)) +return ; +if (rose_loopback_neigh)rose_neigh_hold (rose_loopback_neigh);else
@@ -75,6 +80,13 @@ static void rose_loopback_timer(struct t skb =skb_dequeue (&loopback_queue);if (!skb) goto out; + +if (atomic_read (&loopback_stopping)) { +kfree_skb (skb); +skb_queue_purge (&loopback_queue); + goto out; + } +if (skb->len <ROSE_MIN_LEN ) {kfree_skb (skb);continue ;
@@ -118,7 +130,7 @@ static void rose_loopback_timer(struct t out:rose_neigh_put (rose_loopback_neigh); -if (!skb_queue_empty (&loopback_queue)) +if (!atomic_read (&loopback_stopping) && !skb_queue_empty (&loopback_queue))mod_timer (&loopback_timer, jiffies +1 ); }
@@ -126,10 +138,15 @@ void __exit rose_loopback_clear(void) {struct sk_buff *skb; -del_timer (&loopback_timer); +atomic_set (&loopback_stopping,1 ); +/* Pairs with atomic_read() in rose_loopback_timer(): ensure the +* stopping flag is visible before we cancel, so a concurrent +* callback aborts its loop early rather than re-arming the timer. +*/ +smp_mb (); + +timer_delete_sync (&loopback_timer); -while ((skb =skb_dequeue (&loopback_queue)) !=NULL ) { - skb->sk =NULL ; +while ((skb =skb_dequeue (&loopback_queue)) !=NULL )kfree_skb (skb); - } }
Greg Kroah-Hartman
maintainerPATCH 857/877 rose: clear neighbour pointer after rose_neigh_put() in state machines
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit e8eb0c6faa8849ba7769516c1a8c84d9f612acf6 upstream.
After calling rose_neigh_put() in rose_state1_machine() through rose_state5_machine(), rose->neighbour was left pointing at the potentially freed neighbour structure. A subsequent timer expiry or concurrent teardown path could dereference the stale pointer, causing a use-after-free.
Set rose->neighbour to NULL immediately after each rose_neigh_put() call in the state machine functions.
--- net/rose/rose_in.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/rose/rose_in.c +6 -0
@@ -57,6 +57,7 @@ static int rose_state1_machine(struct sorose_write_internal (sk,ROSE_CLEAR_CONFIRMATION );rose_disconnect (sk,ECONNREFUSED , skb->data[3 ], skb->data[4 ]);rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ;break ;default :
@@ -80,11 +81,13 @@ static int rose_state2_machine(struct sorose_write_internal (sk,ROSE_CLEAR_CONFIRMATION );rose_disconnect (sk,0 , skb->data[3 ], skb->data[4 ]);rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ;break ;case ROSE_CLEAR_CONFIRMATION :rose_disconnect (sk,0 ,-1 ,-1 );rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ;break ;default :
@@ -121,6 +124,7 @@ static int rose_state3_machine(struct sorose_write_internal (sk,ROSE_CLEAR_CONFIRMATION );rose_disconnect (sk,0 , skb->data[3 ], skb->data[4 ]);rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ;break ;case ROSE_RR :
@@ -234,6 +238,7 @@ static int rose_state4_machine(struct sorose_write_internal (sk,ROSE_CLEAR_CONFIRMATION );rose_disconnect (sk,0 , skb->data[3 ], skb->data[4 ]);rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ;break ;default :
@@ -254,6 +259,7 @@ static int rose_state5_machine(struct sorose_write_internal (sk,ROSE_CLEAR_CONFIRMATION );rose_disconnect (sk,0 , skb->data[3 ], skb->data[4 ]);rose_neigh_put (rose_sk (sk)->neighbour); +rose_sk (sk)->neighbour =NULL ; }return 0 ;
Greg Kroah-Hartman
maintainerPATCH 858/877 rose: guard rose_neigh_put() against NULL in timer expiry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit 2b67342c6ff899a0b83359517146a5b7b243af97 upstream.
In rose_timer_expiry(), the ROSE_STATE_2 branch calls rose_neigh_put(rose->neighbour) without first checking whether the pointer is NULL. After commit 5de7665e0a07 ("net: rose: fix timer races against user threads") the timer is re-armed when the socket is owned by a user thread; between the re-arm and the next firing, a device-down event or concurrent teardown via rose_kill_by_device() can set rose->neighbour to NULL, leading to a NULL-pointer dereference inside rose_neigh_put().
Add a NULL check before the put and clear the pointer afterwards.
--- net/rose/rose_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/rose/rose_timer.c +4 -1
@@ -180,7 +180,10 @@ static void rose_timer_expiry(struct timbreak ;case ROSE_STATE_2 :/* T3 */ -rose_neigh_put (rose->neighbour); +if (rose->neighbour) { +rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ; + }rose_disconnect (sk,ETIMEDOUT ,-1 ,-1 );break ;
Greg Kroah-Hartman
maintainerPATCH 859/877 rose: fix netdev double-hold in rose_rx_call_request()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit c675277c3ba0d2310e0825577d58308c39931e14 upstream.
rose_rx_call_request() used netdev_tracker_alloc() after assigning make_rose->device, intending to take ownership of the reference passed by the caller. But every caller -- rose_route_frame() and rose_loopback_timer() -- already calls dev_put() for its own hold after the function returns, so the socket ended up with a tracker entry pointing at a reference that had already been released.
The result was spurious refcount_t warnings ("saturated", "decrement hit 0") on every incoming CALL_REQUEST, leading to refcount corruption and eventual silent freeze.
Replace netdev_tracker_alloc() with netdev_hold() so that rose_rx_call_request() acquires its own independent reference. Each caller retains its own hold from rose_dev_get() and releases it via dev_put() as before; socket cleanup releases the socket's separate hold via netdev_put().
--- net/rose/af_rose.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/rose/af_rose.c +5 -3
@@ -1078,9 +1078,11 @@ int rose_rx_call_request(struct sk_buff make_rose->source_digis[n] = facilities.source_digis[n]; make_rose->neighbour = neigh; make_rose->device = dev; -/* Caller got a reference for us. */ -netdev_tracker_alloc (make_rose->device, &make_rose->dev_tracker, -GFP_ATOMIC ); +/* Take an independent reference for this socket; callers keep their +* own reference (from rose_dev_get / dev_hold) and will release it +* themselves via dev_put(). +*/ +netdev_hold (make_rose->device, &make_rose->dev_tracker,GFP_ATOMIC ); make_rose->facilities = facilities;rose_neigh_hold (make_rose->neighbour);
Greg Kroah-Hartman
maintainerPATCH 860/877 rose: fix notifier unregistered too early in rose_exit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit f71a8a1edc14dba746edde38adddd654ba202b4d upstream.
rose_exit() called unregister_netdevice_notifier() before the loop that calls unregister_netdev() on each ROSE virtual device. As a result, the NETDEV_DOWN event fired by unregister_netdev() was never delivered to rose_device_event(), so rose_kill_by_device() never ran.
Every socket whose rose->device pointed at a ROSE device therefore kept its netdev_tracker entry live until free_netdev() destroyed the ref_tracker_dir, at which point the kernel reported all of them as leaked references (165 entries in a typical FPAC setup). Worse, those sockets retained stale device pointers and live timers that could fire into freed module text after module unload, causing a silent system freeze with no kernel panic logged.
Fix by moving unregister_netdevice_notifier() to after the device- unregistration loop. unregister_netdev() then delivers NETDEV_DOWN while the notifier is still registered, rose_kill_by_device() runs for each device, releases all netdev references held by open sockets, and calls rose_disconnect() which stops the per-socket timers.
--- net/rose/af_rose.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
net/rose/af_rose.c +11 -2
@@ -1669,19 +1669,28 @@ static void __exit rose_exit(void)#ifdef CONFIG_SYSCTL rose_unregister_sysctl ();#endif -unregister_netdevice_notifier (&rose_dev_notifier); -sock_unregister (PF_ROSE );for (i =0 ; i < rose_ndevs; i++) {struct net_device *dev = dev_rose[i];if (dev) { +/* unregister_netdev() fires NETDEV_DOWN, which -- while the +* notifier is still registered below -- invokes +* rose_kill_by_device(dev). That releases every socket's +* netdev reference and disconnects all active circuits. +* Unregistering the notifier before this loop was the +* original bug: NETDEV_DOWN was never delivered, leaving +* 165 netdev_tracker entries leaked and stale timers live. +*/ unregister_netdev (dev);free_netdev (dev); } } +/* Now safe to remove the notifier -- all ROSE devices are gone. */ +unregister_netdevice_notifier (&rose_dev_notifier); +kfree (dev_rose);proto_unregister (&rose_proto); }
Greg Kroah-Hartman
maintainerPATCH 861/877 rose: set SOCK_DESTROY in rose_kill_by_device() for prompt cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit 741a4863ad570889c75f7a8e404567d8f3e46335 upstream.
When rose_kill_by_device() is called (via NETDEV_DOWN on module exit or interface removal), it calls rose_disconnect() which transitions sockets to ROSE_STATE_0 and sets SOCK_DEAD. However, rose_heartbeat_expiry() only calls rose_destroy_socket() at ROSE_STATE_0 if SOCK_DESTROY is set -- the SOCK_DEAD path is reserved for TCP_LISTEN sockets. Without SOCK_DESTROY, orphaned sockets in ROSE_STATE_2 (clearing) loop indefinitely in the heartbeat without ever being freed, keeping the module use-count elevated and blocking modprobe -r rose until the T1 timer (up to 200 s) expires.
Set SOCK_DESTROY immediately after rose_disconnect() so the heartbeat destroys the socket at its next tick (within 5 s), allowing clean module unload.
--- net/rose/af_rose.c | 5 +++++ 1 file changed, 5 insertions(+)
net/rose/af_rose.c +5 -0
@@ -211,6 +211,11 @@ start:spin_lock_bh (&rose_list_lock);if (rose->device == dev) {rose_disconnect (sk,ENETUNREACH ,ROSE_OUT_OF_ORDER ,0 ); +/* Mark for destruction so rose_heartbeat_expiry() +* cleans up the socket at its next tick rather than +* looping forever in ROSE_STATE_0 with no owner. +*/ +sock_set_flag (sk,SOCK_DESTROY );if (rose->neighbour)rose_neigh_put (rose->neighbour);netdev_put (rose->device, &rose->dev_tracker);
Greg Kroah-Hartman
maintainerPATCH 862/877 rose: disconnect orphaned STATE_2 sockets when device is gone
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit d4f4cf9f09a3f5fafa8f09110a7c1b5d10f2f261 upstream.
When ax25stop brings down ROSE interfaces, sockets in ROSE_STATE_2 (awaiting CLEAR CONFIRM) whose device pointer is already NULL are not reached by rose_kill_by_device() and wait for T3 (up to 180s) before self-cleaning via rose_timer_expiry(). This keeps the rose module usecount at 1, blocking rmmod for the full T3 duration.
In rose_heartbeat_expiry(), detect ROSE_STATE_2 sockets with no device, cancel T3, release the neighbour reference, and call rose_disconnect()
+ sock_set_flag(SOCK_DESTROY). The next heartbeat tick (<=5s) then destroys the socket via the existing ROSE_STATE_0/SOCK_DESTROY path, allowing clean module unload within 10s instead of up to 180s.
--- net/rose/rose_timer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/rose/rose_timer.c +14 -0
@@ -139,6 +139,20 @@ static void rose_heartbeat_expiry(struct }break ; +case ROSE_STATE_2 : +/* Device gone before CLEAR CONFIRM arrived: stop waiting for T3 +* and disconnect now instead of blocking rmmod for up to 180s. */ +if (!rose->device) { +rose_stop_timer (sk); +if (rose->neighbour) { +rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ; + } +rose_disconnect (sk,ENETDOWN ,-1 ,-1 ); +sock_set_flag (sk,SOCK_DESTROY ); + } +break ; +case ROSE_STATE_3 :/* * Check for the state of the receive buffer.
Greg Kroah-Hartman
maintainerPATCH 863/877 rose: fix netdev double-hold in rose_make_new()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit b9fb21ceb4f0d043767a1eba60786ec84809033b upstream.
rose_make_new() copies orose->device from the listener socket and calls netdev_hold(), storing the tracker in rose->dev_tracker. The only caller, rose_rx_call_request(), then overwrites both make_rose->device and make_rose->dev_tracker with a fresh netdev_hold() for the actual incoming-call device.
This orphans the tracker allocated by rose_make_new(): it remains in the device's refcount_tracker list but no pointer exists to free it via netdev_put(). The result is one spurious outstanding reference per accepted CALL_REQUEST, visible at rmmod time as:
ref_tracker: netdev@X has 2/2 users at
rose_rx_call_request+0xba3/0x1d50 [rose]
rose_loopback_timer+0x3eb/0x670 [rose]The second entry is the orphaned tracker from rose_make_new(); the first is the correctly-managed socket reference from rose_rx_call_request().
Fix: initialise rose->device to NULL in rose_make_new() and let rose_rx_call_request() -- the sole caller -- assign the correct device and take the sole netdev_hold() as it already does.
--- net/rose/af_rose.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/rose/af_rose.c +1 -3
@@ -631,9 +631,7 @@ static struct sock *rose_make_new(struct rose->hb = orose->hb; rose->idle = orose->idle; rose->defer = orose->defer; - rose->device = orose->device; -if (rose->device) -netdev_hold (rose->device, &rose->dev_tracker,GFP_ATOMIC ); + rose->device =NULL ;/* rose_rx_call_request() sets this */ rose->qbitincl = orose->qbitincl;return sk;
Greg Kroah-Hartman
maintainerPATCH 864/877 rose: release netdev ref and destroy orphaned incoming sockets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit df12be096302d2c947388acc25764456c7f18cc1 upstream.
Two related cleanup gaps left the module unremovable after a loopback session:
1. rose_destroy_socket() did not release the device reference. When an unaccepted incoming socket (created by rose_rx_call_request()) is destroyed via rose_heartbeat_expiry(), it is removed from rose_list before rose_kill_by_device() can find it, so the netdev_hold() taken in rose_rx_call_request() was never matched by netdev_put(). Add the release at the top of rose_destroy_socket() guarded by a NULL check so that rose_release() and rose_kill_by_device(), which already call netdev_put() and set device = NULL, are not affected.
2. rose_heartbeat_expiry() STATE_0 cleanup required TCP_LISTEN in addition to SOCK_DEAD. Unaccepted incoming sockets are TCP_ESTABLISHED, so the condition was never true and those sockets lingered forever, holding the module use count above zero and blocking rmmod. Drop the TCP_LISTEN restriction: any STATE_0 + SOCK_DEAD socket is orphaned and should be destroyed.
Together with the earlier rose_make_new() double-hold fix these three patches allow clean rmmod after loopback sessions.
--- net/rose/af_rose.c | 9 +++++++++ net/rose/rose_timer.c | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
net/rose/af_rose.c +9 -0
@@ -363,6 +363,7 @@ static void rose_destroy_timer(struct ti*/ void rose_destroy_socket (struct sock *sk) { +struct rose_sock *rose =rose_sk (sk);struct sk_buff *skb;rose_remove_socket (sk);
@@ -370,6 +371,14 @@ void rose_destroy_socket(struct sock *skrose_stop_idletimer (sk);rose_stop_timer (sk); +/* Drop any device reference not already released by rose_kill_by_device() +* or rose_release() -- e.g. incoming sockets that were never accepted. +*/ +if (rose->device) { +netdev_put (rose->device, &rose->dev_tracker); + rose->device =NULL ; + } +rose_clear_queues (sk);/* Flush the queues */ while ((skb =skb_dequeue (&sk->sk_receive_queue)) !=NULL ) {
net/rose/rose_timer.c +5 -4
@@ -128,10 +128,11 @@ static void rose_heartbeat_expiry(struct }switch (rose->state) {case ROSE_STATE_0 : -/* Magic here: If we listen() and a new link dies before it -is accepted() it isn't 'dead' so doesn't get removed. */ -if (sock_flag (sk,SOCK_DESTROY ) || - (sk->sk_state ==TCP_LISTEN &&sock_flag (sk,SOCK_DEAD ))) { +/* Destroy any orphaned STATE_0 socket: either explicitly +* flagged SOCK_DESTROY, or SOCK_DEAD (covers both unaccepted +* incoming connections and listening sockets whose link died). +*/ +if (sock_flag (sk,SOCK_DESTROY ) ||sock_flag (sk,SOCK_DEAD )) {bh_unlock_sock (sk);rose_destroy_socket (sk);sock_put (sk);
Re: [PATCH 6.12 864/877] rose: release netdev ref and destroy orphaned incoming sockets
Hi Greg,
Thanks a lot for queuing the ROSE series for 6.12.y and the four extra fixes for 6.18.y.
One heads-up on this particular patch (commit df12be096302), before the 6.12.y release goes out: since it was written I have found a regression in it, and the fix is not merged yet.
The problem: with this patch, rose_heartbeat_expiry() reaps an incoming socket that was cleared by the caller before accept(). But the skb of that call is still on the listening socket's receive queue, with skb->sk pointing at the socket that has just been freed (no reference is held for the queue). Then:
- closing the listening socket makes rose_destroy_socket() walk the queue and touch the freed socket, or
- accept() can hand the freed socket to user space.
I hit it on 26 September on one of my live nodes, on a 6.12.94 KASAN kernel carrying this series, while stopping the FPAC daemons:
BUG: KASAN: slab-use-after-free in rose_destroy_socket+0x24a/0x570 [rose] Write of size 8 ... by task fpacwpd rose_destroy_socket rose_release Allocated by task 0: ... rose_rx_call_request <- rose_loopback_timer Freed by task ...: ... sk_free <- rose_heartbeat_expiry
refcount_t: addition on 0; use-after-free.
followed a few seconds later by a page fault in the re-armed heartbeat and a panic. It needs an incoming call dropped before accept() and then the listener being closed (or accepting), so it is not frequent, but it is a real use-after-free.
The fix is "rose: hold a reference on incoming sockets queued for accept()", with
incoming sockets")
It is pull request #25 in linux-netdev/mod-orphan, waiting for review, so it has no upstream commit id yet. It has been running on all seven of my nodes since 26 September (6.1, 6.12, 6.18 and 7.0 based kernels) without any recurrence.
So, as things stand, 6.18.y already carries the regression (this patch was part of the first fifteen-patch series) and 6.12.y is about to get it. I do not know which you prefer:
- keep 864 in this 6.12.y round and take the fix as soon as it is merged, for both 6.18.y and 6.12.y; or
- hold 864 back until the fix is available. Note that 868/877 ("rose:
don't free fd-owned sockets when reaping in the heartbeat") changes the same reaping code, so dropping 864 alone may not be straightforward.
Either way I will send you the backport of the fix for 6.18.y and 6.12.y, tested with "git am" on both, as soon as it has a commit id. Sorry for not flagging this earlier.
Jakub, I put you in Cc only so that you know why I would be grateful if #25 could be looked at before the rest of the pending ROSE/NetRom pull requests.
Thanks,
Bernard Pidoux, F6BVP
Quoted 83 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit
df12be096302d2c947388acc25764456c7f18cc1upstream.Two related cleanup gaps left the module unremovable after a loopback session:
1.
rose_destroy_socket()did not release the device reference. When an unaccepted incoming socket (created byrose_rx_call_request()) is destroyed viarose_heartbeat_expiry(), it is removed fromrose_listbeforerose_kill_by_device()can find it, so thenetdev_hold()taken inrose_rx_call_request()was never matched bynetdev_put(). Add the release at the top ofrose_destroy_socket()guarded by a NULL check so thatrose_release()androse_kill_by_device(), which already callnetdev_put()and set device = NULL, are not affected.2.
rose_heartbeat_expiry()STATE_0cleanup requiredTCP_LISTENin addition toSOCK_DEAD. Unaccepted incoming sockets areTCP_ESTABLISHED, so the condition was never true and those sockets lingered forever, holding the module use count above zero and blocking rmmod. Drop theTCP_LISTENrestriction: anySTATE_0+SOCK_DEADsocket is orphaned and should be destroyed.Together with the earlier
rose_make_new()double-hold fix these three patches allow clean rmmod after loopback sessions.Signed-off-by Bernard Pidoux <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/rose/af_rose.c | 9 +++++++++ net/rose/rose_timer.c | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-)net/rose/af_rose.c +9
-0@@ -363,6 +363,7 @@ static void rose_destroy_timer(struct ti*/ void rose_destroy_socket (struct sock *sk) { +struct rose_sock *rose =rose_sk (sk);struct sk_buff *skb;rose_remove_socket (sk);@@ -370,6 +371,14 @@ void rose_destroy_socket(struct sock *skrose_stop_idletimer (sk);rose_stop_timer (sk); +/* Drop any device reference not already released by rose_kill_by_device() +* or rose_release() -- e.g. incoming sockets that were never accepted. +*/ +if (rose->device) { +netdev_put (rose->device, &rose->dev_tracker); + rose->device =NULL ; + } +rose_clear_queues (sk);/* Flush the queues */ while ((skb =skb_dequeue (&sk->sk_receive_queue)) !=NULL ) {net/rose/rose_timer.c +5
-4@@ -128,10 +128,11 @@ static void rose_heartbeat_expiry(struct }switch (rose->state) {case ROSE_STATE_0 : -/* Magic here: If we listen() and a new link dies before it -is accepted() it isn't 'dead' so doesn't get removed. */ -if (sock_flag (sk,SOCK_DESTROY ) || - (sk->sk_state ==TCP_LISTEN &&sock_flag (sk,SOCK_DEAD ))) { +/* Destroy any orphaned STATE_0 socket: either explicitly +* flagged SOCK_DESTROY, or SOCK_DEAD (covers both unaccepted +* incoming connections and listening sockets whose link died). +*/ +if (sock_flag (sk,SOCK_DESTROY ) ||sock_flag (sk,SOCK_DEAD )) {bh_unlock_sock (sk);rose_destroy_socket (sk);sock_put (sk);
Sasha Levin
maintainerRe: [PATCH 6.12 864/877] rose: release netdev ref and destroy orphaned incoming sockets
Quoted 4 lines · Bernard Pidoux
- hold 864 back until the fix is available. Note that 868/877 ("rose:
don't free fd-owned sockets when reaping in the heartbeat") changes the same reaping code, so dropping 864 alone may not be straightforward.
Dropped with pre-reqs, thanks!
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 865/877 rose: drop CALL_REQUEST in loopback timer when device is not running
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit cf5567a2652e44866eae8987dff4c1ea507680df upstream.
When ax25stop brings down rose0 while the loopback timer has pending CALL_REQUEST frames, rose_loopback_timer() calls rose_dev_get() and finds the device still registered (unregister_netdevice waits for refs to drop), then calls rose_rx_call_request() which takes a netdev_hold() for the new socket.
But NETDEV_DOWN fires only once: rose_kill_by_device() already ran before this timer tick, so the new socket is never cleaned up. The stuck reference prevents unregister_netdevice from completing, and the orphan socket's timers eventually fire on freed memory (KASAN slab-use-after-free in __run_timers).
The kernel clears IFF_UP via dev_close() before sending NETDEV_DOWN, so checking netif_running() after rose_dev_get() is sufficient: if the device is no longer running, the CALL_REQUEST is silently dropped and no socket is created. This closes the race without touching the module-exit path (which already stops the timer via loopback_stopping).
Tested: unregister_netdevice completes immediately after ax25stop with active loopback connections; no ref_tracker warnings, no KASAN.
--- net/rose/rose_loopback.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/rose/rose_loopback.c +10 -0
@@ -118,6 +118,16 @@ static void rose_loopback_timer(struct tkfree_skb (skb);continue ; } +/* rose_kill_by_device() runs on NETDEV_DOWN (IFF_UP cleared) +* before the device is unregistered. If we create a new +* socket here after that cleanup, the ref never gets released +* because NETDEV_DOWN fires only once. Drop the call instead. +*/ +if (!netif_running (dev)) { +dev_put (dev); +kfree_skb (skb); +continue ; + }if (rose_rx_call_request (skb, dev, rose_loopback_neigh, lci_o) ==0 )kfree_skb (skb);
Greg Kroah-Hartman
maintainerPATCH 866/877 rose: cancel neighbour timers in rose_neigh_put() before freeing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit 9b222cb1d23ff210975e9df5ebab7b011acb6fad upstream.
rose_neigh_put() kfree()s the neighbour but never cancels its ftimer and t0timer. Until now every caller that dropped the final reference first called rose_remove_neigh(), which deletes those timers. The socket heartbeat reaping path drops the last reference directly, so a neighbour could be freed with t0timer still armed -- it re-arms itself in rose_t0timer_expiry() -- leading to a use-after-free write in enqueue_timer().
Cancel both timers with timer_delete_sync() (the synchronous variant, to wait out a concurrently running, self-rearming handler) in the refcount-zero branch of rose_neigh_put().
--- include/net/rose.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/net/rose.h +12 -0
@@ -160,6 +160,18 @@ static inline void rose_neigh_hold(strucstatic inline void rose_neigh_put (struct rose_neigh *rose_neigh) {if (refcount_dec_and_test (&rose_neigh->use)) { +/* We are dropping the last reference, so we are about to free the +* neighbour. Its timers may still be armed -- t0timer in particular +* re-arms itself in rose_t0timer_expiry(). rose_remove_neigh() +* cancels them before its own put, but callers that drop the final +* reference without first calling rose_remove_neigh() (the socket +* heartbeat reaping path) would otherwise kfree() a neighbour with a +* live timer -> use-after-free. timer_delete_sync() (not the async +* variant) is required: it waits out a concurrently running handler +* and loops until the self-rearming timer stays stopped. +*/ +timer_delete_sync (&rose_neigh->ftimer); +timer_delete_sync (&rose_neigh->t0timer);if (rose_neigh->ax25)ax25_cb_put (rose_neigh->ax25);kfree (rose_neigh->digipeat);
Greg Kroah-Hartman
maintainerPATCH 867/877 rose: clear neighbour pointer in rose_kill_by_device()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit 606e42d195b467480d4d405f8814c48d1651a76a upstream.
rose_kill_by_device() drops the neighbour reference but leaves rose->neighbour pointing at it, unlike every other rose_neigh_put() site (see "rose: clear neighbour pointer after rose_neigh_put() in state machines"). The heartbeat STATE_0 reaping path then puts the same neighbour a second time, causing a rose_neigh refcount underflow and a use-after-free.
Set rose->neighbour = NULL after the put, restoring the invariant.
--- net/rose/af_rose.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/rose/af_rose.c +9 -1
@@ -216,8 +216,16 @@ start:* looping forever in ROSE_STATE_0 with no owner. */ sock_set_flag (sk,SOCK_DESTROY ); -if (rose->neighbour) +if (rose->neighbour) {rose_neigh_put (rose->neighbour); +/* Clear the pointer after dropping the reference, as +* every other rose_neigh_put() site does. Otherwise +* rose_heartbeat_expiry() (STATE_0 reaping) sees a stale +* rose->neighbour and puts it a second time -> rose_neigh +* refcount underflow / use-after-free. +*/ + rose->neighbour =NULL ; + }netdev_put (rose->device, &rose->dev_tracker); rose->device =NULL ; }
Greg Kroah-Hartman
maintainerPATCH 868/877 rose: dont free fd-owned sockets when reaping in the heartbeat
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bernard Pidoux <[email protected]>
commit 56576518920edd7b6c3479477d8d490fe2ebdaaa upstream.
The heartbeat reaps orphaned ROSE sockets after their bound device goes down. A socket still attached to a struct socket (sk->sk_socket != NULL -- e.g. an incoming connection an fpad client has accepted and kept open) is owned by that userspace fd: rose_release() frees it on close(). Freeing it from the heartbeat left the fd dangling, so the eventual close() touched freed memory -- slab-use-after-free in rose_release().
Reap only sockets with sk->sk_socket == NULL (unaccepted incoming connections and post-close orphans). For an fd-owned socket whose device went down, disconnect it and fall through to the switch so close() does the teardown. Also release the neighbour reference held by orphaned incoming sockets before tearing them down.
--- net/rose/rose_timer.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)
net/rose/rose_timer.c +56 -1
@@ -126,13 +126,68 @@ static void rose_heartbeat_expiry(structsk_reset_timer (sk, &sk->sk_timer, jiffies +HZ /20 ); goto out; } + +/* The bound device went down while we still hold a reference on it. +* This catches the narrow race where rose_loopback_timer() created a +* socket in the window after rose_kill_by_device()'s NETDEV_DOWN sweep +* but before rose_insert_socket() -- leaving a STATE_3 socket that no +* other branch reaps. A down device means the link is dead, so tear +* the socket down regardless of state. rose_destroy_socket() releases +* the held netdev reference (rose->device still set). +*/ +if (rose->device && !netif_running (rose->device)) { +if (rose->neighbour) { +rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ; + } +rose_disconnect (sk,ENETDOWN ,-1 ,-1 ); + +/* Only reap the socket if userspace no longer holds it. A socket +* still attached to a struct socket (sk->sk_socket != NULL -- e.g. +* a connection an fpad client has accepted and kept open) is owned +* by that fd: rose_release() will destroy it on close(). Dropping +* the last reference here leaves the open fd dangling, so the +* eventual close() touches freed memory -> slab-use-after-free in +* rose_release(). Unaccepted incoming sockets and post-close +* orphans have sk->sk_socket == NULL and stay safe to reap here. +*/ +if (!sk->sk_socket) { +sock_set_flag (sk,SOCK_DESTROY ); +bh_unlock_sock (sk); +rose_destroy_socket (sk); +sock_put (sk); +return ; + } + +/* Owned by userspace: the link is down and the socket is now +* disconnected (rose_disconnect() moved it to STATE_0). Fall +* through to the switch, which re-arms the heartbeat; the close() +* will tear the socket down. */ + } +switch (rose->state) {case ROSE_STATE_0 :/* Destroy any orphaned STATE_0 socket: either explicitly * flagged SOCK_DESTROY, or SOCK_DEAD (covers both unaccepted * incoming connections and listening sockets whose link died). */ -if (sock_flag (sk,SOCK_DESTROY ) ||sock_flag (sk,SOCK_DEAD )) { +if ((sock_flag (sk,SOCK_DESTROY ) ||sock_flag (sk,SOCK_DEAD )) && + !sk->sk_socket) { +/* Reap only orphaned sockets (sk->sk_socket == NULL). A +* socket still owned by a userspace fd reaches here via the +* STATE_2 device-gone branch, which sets SOCK_DESTROY without +* knowing about the fd; freeing it would race rose_release() +* at close() -> use-after-free. Leave it for close(). +* +* Orphaned incoming sockets (rose_rx_call_request) hold a +* neighbour reference; release it before teardown, as the +* STATE_2 and device-down branches do. rose_destroy_socket() +* does not drop it. +*/ +if (rose->neighbour) { +rose_neigh_put (rose->neighbour); + rose->neighbour =NULL ; + }bh_unlock_sock (sk);rose_destroy_socket (sk);sock_put (sk);
Greg Kroah-Hartman
maintainerPATCH 869/877 drm/amdgpu: fix ring timeout issue in gfx10 sr-iov environment
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lin.Cao <[email protected]>
commit b529093999ff052916b35356dc66eddb83258ead upstream.
commit 26c95e838e63 ("drm/amdgpu: set the VM pointer to NULL in amdgpu_job_prepare") set job->vm as NULL if there is no fence. It will cause emit switch buffer be skippen if job->vm set as NULL.
Check job rather than vm could solve this problem.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -1
@@ -300,7 +300,7 @@ int amdgpu_ib_schedule(struct amdgpu_rinamdgpu_ring_patch_cond_exec (ring, cond_exec); ring->current_ctx = fence_ctx; -if (vm && ring->funcs->emit_switch_buffer) +if (job && ring->funcs->emit_switch_buffer)amdgpu_ring_emit_switch_buffer (ring); if (ring->funcs->emit_wave_limit &&
Greg Kroah-Hartman
maintainerPATCH 870/877 nvme: revert the cross-controller atomic write size validation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
commit 1fc09f2961f5c6d8bb53bc989f17b12fdc6bc93d upstream.
This was originally added by commit 8695f060a029 ("nvme: all namespaces in a subsystem must adhere to a common atomic write size") to check the all controllers in a subsystem report the same atomic write size, but the check wasn't quite correct and caused problems for devices with multiple namespaces that report different LBA sizes. Commit f46d273449ba ("nvme: fix atomic write size validation") tried to fix this, but then caused problems for namespace rediscovery after a format with an LBA size change that changes the AWUPF value.
This drops the validation and essentially reverts those two commits while keeping the cleanup that went in between the two. We'll need to figure out how to properly check for the mouse trap that nvme left us, but for now revert the check to keep devices working for users who couldn't care less about the atomic write feature.
--- drivers/nvme/host/core.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/nvme/host/core.c +0 -9
@@ -3373,15 +3373,6 @@ static int nvme_init_identify(struct nvmif (ret) goto out_free; } - -if (le16_to_cpu (id->awupf) != ctrl->subsys->awupf) { -dev_err_ratelimited (ctrl->device, -"inconsistent AWUPF, controller not added (%u/%u).\n" , -le16_to_cpu (id->awupf), ctrl->subsys->awupf); - ret = -EINVAL ; - goto out_free; - } -memcpy (ctrl->subsys->firmware_rev, id->fr,sizeof (ctrl->subsys->firmware_rev));
Greg Kroah-Hartman
maintainerPATCH 871/877 bootconfig: Fix negative seeks on 32-bit with LFS enabled
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ben Hutchings <[email protected]>
commit 729dc340a4ed1267774fc8518284e976e2210bdc upstream.
Commit 26dda5769509 "tools/bootconfig: Cleanup bootconfig footer size calculations" replaced some expressions of type int with the BOOTCONFIG_FOOTER_SIZE macro, which expands to an expression of type size_t, which is unsigned.
On 32-bit architectures with LFS enabled (i.e. off_t is 64-bit), the seek offset of -BOOTCONFIG_FOOTER_SIZE now turns into a positive value.
Fix this by casting the size to off_t before negating it.
Just in case someone changes BOOTCONFIG_MAGIC_LEN to have type size_t later, do the same thing to the seek offset of -BOOTCONFIG_MAGIC_LEN.
--- tools/bootconfig/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bootconfig/main.c +2 -2
@@ -205,7 +205,7 @@ static int load_xbc_from_initrd(int fd,if (stat.st_size <BOOTCONFIG_FOOTER_SIZE )return 0 ; -if (lseek (fd, -BOOTCONFIG_MAGIC_LEN ,SEEK_END ) <0 ) +if (lseek (fd, -(off_t )BOOTCONFIG_MAGIC_LEN ,SEEK_END ) <0 )return pr_errno ("Failed to lseek for magic" , -errno);if (read (fd, magic,BOOTCONFIG_MAGIC_LEN ) <0 )
@@ -215,7 +215,7 @@ static int load_xbc_from_initrd(int fd,if (memcmp (magic,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN ) !=0 )return 0 ; -if (lseek (fd, -BOOTCONFIG_FOOTER_SIZE ,SEEK_END ) <0 ) +if (lseek (fd, -(off_t )BOOTCONFIG_FOOTER_SIZE ,SEEK_END ) <0 )return pr_errno ("Failed to lseek for size" , -errno);if (read (fd, &size,sizeof (uint32_t )) <0 )
Greg Kroah-Hartman
maintainerPATCH 872/877 tracing: Move d_max_latency out of CONFIG_FSNOTIFY protection
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit b4bade506b18eb2e5e34ac84f915d7ee6156d4e2 upstream.
The tracing_max_latency shouldn't be limited if CONFIG_FSNOTIFY is defined or not and it was moved out of that protection to be always available with CONFIG_TRACER_MAX_TRACE. All was moved out except the dentry descriptor for it (d_max_latency) and it failed to build on some configs.
Move that out of the CONFIG_FSNOTIFY protection too.
--- kernel/trace/trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.h +1 -1
@@ -341,8 +341,8 @@ struct trace_array {spinlock_t snapshot_trigger_lock;unsigned int snapshot;unsigned long max_latency; -#ifdef CONFIG_FSNOTIFY struct dentry *d_max_latency; +#ifdef CONFIG_FSNOTIFY struct work_struct fsnotify_work;struct irq_work fsnotify_irqwork;#endif
Greg Kroah-Hartman
maintainerPATCH 873/877 mtd: rawnand: pl353: Fix debug prints
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal (DAVE) <[email protected]>
commit 2b7baaddf1bc3e39206a0354449fdc349945b86b upstream.
They are partially incorrect since "software" engine does not mean hamming, the "none" cae is also falling into this print, and on-die means there is some kind of hardware support; we prefer to use the wording on-host vs. on-die.
Fix all those prints.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/pl35x-nand-controller.c +5 -3
@@ -972,17 +972,19 @@ static int pl35x_nand_attach_chip(structswitch (chip->ecc.engine_type) {case NAND_ECC_ENGINE_TYPE_ON_DIE : -dev_dbg (nfc->dev,"Using on-die ECC\n" ); +dev_dbg (nfc->dev,"Using on-die hardware ECC\n" );/* Keep these legacy BBT descriptors for ON_DIE situations */ chip->bbt_td = &bbt_main_descr; chip->bbt_md = &bbt_mirror_descr; fallthrough;case NAND_ECC_ENGINE_TYPE_NONE : +dev_dbg (nfc->dev,"Using no ECC engine\n" ); +break ;case NAND_ECC_ENGINE_TYPE_SOFT : -dev_dbg (nfc->dev,"Using software ECC (Hamming 1-bit/512B)\n" ); +dev_dbg (nfc->dev,"Using software ECC\n" );break ;case NAND_ECC_ENGINE_TYPE_ON_HOST : -dev_dbg (nfc->dev,"Using hardware ECC\n" ); +dev_dbg (nfc->dev,"Using on-host hardware ECC\n" ); ret =pl35x_nand_init_hw_ecc_controller (nfc, chip);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 874/877 platform/x86/amd/pmc: Fix LPS0 and debugfs leaks when STB init fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
commit 76f650a76d6a36a4bee79d94db90a0e935a95477 upstream.
amd_pmc_probe() registers the LPS0 s2idle handler with acpi_register_lps0_dev() and creates the driver's debugfs directory before calling amd_stb_s2d_init(), which is the last step in probe that can fail.
When amd_stb_s2d_init() fails (for example the S2D telemetry region cannot be ioremapped on a long-running system, or the SMU rejects the S2D setup) the error path only calls pci_dev_put() and returns. This leaves amd_pmc_s2idle_dev_ops on the global lps0_s2idle_devops_head list and leaks the debugfs directory, while the devm-managed resources backing the handler are torn down.
Reloading the module then walks the corrupted list in acpi_register_lps0_dev() and hits:
list_add corruption. next->prev should be prev, but was NULL. kernel BUG at lib/list_debug.c:29!
acpi_register_lps0_dev+0x44/0x80 amd_pmc_probe+0x224/0x380 [amd_pmc] platform_probe+0x67/0x90
Even without a reload, the stale registration means the next s2idle transition calls into torn-down driver state.
Unwind the debugfs directory and the LPS0 registration on the amd_stb_s2d_init() error path. acpi_unregister_lps0_dev() is safe to call unconditionally here: it is guarded on the same conditions as acpi_register_lps0_dev(), which is exactly what amd_pmc_remove() already relies on.
--- drivers/platform/x86/amd/pmc/pmc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/pmc/pmc.c +5 -1
@@ -933,13 +933,17 @@ static int amd_pmc_probe(struct platformamd_pmc_dbgfs_register (dev); err =amd_stb_s2d_init (dev);if (err) - goto err_pci_dev_put; + goto err_dbgfs_unregister;if (IS_ENABLED (CONFIG_AMD_MP2_STB ))amd_mp2_stb_init (dev);pm_report_max_hw_sleep (U64_MAX );return 0 ; +err_dbgfs_unregister: +amd_pmc_dbgfs_unregister (dev); +if (IS_ENABLED (CONFIG_SUSPEND )) +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); err_pci_dev_put:pci_dev_put (rdev);return err;
Greg Kroah-Hartman
maintainerPATCH 875/877 usb: dwc3: gadget: Fix use-after-free in dwc3_gadget_free_endpoints due to race condition
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
commit 9c855832790cd488d87de1885974f4c37cfe7358 upstream.
In dwc3_gadget_init_endpoint, &dep->nostream_work is bound with dwc3_nostream_work, and dwc3_gadget_endpoint_stream_event can queue this delayed work on system_percpu_wq when a DEPEVT_STREAM_NOSTREAM event is received.
If we remove the gadget, dwc3_gadget_free_endpoints makes cleanup and the memory allocated for dep with kzalloc() is released by kfree(dep), while the delayed work mentioned above may still be pending or running. The sequence of operations that may lead to a UAF bug is as follows:
CPU0 CPU1
| dwc3_thread_interrupt
| dwc3_endpoint_interrupt
| dwc3_gadget_endpoint_stream_event
| queue_delayed_work(system_percpu_wq,
| &dep->nostream_work)
dwc3_gadget_free_endpoints |
dwc3_free_trb_pool(dep) |
list_del(&dep->endpoint.ep_list) |
dwc3_debugfs_remove_endpoint_dir(dep) |
kfree(dep) |
// dep is freed |
| dwc3_nostream_work
| // use dep (use-after-free)Fix it by canceling the delayed work before kfree(dep) in dwc3_gadget_free_endpoints.
--- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/dwc3/gadget.c +1 -0
@@ -3450,6 +3450,7 @@ static void dwc3_gadget_free_endpoints(s }dwc3_debugfs_remove_endpoint_dir (dep); +cancel_delayed_work_sync (&dep->nostream_work);kfree (dep); } }
Greg Kroah-Hartman
maintainerPATCH 876/877 bpf: Reject key-less BTF for hash maps
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
commit 0895a0c0734703be5532f3883c42db95615fd98b upstream.
map_check_btf() allows a key-less BTF (btf_key_type_id == 0) only for maps that have a ->map_check_btf callback, and leaves the actual decision to that callback. Hash maps used to have no ->map_check_btf, so a key-less BTF was rejected outright.
That changed when htab and rhtab gained a ->map_check_btf to register a dtor - htab in commit 1df97a7453ee ("bpf: Register dtor for freeing special fields") and rhtab in commit 6905f8601298 ("bpf: Allow special fields in resizable hashtab"). Neither looks at the key, so a key-less hash map now passes map_check_btf() and gets created. Reading it back through bpffs feeds the key type_id 0 into btf_type_seq_show(); btf_type_by_id() returns the void type, kind_ops[BTF_KIND_UNKN] is NULL, and btf_type_show() dereferences it:
RIP: 0010:btf_type_show+0x223/0x2e0 kernel/bpf/btf.c:8232 RSP: 0018:ffffc9000399f868 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000000005 RSI: 0000000000000000 RDI: 0000000000000028 RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000000 R10: ffffc9000399f970 R11: 0000000000000001 R12: ffffffff9b96b140 R13: ffffc9000399f8e0 R14: ffff88803d393c00 R15: 0000000000000003 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000200000000000 CR3: 000000003d213000 CR4: 0000000000352ef0 DR0: 0000000039ae8f55 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Call Trace: <TASK> btf_type_seq_show_flags+0xca/0x120 kernel/bpf/btf.c:8250 htab_map_seq_show_elem+0x12e/0x350 kernel/bpf/hashtab.c:1669 map_seq_show+0x13d/0x1e0 kernel/bpf/inode.c:293 traverse.part.0.constprop.0+0x107/0x650 fs/seq_file.c:112 traverse fs/seq_file.c:99 [inline] seq_read_iter+0x93f/0x1270 fs/seq_file.c:196 seq_read+0x344/0x4d0 fs/seq_file.c:163 vfs_read+0x1e4/0xb40 fs/read_write.c:572 ksys_pread64 fs/read_write.c:764 [inline] __do_sys_pread64 fs/read_write.c:772 [inline] __se_sys_pread64 fs/read_write.c:769 [inline] __x64_sys_pread64+0x1eb/0x250 fs/read_write.c:769 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Reject a key-less BTF in htab_map_check_btf() and rhtab_map_check_btf(), restoring the previous behavior.
--- kernel/bpf/hashtab.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/hashtab.c +3 -0
@@ -546,6 +546,9 @@ static int htab_map_check_btf(const stru { struct bpf_htab *htab = container_of(map, struct bpf_htab, map); +if (btf_type_is_void (key_type)) +return -EINVAL ; +if (htab_is_prealloc (htab))return 0 ;/*
Greg Kroah-Hartman
maintainerPATCH 877/877 mm/hugetlb: keep max_huge_pages when dissolving surplus folios
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longlong Xia <[email protected]>
commit 267bede12d3b108ca29997ce280e927a570ec97f upstream.
dissolve_free_hugetlb_folio() can remove a free folio as surplus when its node has surplus pages. In that case remove_hugetlb_folio() decrements both nr_huge_pages and surplus_huge_pages, leaving the persistent pool size unchanged.
Updating max_huge_pages as if a persistent folio had been removed can therefore corrupt the persistent pool target and underflow it when max_huge_pages is zero. Keep max_huge_pages unchanged for surplus folios, including the vmemmap restoration rollback path.
--- mm/hugetlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/hugetlb.c +4 -2
@@ -2248,7 +2248,8 @@ retry:if (h->surplus_huge_pages_node[folio_nid (folio)]) adjust_surplus = true;remove_hugetlb_folio (h, folio, adjust_surplus); - h->max_huge_pages--; +if (!adjust_surplus) + h->max_huge_pages--;spin_unlock_irq (&hugetlb_lock);/*
@@ -2268,7 +2269,8 @@ retry:if (rc) {spin_lock_irq (&hugetlb_lock);add_hugetlb_folio (h, folio, adjust_surplus); - h->max_huge_pages++; +if (!adjust_surplus) + h->max_huge_pages++; goto out; } }else
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.12.112-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.12.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
Am 30.09.2026 um 17:15 schrieb Greg Kroah-Hartman:
Quoted 4 lines
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Builds, boots and works on my 2-socket Ivy Bridge Xeon E5-2697v2 server. No dmesg oddities or regressions found.
Beste Grüße,
Peter Schneider
Signature · 8 lines
Climb the mountain not to plant your flag, but to embrace the challenge, enjoy the air and behold the view. Climb it so you can see the world, not so the world can see you. -- David McCullough Jr. OpenPGP: 0xA3828BD796CCE11A8CADE8866E3A92C92C3FF244 Download: https://www.peters-netzplatz.de/download/pschneider1968_pub.asc https://keys.mailvelope.com/pks/lookup?op=get&[email protected] https://keys.mailvelope.com/pks/lookup?op=get&[email protected]
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.12.112-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.12.y
and the diffstat can be found below.thanks,
greg k-h
Tested on an amd64 laptop (Lenovo ThinkPad T14 Gen 1). Working well, no regressions observed.
Signature · 1 line
-Barry K. Nathan <[email protected]>
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-6.12.y
Best regards,
Pavel
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.12.112-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.12.y
and the diffstat can be found below.thanks,
greg k-h
Built and booted successfully on RISC-V RV64 (HiFive Unmatched).
Quoted 8 lines · On Wed, 30 Sep 2026 17:15:11 +0200 Greg Kroah-Hartman…
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
Boot-tested under QEMU for Rust x86_64, arm64 and riscv64; built-tested for loongarch64:
Thanks!
Cheers,
Miguel
# Librecast Test Results
044/044 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 6.12.112-rc1-gf4ffa8dc360b #1 SMP PREEMPT_DYNAMIC Thu Oct 1 15:05:55 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.12.112 release. There are 877 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.12.112-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.12.y
and the diffstat can be found below.thanks,
greg k-h
Tested on AMD64 12-core and 4-core systems
and on Intel x86-64 4-core and x86 1-core systems