6.18.57-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 501/621 smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit da6e25842431982d5a53cf00d925b98c690f4467 ]
cifs_posix_to_fattr() ignores the return value of posix_info_parse(). When a malformed POSIX directory entry is encountered (e.g. invalid SID lengths from an untrusted server), posix_info_parse() returns -1 without populating the 'parsed' struct. The uninitialized stack memory in parsed.owner and parsed.group is then passed to sid_to_id(), which processes the garbage bytes and passes them to request_key() to construct a SID string, potentially leaking kernel stack contents to the userspace idmap daemon.
Fix this by checking the return value and skipping the SID-to-id mapping when parsing fails. The remaining fattr fields (timestamps, mode, etc.) are populated directly from the 'info' pointer so they are unaffected.
--- fs/smb/client/readdir.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
fs/smb/client/readdir.c +11 -3
@@ -243,8 +243,9 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, struct cifs_sb_info *cifs_sb) {struct smb2_posix_info_parsed parsed; +int rc; -posix_info_parse (info,NULL , &parsed); + rc =posix_info_parse (info,NULL , &parsed);memset (fattr,0 ,sizeof (*fattr)); fattr->cf_uniqueid =le64_to_cpu (info->Inode);
@@ -281,8 +282,15 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,le32_to_cpu (info->ReparseTag), le32_to_cpu(info->Mode)); -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; +if (rc <0 ) { +cifs_dbg (VFS ,"%s: failed to parse SIDs: %d\n" , + __func__, rc); + }else { +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + } }static void __dir_info_to_fattr (struct cifs_fattr *fattr,const void *info)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 484/621 platform/x86: dell-wmi-base: Fix handling of ultra performance key
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armin Wolf <[email protected]>
[ Upstream commit adfd6846bea13667ff28f8aaf00c32fbd69825ab ]
The commit message of commit 5fbd827eb9c2 ("platform/x86: dell-wmi: Recognise or support new switches") states that the ultra performance key contains additional data
after the type and code fields. The event data passed todell_wmi_process_key() is already parsed, so "buffer" already
starts after those two fields.
Use the correct index for accessing the first data field to avoid a potential buffer overread.
--- drivers/platform/x86/dell/dell-wmi-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/dell/dell-wmi-base.c +1 -1
@@ -454,7 +454,7 @@ static int dell_wmi_process_key(struct wmi_device *wdev, int type, int code, u16 key++; used =1 ; }else if (type ==0x0012 && code ==0x000d && remaining >0 ) { - value = (buffer[2 ] ==2 ); + value = (buffer[0 ] ==2 ); used =1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 502/621 smb: client: honor forceuid/forcegid when mapping SIDs to uid/gid
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 18a72975e9f35aadecc75b031f693f2d1f49308f ]
When the administrator mounts with forceuid or forcegid (uid=/gid= mount options), they expect all files to appear owned by the specified user/group. However, several code paths unconditionally called sid_to_id() to overwrite cf_uid/cf_gid with server-provided values, ignoring the administrator's explicit override:
- smb311_posix_info_to_fattr() (stat via POSIX extensions)
- cifs_posix_to_fattr() (readdir via POSIX extensions)
- parse_sec_desc() (CIFS ACL ownership mapping)
This allowed an untrusted server to dictate local file ownership even when the mount was configured to force specific uid/gid values.
Fix all three call sites to check CIFS_MOUNT_OVERR_UID and CIFS_MOUNT_OVERR_GID before calling sid_to_id(), following the same pattern already used by cifs_unix_basic_to_fattr() for unix extensions.
--- fs/smb/client/cifsacl.c | 28 ++++++++++++++++++---------- fs/smb/client/inode.c | 9 +++++++-- fs/smb/client/readdir.c | 7 +++++-- 3 files changed, 30 insertions(+), 14 deletions(-)
fs/smb/client/cifsacl.c +18 -10
@@ -1314,6 +1314,7 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, {int rc =0 ;struct smb_sid *owner_sid_ptr, *group_sid_ptr; +unsigned int sbflags =cifs_sb_flags (cifs_sb);struct smb_acl *dacl_ptr;/* no need for SACL ptr */ char *end_of_acl = ((char *)pntsd) + acl_len;__u32 dacloffset;
@@ -1331,16 +1332,21 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,le32_to_cpu (pntsd->gsidoffset), le32_to_cpu(pntsd->sacloffset), dacloffset);/* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; + rc =parse_sid (owner_sid_ptr, end_of_acl);if (rc) {cifs_dbg (FYI ,"%s: Error %d parsing Owner SID\n" , __func__, rc);return rc; } - rc =sid_to_id (cifs_sb, owner_sid_ptr, fattr,SIDOWNER ); -if (rc) { -cifs_dbg (FYI ,"%s: Error %d mapping Owner SID to uid\n" , - __func__, rc); -return rc; +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) { + rc =sid_to_id (cifs_sb, owner_sid_ptr, fattr,SIDOWNER ); +if (rc) { +cifs_dbg (FYI ,"%s: Error %d mapping Owner SID to uid\n" , + __func__, rc); +return rc; + } } rc =parse_sid (group_sid_ptr, end_of_acl);
@@ -1349,11 +1355,13 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, __func__, rc);return rc; } - rc =sid_to_id (cifs_sb, group_sid_ptr, fattr,SIDGROUP ); -if (rc) { -cifs_dbg (FYI ,"%s: Error %d mapping Group SID to gid\n" , - __func__, rc); -return rc; +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) { + rc =sid_to_id (cifs_sb, group_sid_ptr, fattr,SIDGROUP ); +if (rc) { +cifs_dbg (FYI ,"%s: Error %d mapping Group SID to gid\n" , + __func__, rc); +return rc; + } }if (dacloffset) {
fs/smb/client/inode.c +7 -2
@@ -849,6 +849,7 @@ static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr,struct smb311_posix_qinfo *info = &data->posix_fi;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb); +unsigned int sbflags =cifs_sb_flags (cifs_sb);memset (fattr,0 ,sizeof (*fattr));
@@ -893,8 +894,12 @@ static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr, fattr->cf_symlink_target = data->symlink_target; data->symlink_target =NULL ; } -sid_to_id (cifs_sb, &data->posix_owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &data->posix_group, fattr,SIDGROUP ); + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &data->posix_owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &data->posix_group, fattr,SIDGROUP );cifs_dbg (FYI ,"POSIX query info: mode 0x%x uniqueid 0x%llx nlink %d\n" , fattr->cf_mode, fattr->cf_uniqueid, fattr->cf_nlink);
fs/smb/client/readdir.c +5 -2
@@ -242,6 +242,7 @@ static void cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, struct cifs_sb_info *cifs_sb) { + unsigned int sbflags = cifs_sb_flags(cifs_sb);struct smb2_posix_info_parsed parsed;int rc;
@@ -288,8 +289,10 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,cifs_dbg (VFS ,"%s: failed to parse SIDs: %d\n" , __func__, rc); }else { -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 503/621 drm/amdgpu: skip the VMID 0 flush for VRAM
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arunpravin Paneer Selvam <[email protected]>
[ Upstream commit 87ceb8cba73d0b3c4025ff42495bccd8164acaed ]
Clear-on-release only runs on VRAM, which amdgpu_ttm_map_buffer() reaches via its direct MC address without programming a GART window, yet the wipe still forces a VMID 0 flush. On GFX11 (e.g. Navi33) that spurious SDMA flush can wedge the engine; only flush when a GART window is actually used.
v2: Let amdgpu_ttm_map_buffer() return whether the VMID 0 flush is needed,
and drive the clear and copy paths from that. (Christian)
v3: Make the vm_needs_flush output parameter mandatory instead of
allowing NULL. (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +17 -8
@@ -175,6 +175,8 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,* @tmz: if we should setup a TMZ enabled mapping * @size: in number of bytes to map, out number of bytes mapped * @addr: resulting address inside the MC address space +* @vm_needs_flush: out, set true if a GART window was programmed (VMID 0 flush +* needed) or false for a direct address * * Setup one of the GART windows to access a specific piece of memory or return * the physical address for local memory.
@@ -183,7 +185,8 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,struct ttm_resource *mem, struct amdgpu_res_cursor *mm_cur, unsigned int window, struct amdgpu_ring *ring, - bool tmz, uint64_t *size, uint64_t *addr) + bool tmz, uint64_t *size, uint64_t *addr, + bool *vm_needs_flush) { struct amdgpu_device *adev = ring->adev;unsigned int offset, num_pages, num_dw, num_bytes;
@@ -204,9 +207,12 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,if (!tmz && mem->start !=AMDGPU_BO_INVALID_OFFSET ) { *addr =amdgpu_ttm_domain_start (adev, mem->mem_type) + mm_cur->start; + *vm_needs_flush = false;return 0 ; } +/* A GART window is programmed below, so its VMID 0 TLB needs a flush */ + *vm_needs_flush = true;/* * If start begins at an offset inside the page, then adjust the size
@@ -316,6 +322,7 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,while (src_mm.remaining) {uint64_t from, to, cur_size, tiling_flags;uint32_t num_type, data_format, max_com, write_compress_disable; +bool src_vm_flush, dst_vm_flush;struct dma_fence *next;/* Never copy more than 256MiB at once to avoid a timeout */
@@ -323,12 +330,12 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,/* Map src to window 0 and dst to window 1. */ r =amdgpu_ttm_map_buffer (src->bo, src->mem, &src_mm, -0 , ring, tmz, &cur_size, &from); +0 , ring, tmz, &cur_size, &from, &src_vm_flush);if (r) goto error; r =amdgpu_ttm_map_buffer (dst->bo, dst->mem, &dst_mm, -1 , ring, tmz, &cur_size, &to); +1 , ring, tmz, &cur_size, &to, &dst_vm_flush);if (r) goto error;
@@ -356,7 +363,7 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, } r =amdgpu_copy_buffer (ring, from, to, cur_size, resv, - &next, false, true, copy_flags); + &next, false, src_vm_flush || dst_vm_flush, copy_flags);if (r) goto error;
@@ -2419,6 +2426,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;struct amdgpu_res_cursor cursor; +bool vm_needs_flush = false;u64 addr;int r =0 ;
@@ -2446,12 +2454,12 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo, size =min (cursor.size,256ULL <<20 ); r =amdgpu_ttm_map_buffer (&bo->tbo, bo->tbo.resource, &cursor, -1 , ring, false, &size, &addr); +1 , ring, false, &size, &addr, &vm_needs_flush);if (r) goto err; r =amdgpu_ttm_fill_mem (ring,0 , addr, size, resv, - &next, true, true, + &next, vm_needs_flush, true,AMDGPU_KERNEL_JOB_ID_TTM_CLEAR_BUFFER );if (r) goto err;
@@ -2478,6 +2486,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;struct dma_fence *fence =NULL ;struct amdgpu_res_cursor dst; +bool vm_needs_flush = false;int r;if (!adev->mman.buffer_funcs_enabled) {
@@ -2497,12 +2506,12 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo, cur_size =min (dst.size,256ULL <<20 ); r =amdgpu_ttm_map_buffer (&bo->tbo, bo->tbo.resource, &dst, -1 , ring, false, &cur_size, &to); +1 , ring, false, &cur_size, &to, &vm_needs_flush);if (r) goto error; r =amdgpu_ttm_fill_mem (ring, src_data, to, cur_size, resv, - &next, true, delayed, k_job_id); + &next, vm_needs_flush, delayed, k_job_id);if (r) goto error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 504/621 tracing: Take trace_array reference when opening a tracer options file
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit ed0aff60f83a9bdc2f6556376ac79c96b3ce7e80 ]
When a tracer option file is opened, it is passed a descriptor that points to an element on the trace_array's topts array. This element has information to find the trace array and other information. It uses this element to take a reference of the trace_array so that the trace_array does not get removed while this file is opened.
Unfortunately, there's a race condition where the element itself could be freed by the removal of the instance the trace_array represents causing a use-after-free as this element that is used to find the trace_array to increment its reference counter is also freed when the instance is removed.
To solve this, add a trace_array_tracer_options_get() helper function that will take the address of the element that is passed to the open function by the inode->i_private pointer and search all the trace_arrays under a lock to find the one that the element's address is in the range of the trace_arrays topts array elements. When a match happens, that trace_array's reference would be increased.
Note, there's a race where if an admin was deleting and creating trace instances at the same time and the memory of the old trace_array's array matched the memory of the new trace_array that it could in theory open the option from the wrong trace array. But we do not care because it would be stupid to perform that kind of action. As long as the only thing that can happen is that the option from the wrong trace array is used and doesn't crash the kernel it will only make the user confused. But if they are doing something stupid like this, they are already confused, so no harm done.
--- kernel/trace/trace.c | 48 +++++++++++++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-)
kernel/trace/trace.c +47 -1
@@ -9279,12 +9279,57 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,return cnt; } +static bool tr_option_match (struct trace_array *tr,void *topt) +{ +for (int i =0 ; i < tr->nr_topts; i++) { +struct trace_options *tr_topts = &tr->topts[i]; + +if (topt >= (void *)&tr_topts->topts[0 ] && + topt < (void *)&tr_topts->topts[tr_topts->nr_topts]) +return true; + } +return false; +} + +/* +* The topt is the address of a trace_array->topts[] element that holds the +* the tracer options descriptor. But since the trace_array reference has not +* been taken yet, it cannot be dereferenced as it could have been freed by +* a rmdir of the instance the trace_array represents. +* +* Search the list of trace_arrays and compare the topt to the address of +* the entire trace_array topts array for each trace_array in the list. +* If one is matched, then take the reference and return it. If not, the +* trace_array no longer exits. +*/ +static int trace_array_tracer_options_get (void *topt) +{ +struct trace_array *tr; +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + +if (tracing_disabled) +return -ENODEV ; + +guard (mutex)(&trace_types_lock); +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (tr_option_match (tr, topt)) { + tr->ref++; +return 0 ; + } + } +return -ENODEV ; +} +static int tracing_open_options (struct inode *inode,struct file *filp) {struct trace_option_dentry *topt = inode->i_private;int ret; - ret =tracing_check_open_get_tr (topt->tr); + ret =trace_array_tracer_options_get (topt);if (ret)return ret;
@@ -9568,6 +9613,7 @@ create_trace_option_files(struct trace_array *tr, struct tracer *tracer) tr->topts = tr_topts; tr->topts[tr->nr_topts].tracer = tracer; tr->topts[tr->nr_topts].topts = topts; + tr->topts[tr->nr_topts].nr_topts = cnt; tr->nr_topts++;for (cnt =0 ; opts[cnt].name; cnt++) {
kernel/trace/trace.h +1 -0
@@ -224,6 +224,7 @@ struct array_buffer {struct trace_options {struct tracer *tracer;struct trace_option_dentry *topts; +int nr_topts; };struct trace_pid_list *trace_pid_list_alloc (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 505/621 vhost: invalidate vring access on IOTLB transitions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit e4f4761879a230aa59e569102a6ab9851847d833 ]
When VIRTIO_F_ACCESS_PLATFORM changes, cached vring pointers and IOTLB metadata are interpreted in a different address space. Keeping them across the transition can leave stale ring mappings in use.
Clearing d->iotlb before taking the VQ locks also lets a worker observe a transient NULL d->iotlb and fall back to d->umem while translating a descriptor.
Add a common vhost_clear_device_iotlb() helper for vhost-net and vhost-vsock. Take all VQ mutexes in index order before dropping the device-wide IOTLB, invalidate each VQ's cached ring access and metadata, clear pending IOTLB messages, and free the old table after the handoff. This serializes the transition with workers and prevents mixed address space mappings.
On the first direct-to-IOTLB transition, invalidate the cached vring addresses. When an existing device IOTLB is replaced, preserve the GIOVA ring addresses and reset only the metadata cache. After clearing ACCESS_PLATFORM, userspace must configure the vring addresses for the new address mode.
vhost_vq_invalidate_access() clears desc, avail, and used together. Treat the VQ as invalidated only when all three are NULL, since a single GIOVA address may legitimately be zero.
Message-ID: <[email protected]>
--- drivers/vhost/net.c | 2 ++ drivers/vhost/vhost.c | 57 ++++++++++++++++++++++++++++++++++++++++++- drivers/vhost/vhost.h | 1 + drivers/vhost/vsock.c | 2 ++ 4 files changed, 61 insertions(+), 1 deletion(-)
drivers/vhost/net.c +2 -0
@@ -1698,6 +1698,8 @@ static int vhost_net_set_features(struct vhost_net *n, const u64 *features)if (virtio_features_test_bit (features,VIRTIO_F_ACCESS_PLATFORM )) {if (vhost_init_device_iotlb (&n->dev)) goto out_unlock; + }else { +vhost_clear_device_iotlb (&n->dev); }for (i =0 ; i <VHOST_NET_VQ_MAX ; ++i) {
drivers/vhost/vhost.c +56 -1
81 lines not on this page · raw message
drivers/vhost/vhost.h +1 -0
@@ -276,6 +276,7 @@ ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to, int noblock);ssize_t vhost_chr_write_iter (struct vhost_dev *dev,struct iov_iter *from); +void vhost_clear_device_iotlb (struct vhost_dev *d);int vhost_init_device_iotlb (struct vhost_dev *d); void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
drivers/vhost/vsock.c +2 -0
@@ -819,6 +819,8 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)if ((features & (1ULL <<VIRTIO_F_ACCESS_PLATFORM ))) {if (vhost_init_device_iotlb (&vsock->dev)) goto err; + }else { +vhost_clear_device_iotlb (&vsock->dev); } vsock->seqpacket_allow = features & (1ULL <<VIRTIO_VSOCK_F_SEQPACKET );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 506/621 vduse: validate virtqueue alignment
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit fa2c25b4add57888acfa89e398389e267bff3dcf ]
vduse_validate_config() only checks the upper bound of vq_align. Invalid values can therefore reach vring_create_virtqueue_map(). The split-ring helpers use align - 1 as a bit mask, so the alignment must be a non-zero power of two. A zero value makes vring_size() drop the descriptor and available-ring part and vring_init() leave the used ring pointer NULL.
The VIRTIO spec requires the used ring to start at an address aligned to at least 4 bytes. Reject values below VRING_USED_ALIGN_SIZE as well as non-power-of-two values before they reach the virtio ring helpers.
Opening a virtio-net device created with vq_align=0 triggered:
BUG: KASAN: null-ptr-deref in virtqueue_kick_prepare_split+0xe3/0x100 Read of size 2 at addr 0000000000000000 by task systemd-network/1062
Call Trace (relevant frames):
dump_stack_lvl
print_report
kasan_report
__asan_load2
virtqueue_kick_prepare_split+0xe3/0x100 virtqueue_kick_prepare+0x40/0x60 try_fill_recv+0x857/0x1250 virtnet_open+0x189/0x460 __dev_open+0x225/0x390 __dev_change_flags+0x368/0x3b0 netif_change_flags+0x56/0xc0 do_setlink.isra.0+0x68c/0x1e30
Validate the value before it reaches the virtio ring helpers.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_user/vduse_dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_user/vduse_dev.c +3 -1
@@ -1837,7 +1837,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config) sizeof(config->reserved)))return false; -if (config->vq_align >PAGE_SIZE ) +if (config->vq_align <VRING_USED_ALIGN_SIZE || + !is_power_of_2 (config->vq_align) || + config->vq_align >PAGE_SIZE )return false;if (config->config_size >PAGE_SIZE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 507/621 virtio_ring: fix stale descriptor flags after a failed packed add
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Graf <[email protected]>
[ Upstream commit 75d276e5bb68778b2916f98a2bc30f142ebadc64 ]
In a packed ring the AVAIL and USED bits sit in the descriptor itself, so writing them makes that descriptor available. Those bit combinations flip meaning on every round of the ring, tracked by a wrap counter, so invalidating or validating a descriptor means inverting both bits.
Commit 1ce9e6055fa0 ("virtio_ring: introduce packed ring support") has virtqueue_add_packed() make every descriptor of a chain available as it maps the chain, and write the head last. The device consumes the ring in order and stops at a head that is not available yet, so it never reaches the rest.
When vring_map_one_sg() fails partway, unmap_release unmaps the segments and restores avail_used_flags, but the descriptors it wrote to in the ring stay marked with AVAIL and USED bits. The head is now the only entry that keeps the device from consuming these stale entries.
For example, the ring would look like this now.
Z - pre-previous command
A - previous command
B - aborted command
C - current command
[A1 DONE] [A2 DONE] <C1 EMPTY> [B2] [B3] [Z1 DONE]
When the driver now attempts to issue the C command, the next add starts at the same head as B. If C spans less descriptors than B, there is no end marker because AVAIL and USED bits were still in place. And that means the device will start interpreting these stale entries (B2/B3) as another command entry, which then blocks the queue.
This effect typically happens in swiotlb configurations under memory pressure, because vring_map_one_sg() can then fail with larger I/O requests which then leads to command abortions.
There are broadly 2 ways to avoid leaving those flags behind:
1) Defer those flags too until the chain is complete.
2) Rewrite those flags for the previous wrap counter.
Implement the second option in both packed add paths. The first option traverses the chain a second time on every successful add. The second option invalidates all added descriptors when any add fails.
With this patch applied, a packed virtqueue keeps completing requests after a failed add.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_ring.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +17 -2
@@ -1459,7 +1459,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,struct scatterlist *sg;unsigned int i, n, c, descs_used, err_idx, len;__le16 head_flags, flags; -u16 head, id, prev, curr, avail_used_flags; +u16 head, id, prev, curr, avail_used_flags, unpub_flags;int err;START_USE (vq);
@@ -1584,15 +1584,30 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, curr = vq->free_head; vq->packed.avail_used_flags = avail_used_flags; + unpub_flags = avail_used_flags ^ (1 <<VRING_PACKED_DESC_F_AVAIL | +1 <<VRING_PACKED_DESC_F_USED );for (n =0 ; n < total_sg; n++) {if (i == err_idx)break ; +/* +* The mapping loop made every descriptor but the head +* available. Stamp the previous wrap counter's AVAIL and USED +* bits on those, so that a later and shorter chain at this head +* does not leave one of them available beyond its own last +* descriptor. Marking them used instead would hand +* is_used_desc_packed() a completion we never made. +*/ +if (i != head) + desc[i].flags =cpu_to_le16 (unpub_flags);vring_unmap_extra_packed (vq, &vq->packed.desc_extra[curr]); curr = vq->packed.desc_extra[curr].next; i++; -if (i >= vq->packed.vring.num) +if (i >= vq->packed.vring.num) { i =0 ; + unpub_flags ^=1 <<VRING_PACKED_DESC_F_AVAIL | +1 <<VRING_PACKED_DESC_F_USED ; + } }END_USE (vq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 508/621 iommu/riscv: Serialize command queue publishing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fangyu Yu <[email protected]>
[ Upstream commit ca58afa40946acd252a50fa4d4a86f15847a3d7d ]
Serialize command queue publishing so software producer state advances only after a command is written and the hardware tail is updated. Wait for hardware consumption outside the queue lock when the command queue is full so other CPUs are not blocked behind a long poll.
--- drivers/iommu/riscv/iommu.c | 100 +++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 42 deletions(-)
drivers/iommu/riscv/iommu.c +58 -42
@@ -381,75 +381,91 @@ static int riscv_iommu_queue_wait(struct riscv_iommu_queue *queue, (int)(cons - index) > 0, 0, timeout_us); } -/* Enqueue an entry and wait to be processed if timeout_us > 0 -* -* Error handling for IOMMU hardware not responding in reasonable time -* will be added as separate patch series along with other RAS features. -* For now, only report hardware failure and continue. -*/ +static int riscv_iommu_queue_wait_for_space (struct riscv_iommu_queue *queue, +unsigned int last) +{ +unsigned int head; +unsigned int tail; +unsigned int hw_head; +unsigned long flags; +int ret; + + ret =riscv_iommu_readl_timeout (queue->iommu,Q_HEAD (queue), hw_head, + !(hw_head & ~queue->mask) && hw_head != last, +0 ,RISCV_IOMMU_QUEUE_TIMEOUT ); +if (ret) +return ret; + +raw_spin_lock_irqsave (&queue->lock, flags); + head =atomic_read (&queue->head); + tail =atomic_read (&queue->tail); +if ((tail - head) >= queue->mask) { + last =Q_ITEM (queue, head); +/* +* Re-read hw_head under the lock so that it is consistent with +* the freshly computed 'last'. Using the pre-lock snapshot +* could produce a stale value that wraps around relative to the +* new 'last', advancing the shadow head past entries that have +* not yet been consumed by the hardware. +*/ + hw_head =riscv_iommu_readl (queue->iommu,Q_HEAD (queue)); +if (!(hw_head & ~queue->mask) && hw_head != last) +atomic_add ((hw_head - last) & queue->mask, &queue->head); + } +raw_spin_unlock_irqrestore (&queue->lock, flags); + +return 0 ; +} + +/* Enqueue an entry and publish it to the hardware queue. */ static unsigned int riscv_iommu_queue_send (struct riscv_iommu_queue *queue,void *entry,size_t entry_size) {unsigned int prod;unsigned int head; -unsigned int tail;unsigned long flags; +int ret; -/* Do not preempt submission flow. */ -local_irq_save (flags); +/* 1. Wait for space availability and reserve the next slot. */ +for (;;) { +raw_spin_lock_irqsave (&queue->lock, flags); -/* 1. Allocate some space in the queue */ - prod =atomic_inc_return (&queue->prod) -1 ; - head =atomic_read (&queue->head); + prod =atomic_read (&queue->tail); + head =atomic_read (&queue->head); -/* 2. Wait for space availability. */ -if ((prod - head) > queue->mask) { -if (readx_poll_timeout (atomic_read, &queue->head, - head, (prod - head) < queue->mask, -0 ,RISCV_IOMMU_QUEUE_TIMEOUT )) - goto err_busy; - }else if ((prod - head) == queue->mask) { -const unsigned int last =Q_ITEM (queue, head); +if ((prod - head) < queue->mask) +break ; + + head =Q_ITEM (queue, head); +raw_spin_unlock_irqrestore (&queue->lock, flags); -if (riscv_iommu_readl_timeout (queue->iommu,Q_HEAD (queue), head, - !(head & ~queue->mask) && head != last, -0 ,RISCV_IOMMU_QUEUE_TIMEOUT )) + ret =riscv_iommu_queue_wait_for_space (queue, head); +if (ret) goto err_busy; -atomic_add ((head - last) & queue->mask, &queue->head); } -/* 3. Store entry in the ring buffer */ +/* 2. Store entry in the ring buffer. */ memcpy (queue->base +Q_ITEM (queue, prod) * entry_size, entry, entry_size); -/* 4. Wait for all previous entries to be ready */ -if (readx_poll_timeout (atomic_read, &queue->tail, tail, prod == tail, -0 ,RISCV_IOMMU_QUEUE_TIMEOUT )) - goto err_busy; - -/* -* 5. Make sure the ring buffer update (whether in normal or I/O memory) is -* completed and visible before signaling the tail doorbell to fetch -* the next command. 'fence ow, ow' -*/ +/* 3. Make sure the entry is visible before updating the queue tail. */ dma_wmb ();riscv_iommu_writel (queue->iommu,Q_TAIL (queue),Q_ITEM (queue, prod +1 ));/* -* 6. Make sure the doorbell write to the device has finished before updating -* the shadow tail index in normal memory. 'fence o, w' +* 4. Make sure the doorbell write to the device has finished before +* updating the shadow tail index in normal memory. 'fence o, w' */ mmiowb (); -atomic_inc (&queue->tail); +atomic_set (&queue->tail, prod +1 ); +atomic_set (&queue->prod, prod +1 ); -/* 7. Complete submission and restore local interrupts */ -local_irq_restore (flags); +raw_spin_unlock_irqrestore (&queue->lock, flags);return prod; err_busy: -local_irq_restore (flags); +/* Report the failure and continue; full RAS recovery is not implemented. */ dev_err_once (queue->iommu->dev,"Hardware error: command enqueue failed\n" ); -return prod; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 509/621 bpf: mark a NULL call argument precise
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 1a3a10b030c96ea88868ccc060a16827c01eaa5a ]
check_func_arg() allows bpf_register_is_null() for nullable arguments w/o marking the underlying scalar register precise. Hence a checkpoint created on such a path would prune against arbitrary scalar value.
check_helper_call() enforces second parameter of the bpf_get_local_storage() to be zero, w/o marking the underlying scalar register precise. Hence a checkpoint created on such a path would prune against arbitrary scalar value.
Grouping these two into one patch, as they share the same fixes tag.
--- kernel/bpf/verifier.c | 9 ++++++++- .../selftests/bpf/progs/verifier_subprog_precision.c | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-)
kernel/bpf/verifier.c +8 -1
@@ -9871,11 +9871,15 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,return err; } -if (register_is_null (reg) &&type_may_be_null (arg_type)) +if (register_is_null (reg) &&type_may_be_null (arg_type)) {/* A NULL register has a SCALAR_VALUE type, so skip * type checking. */ + err =mark_chain_precision (env, regno); +if (err) +return err; goto skip_type_check; + }/* arg_btf_id and arg_size are in a union. */ if (base_type(arg_type) == ARG_PTR_TO_BTF_ID ||
@@ -11811,6 +11815,9 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insnverbose (env,"get_local_storage() doesn't support non-zero flags\n" );return -EINVAL ; } + err =mark_chain_precision (env,BPF_REG_2 ); +if (err) +return err;break ;case BPF_FUNC_for_each_map_elem: err = push_callback_call(env, insn, insn_idx, meta.subprogno,
tools/testing/selftests/bpf/progs/verifier_subprog_precision.c +6 -6
@@ -287,9 +287,9 @@ __msg("17: (b7) r0 = 0") __msg("18: (95) exit") __msg("returning from callee:") __msg("to caller at 9:") -__msg("frame 0: propagating r1,r4") +__msg("frame 0: propagating r1,r3,r4") __msg("mark_precise: frame0: last_idx 9 first_idx 9 subseq_idx -1") -__msg("mark_precise: frame0: regs=r1,r4 stack= before 18: (95) exit") +__msg("mark_precise: frame0: regs=r1,r3,r4 stack= before 18: (95) exit") __msg("from 18 to 9: safe")__naked int callback_result_precise (void ) {
@@ -419,9 +419,9 @@ __msg("to caller at 9:")/* r1, r4 are always precise for bpf_loop(), * r6 was marked before backtracking to callback body. */ -__msg("frame 0: propagating r1,r4,r6") +__msg("frame 0: propagating r1,r3,r4,r6") __msg("mark_precise: frame0: last_idx 9 first_idx 9 subseq_idx -1") -__msg("mark_precise: frame0: regs=r1,r4,r6 stack= before 16: (95) exit") +__msg("mark_precise: frame0: regs=r1,r3,r4,r6 stack= before 16: (95) exit") __msg("mark_precise: frame1: regs= stack= before 15: (b7) r0 = 0") __msg("mark_precise: frame1: regs= stack= before 9: (85) call bpf_loop")__msg ("mark_precise: frame0: parent state regs= stack=:" )
@@ -575,9 +575,9 @@ __msg("to caller at 10:")/* r1, r4 are always precise for bpf_loop(), * fp-8 was marked before backtracking to callback body. */ -__msg("frame 0: propagating r1,r4,fp-8") +__msg("frame 0: propagating r1,r3,r4,fp-8") __msg("mark_precise: frame0: last_idx 10 first_idx 10 subseq_idx -1") -__msg("mark_precise: frame0: regs=r1,r4 stack=-8 before 18: (95) exit") +__msg("mark_precise: frame0: regs=r1,r3,r4 stack=-8 before 18: (95) exit") __msg("mark_precise: frame1: regs= stack= before 17: (b7) r0 = 0") __msg("mark_precise: frame1: regs= stack= before 10: (85) call bpf_loop#181")__msg ("mark_precise: frame0: parent state regs= stack=:" )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 510/621 tracing: Fix subbuf resize races with trace_pipe_raw readers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
[ Upstream commit dae8dda341d2d9034a90d59e8a7d502e1263813f ]
Concurrent subbuffer resizes may crash trace_pipe_raw readers or leak uninitialized memory to userspace due to stale size values.
Modify ring_buffer_alloc_read_page() to handle the resizing of an existing buffer_data_read_page if necessary and add a new ring_buffer_read_page_size(). This new function enables ring-buffer buffer_data_read_page users to not call the racy ring_buffer_subbuf_size_get(). This makes the spare_size member of ftrace_buffer_info redundant.
Finally, handle buffer_data_read_page/reader_page order discrepancy in ring_buffer_read_page(). On a mismatch simply copy manually the data to the buffer_data_read_page.
--- include/linux/ring_buffer.h | 5 +- kernel/trace/ring_buffer.c | 137 ++++++++++++++++++--------- kernel/trace/ring_buffer_benchmark.c | 6 +- kernel/trace/trace.c | 106 +++++++++------------ 4 files changed, 145 insertions(+), 109 deletions(-)
include/linux/ring_buffer.h +3 -2
@@ -218,14 +218,15 @@ bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer);size_t ring_buffer_nr_dirty_pages (struct trace_buffer *buffer,int cpu);struct buffer_data_read_page ; -struct buffer_data_read_page * -ring_buffer_alloc_read_page (struct trace_buffer *buffer,int cpu); +int ring_buffer_alloc_read_page (struct trace_buffer *buffer,int cpu, +struct buffer_data_read_page **rpage);void ring_buffer_free_read_page (struct trace_buffer *buffer,int cpu,struct buffer_data_read_page *page);int ring_buffer_read_page (struct trace_buffer *buffer,struct buffer_data_read_page *data_page,size_t len,int cpu,int full);void *ring_buffer_read_page_data (struct buffer_data_read_page *page); +unsigned int ring_buffer_read_page_size (struct buffer_data_read_page *rpage);struct trace_seq ;
kernel/trace/ring_buffer.c +93 -44
260 lines not on this page · raw message
kernel/trace/ring_buffer_benchmark.c +3 -3
@@ -104,7 +104,7 @@ static enum event_status read_event(int cpu)static enum event_status read_page (int cpu) { -struct buffer_data_read_page *bpage; +struct buffer_data_read_page *bpage =NULL ;struct ring_buffer_event *event;struct rb_page *rpage;unsigned long commit;
@@ -114,8 +114,8 @@ static enum event_status read_page(int cpu)int inc;int i; - bpage =ring_buffer_alloc_read_page (buffer, cpu); -if (IS_ERR (bpage)) + ret =ring_buffer_alloc_read_page (buffer, cpu, &bpage); +if (ret <0 )return EVENT_DROPPED ; page_size =ring_buffer_subbuf_size_get (buffer);
kernel/trace/trace.c +46 -60
185 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 511/621 bpf: Preserve inner map identity in callback frames
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit b90c5d770dad910fb89e6c1b15052a8a1e8db752 ]
Callback frame constructors initialize map-typed argument registers with __mark_reg_known_zero() and then restore map_ptr. This clears map_uid, which is the only field distinguishing inner maps that share an inner_map_meta template.
When a timer callback invokes bpf_for_each_map_elem() on a second inner map, both the saved first map and the second map value can reach the nested callback as the same template with map_uid zero. bpf_timer_init() then accepts pairing the timer from the second map with the first map.
The runtime records the first map in the timer without taking a reference. Freeing that map does not find the timer stored in the second map, so a later timer callback dereferences the freed map.
Copy map_uid from the same caller register as map_ptr when constructing for-each, timer/workqueue, and task-work callback arguments. The existing identity check can then reject mismatched inner maps while allowing a callback value to be paired with its actual map.
--- kernel/bpf/verifier.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/bpf/verifier.c +10 -0
@@ -10935,10 +10935,12 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env, callee->regs[BPF_REG_2 ].type =PTR_TO_MAP_KEY ;__mark_reg_known_zero (&callee->regs[BPF_REG_2 ]); callee->regs[BPF_REG_2 ].map_ptr = caller->regs[BPF_REG_1 ].map_ptr; + callee->regs[BPF_REG_2 ].map_uid = caller->regs[BPF_REG_1 ].map_uid; callee->regs[BPF_REG_3 ].type =PTR_TO_MAP_VALUE ;__mark_reg_known_zero (&callee->regs[BPF_REG_3 ]); callee->regs[BPF_REG_3 ].map_ptr = caller->regs[BPF_REG_1 ].map_ptr; + callee->regs[BPF_REG_3 ].map_uid = caller->regs[BPF_REG_1 ].map_uid;/* pointer to stack or null */ callee->regs[BPF_REG_4 ] = caller->regs[BPF_REG_3 ];
@@ -11016,6 +11018,7 @@ static int set_timer_callback_state(struct bpf_verifier_env *env, int insn_idx) {struct bpf_map *map_ptr = caller->regs[BPF_REG_1 ].map_ptr; +u32 map_uid = caller->regs[BPF_REG_1 ].map_uid;/* bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn); * callback_fn(struct bpf_map *map, void *key, void *value);
@@ -11023,14 +11026,17 @@ static int set_timer_callback_state(struct bpf_verifier_env *env, callee->regs[BPF_REG_1 ].type =CONST_PTR_TO_MAP ;__mark_reg_known_zero (&callee->regs[BPF_REG_1 ]); callee->regs[BPF_REG_1 ].map_ptr = map_ptr; + callee->regs[BPF_REG_1 ].map_uid = map_uid; callee->regs[BPF_REG_2 ].type =PTR_TO_MAP_KEY ;__mark_reg_known_zero (&callee->regs[BPF_REG_2 ]); callee->regs[BPF_REG_2 ].map_ptr = map_ptr; + callee->regs[BPF_REG_2 ].map_uid = map_uid; callee->regs[BPF_REG_3 ].type =PTR_TO_MAP_VALUE ;__mark_reg_known_zero (&callee->regs[BPF_REG_3 ]); callee->regs[BPF_REG_3 ].map_ptr = map_ptr; + callee->regs[BPF_REG_3 ].map_uid = map_uid;/* unused */ __mark_reg_not_init (env, &callee->regs[BPF_REG_4 ]);
@@ -11129,6 +11135,7 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env, int insn_idx) {struct bpf_map *map_ptr = caller->regs[BPF_REG_3 ].map_ptr; +u32 map_uid = caller->regs[BPF_REG_3 ].map_uid;/* * callback_fn(struct bpf_map *map, void *key, void *value);
@@ -11136,14 +11143,17 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env, callee->regs[BPF_REG_1 ].type =CONST_PTR_TO_MAP ;__mark_reg_known_zero (&callee->regs[BPF_REG_1 ]); callee->regs[BPF_REG_1 ].map_ptr = map_ptr; + callee->regs[BPF_REG_1 ].map_uid = map_uid; callee->regs[BPF_REG_2 ].type =PTR_TO_MAP_KEY ;__mark_reg_known_zero (&callee->regs[BPF_REG_2 ]); callee->regs[BPF_REG_2 ].map_ptr = map_ptr; + callee->regs[BPF_REG_2 ].map_uid = map_uid; callee->regs[BPF_REG_3 ].type =PTR_TO_MAP_VALUE ;__mark_reg_known_zero (&callee->regs[BPF_REG_3 ]); callee->regs[BPF_REG_3 ].map_ptr = map_ptr; + callee->regs[BPF_REG_3 ].map_uid = map_uid;/* unused */ __mark_reg_not_init (env, &callee->regs[BPF_REG_4 ]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 485/621 bpf: Reject writes through untrusted BTF pointers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Dudar <[email protected]>
[ Upstream commit ac65c710cc643cbc52b899627577357867249530 ]
check_ptr_to_btf_access() lets program-type btf_struct_access callbacks validate writes before the default BTF access path rejects non-read accesses. That bypasses the read-only policy for untrusted BTF pointers created by helpers such as bpf_rdonly_cast().
Reject non-read accesses through PTR_UNTRUSTED BTF pointers at the common entry point, before the callback branch to handle all cases.
--- kernel/bpf/verifier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +6 -2
@@ -7372,6 +7372,11 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,return -EACCES ; } +if (atype !=BPF_READ && (type_flag (reg->type) &PTR_UNTRUSTED )) { +verbose (env,"only read is supported\n" ); +return -EACCES ; + } +if (env->ops->btf_struct_access && !type_is_alloc (reg->type) && atype ==BPF_WRITE ) {if (!btf_is_kernel (reg->btf)) {verifier_bug (env,"reg->btf must be kernel btf" );
@@ -7380,8 +7385,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env, ret = env->ops->btf_struct_access (&env->log, reg, off, size); }else {/* Writes are permitted with default btf_struct_access for -* program allocated objects (which always have ref_obj_id > 0), -* but not for untrusted PTR_TO_BTF_ID | MEM_ALLOC. +* program allocated objects (which always have ref_obj_id > 0). */ if (atype !=BPF_READ && !type_is_ptr_alloc_obj (reg->type)) {verbose (env,"only read is supported\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 512/621 bpf: Mark NULL kptr stores precise
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit ecdc5043794c9184aa8e6c814603899479c46b35 ]
check_map_kptr_access() permits a scalar store into an untrusted kptr field only when the register is known to contain zero. Unlike other verifier checks whose outcome depends on a scalar value, it does not mark that register precise.
A state checkpoint reached with an imprecise zero can therefore prune a second path that reaches the store with an arbitrary nonzero scalar. The program can write attacker-controlled bits into the kptr field and load them back as a PTR_TO_BTF_ID.
Call mark_chain_precision() before accepting a known-zero register. This forces state equivalence to compare its scalar range and makes the verifier visit and reject a path carrying a nonzero value.
--- kernel/bpf/verifier.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +9 -2
@@ -6097,8 +6097,15 @@ static int check_map_kptr_access(struct bpf_verifier_env *env, u32 regno,return ret; }else if (class ==BPF_STX ) { val_reg =reg_state (env, value_regno); -if (!register_is_null (val_reg) && -map_kptr_match_type (env, kptr_field, val_reg, value_regno)) +if (register_is_null (val_reg)) { +/* +* This store is valid only because the scalar is known to be +* zero. Mark it precise so another scalar cannot be pruned +* against this state. +*/ +return mark_chain_precision (env, value_regno); + } +if (map_kptr_match_type (env, kptr_field, val_reg, value_regno))return -EACCES ; }else if (class ==BPF_ST ) {if (insn->imm) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 513/621 bpf: Keep refcount_acquire nullable for borrowed RCU kptrs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ning Ding <[email protected]>
[ Upstream commit dc36739e5cc9f60485418a910b42bc95339218d2 ]
bpf_refcount_acquire() is fallible for a borrowed reference because the object may have reached a zero refcount. The verifier therefore keeps KF_RET_NULL on the return value unless the argument is an owning reference.
An RCU-protected load of a local kptr is marked MEM_ALLOC, but it only receives NON_OWN_REF when the pointee contains a graph node. A refcounted object without a graph node consequently looks like an owning reference even though the loaded register has no acquired reference state. If the program drops the last real reference while remaining in the RCU critical section, refcount_inc_not_zero() returns NULL while the verifier treats the result as non-NULL.
Only classify the argument as owning when it is backed by a verifier-tracked reference. This retains the non-NULL return for pointers from bpf_obj_new(), bpf_kptr_xchg(), or an earlier successful acquisition, while requiring a NULL check for borrowed RCU kptrs.
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -13812,7 +13812,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_verbose (env,"arg#%d is neither owning or non-owning ref\n" , i);return -EINVAL ; } -if (!type_is_non_owning_ref (reg->type)) +if (!type_is_non_owning_ref (reg->type) && reg->ref_obj_id) meta->arg_owning_ref = true; rec =reg_btf_record (reg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 514/621 bpf: Dont infer non-NULL from a pointer with an unbounded offset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 67b529f521a6676cdfc78b91b0217d7eaa84216b ]
reg_not_null() decides that a register holds a non-NULL value by looking at its type alone. For pointer types that allow arithmetic the type only guarantees a non-NULL base, in case of an unbound offset the runtime offset value might still add up to NULL. Consider the followng program:
r6 = bpf_map_lookup_elem(map, &0); /* present */
if (r6 == 0) return 0;
r7 = bpf_map_lookup_elem(map, &1); /* absent, NULL at runtime */
r8 = r7;
r8 -= r6; /* pointer - pointer: unknown scalar, -r6 */
r8 <<= 1;
r8 >>= 1; /* any non-negative offset is accepted by */
/* check_reg_sane_offset_ptr() */
r6 += r8; /* verifier: map value; runtime: zero */
if (r7 != r6) return 0;
*(u8 *)(r7 + 0); /* r7 is inferred non-NULL, both are zero */At runtime both registers are zero, the comparison is true and the load faults with NULL pointer dereference.
Require the offset to be within +-BPF_MAX_VAR_OFF in reg_not_null().
--- kernel/bpf/verifier.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/bpf/verifier.c +7 -0
@@ -405,6 +405,13 @@ static bool reg_not_null(const struct bpf_reg_state *reg)if (type_may_be_null (type))return false; +/* +* The types below guarantee a non-NULL base, an unbounded offset can +* still wrap base + offset to zero. +*/ +if (reg->smin_value <= -BPF_MAX_VAR_OFF || reg->smax_value >=BPF_MAX_VAR_OFF ) +return false; + type =base_type (type);return type ==PTR_TO_SOCKET || type == PTR_TO_TCP_SOCK ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/621 bpf: dont rewrite bpf_fastcall patterns entered by a jump
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 0b1c83dc3c4401cd7e846548f62e3caf3d06742e ]
mark_fastcall_pattern_for_call() must ensure that matched "spill; call; fill" instruction series is not interrupted by a jump. Otherwise the rewrite applied by bpf_remove_fastcall_spills_fills() is not sound.
Record the instructions targeted by jumps in insn_aux_data[*].jump_target when the CFG is built and use this flag to stop growing a pattern at such an instruction. Jumps to the first spill are fine.
Note that existing insn_aux_data[*].jmp_point field can't be reused, as it marks subprogram return instructions.
--- include/linux/bpf_verifier.h | 2 ++ kernel/bpf/verifier.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+)
include/linux/bpf_verifier.h +2 -0
@@ -580,6 +580,8 @@ struct bpf_insn_aux_data {* accepts callback function as a parameter. */ bool calls_callback; +/* true if some jump or call instruction targets this instruction */ +bool jump_target;/* * CFG strongly connected component this instruction belongs to, * zero if it is a singleton SCC.
kernel/bpf/verifier.c +20 -0
@@ -3889,6 +3889,16 @@ static bool is_jmp_point(struct bpf_verifier_env *env, int insn_idx)return env->insn_aux_data[insn_idx].jmp_point; } +static void mark_jump_target (struct bpf_verifier_env *env,int idx) +{ + env->insn_aux_data[idx].jump_target = true; +} + +static bool bpf_is_jump_target (struct bpf_verifier_env *env,int insn_idx) +{ +return env->insn_aux_data[insn_idx].jump_target; +} +#define LR_FRAMENO_BITS 3#define LR_SPI_BITS 6#define LR_ENTRY_BITS (LR_SPI_BITS + LR_FRAMENO_BITS + 1)
@@ -18012,6 +18022,7 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)/* mark branch target for state pruning */ mark_prune_point (env, w);mark_jmp_point (env, w); +mark_jump_target (env, w); }if (insn_state[w] ==0 ) {
@@ -18206,6 +18217,10 @@ static bool get_call_summary(struct bpf_verifier_env *env, struct bpf_insn *call* r0 = *(u64 *)(r10 - 8); r0 += r1; * r0 += r1; exit; * exit; +* +* Both uses of the marks assume that a pattern is entered at its first +* spill and thus executes as a unit, hence a pattern is not grown past +* an instruction targeted by a jump. */ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env, struct bpf_subprog_info *subprog,
@@ -18244,6 +18259,10 @@ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env,for (i =1 , off = lowest_off; i <=ARRAY_SIZE (caller_saved); ++i, off +=BPF_REG_SIZE ) {if (insn_idx - i <0 || insn_idx + i >= env->prog->len)break ; +/* stx/ldx/call must not be a jump targets, a jump to the first stx is fine */ +if (bpf_is_jump_target (env, insn_idx - i +1 ) || +bpf_is_jump_target (env, insn_idx + i)) +break ; stx = &insns[insn_idx - i]; ldx = &insns[insn_idx + i];/* must be a stack spill/fill pair */
@@ -18429,6 +18448,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)mark_prune_point (env, t + off +1 );mark_jmp_point (env, t + off +1 ); +mark_jump_target (env, t + off +1 );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 516/621 bpf: zero extend the result of an arena 32-bit cmpxchg
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 4814ed6406f3493bd554ad046da5f7fc04833571 ]
bpf_convert_ctx_accesses() rewrites an atomic on an arena pointer from BPF_STX | BPF_ATOMIC to BPF_STX | BPF_PROBE_ATOMIC, and it runs before bpf_opt_subreg_zext_lo32_rnd_hi32().
That pass emits an explicit zero extension for a 32-bit cmpxchg even when bpf_jit_needs_zext() is false. This is done because on some architectures 32-bit cmpxchg requires explicit zero extension for the dst register. E.g. on x86-64 'lock cmpxchg' does not change the %eax if comparison is successful, while BPF semantics declare that each operation on a 32-bit register zero extends it's upper half.
is_cmpxchg_insn() matches BPF_MODE == BPF_ATOMIC only, so an arena cmpxchg misses said zero extension adjustment. This patch adjusts is_cmpxchg_insn() to match BPF_PROBE_ATOMIC alongside BPF_ATOMIC.
--- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +6 -1
@@ -604,10 +604,15 @@ static bool helper_multiple_ref_obj_use(enum bpf_func_id func_id,return ref_obj_uses >1 ; } +/* +* Matches BPF_PROBE_ATOMIC too: bpf_convert_ctx_accesses() rewrites arena +* atomics before bpf_opt_subreg_zext_lo32_rnd_hi32() runs. +*/ static bool is_cmpxchg_insn (const struct bpf_insn *insn) {return BPF_CLASS (insn->code) ==BPF_STX && -BPF_MODE (insn->code) ==BPF_ATOMIC && + (BPF_MODE (insn->code) ==BPF_ATOMIC || +BPF_MODE (insn->code) ==BPF_PROBE_ATOMIC ) && insn->imm ==BPF_CMPXCHG ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 517/621 ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit eb3bd277b37cd435d26a44a40d8f7c87ff16feb6 ]
Skip invalid sub-buffers when validating the persistent ring buffer instead of discarding the entire ring buffer. Only skipped buffers are invalidated (cleared).
If the cache data in memory fails to be synchronized during a reboot, the persistent ring buffer may become partially corrupted, but other sub-buffers may still contain readable event data. Only discard the subbuffers that are found to be corrupted.
Stable-dep-of: 6c001a62c34f ("ring-buffer: Add checking nr_subbufs to persistent ring buffer validation")
--- kernel/trace/ring_buffer.c | 118 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 46 deletions(-)
kernel/trace/ring_buffer.c +72 -46
@@ -412,6 +412,12 @@ static __always_inline unsigned int rb_page_capacity(struct buffer_page *bpage)return (PAGE_SIZE << bpage->order) -BUF_PAGE_HDR_SIZE ; } +/* Size is determined by what has been committed */ +static __always_inline unsigned int rb_page_size(struct buffer_page *bpage) +{ +return rb_page_commit (bpage) & ~RB_MISSED_MASK ; +} +static void free_buffer_page (struct buffer_page *bpage) {/* Range pages are not to be freed */
@@ -1836,7 +1842,6 @@ static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu, unsigned long *subbuf_mask) {int subbuf_size =PAGE_SIZE ; -struct buffer_data_page *subbuf;unsigned long buffers_start;unsigned long buffers_end;int i;
@@ -1844,6 +1849,11 @@ static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu,if (!subbuf_mask)return false; +if (meta->subbuf_size !=PAGE_SIZE ) { +pr_info ("Ring buffer boot meta [%d] invalid subbuf_size\n" , cpu); +return false; + } + buffers_start = meta->first_buffer; buffers_end = meta->first_buffer + (subbuf_size * meta->nr_subbufs);
@@ -1860,11 +1870,12 @@ static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu,return false; } - subbuf =rb_subbufs_from_meta (meta); -bitmap_clear (subbuf_mask,0 , meta->nr_subbufs); -/* Is the meta buffers and the subbufs themselves have correct data? */ +/* +* Ensure the meta::buffers array has correct data. The data in each subbufs +* are checked later in rb_meta_validate_events(). +*/ for (i =0 ; i < meta->nr_subbufs; i++) {if (meta->buffers[i] <0 || meta->buffers[i] >= meta->nr_subbufs) {
@@ -1872,18 +1883,12 @@ static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu,return false; } -if ((unsigned )local_read (&subbuf->commit) > subbuf_size) { -pr_info ("Ring buffer boot meta [%d] buffer invalid commit\n" , cpu); -return false; - } -if (test_bit (meta->buffers[i], subbuf_mask)) {pr_info ("Ring buffer boot meta [%d] array has duplicates\n" , cpu);return false; }set_bit (meta->buffers[i], subbuf_mask); - subbuf = (void *)subbuf + subbuf_size; }return true;
@@ -1947,13 +1952,22 @@ static int rb_read_data_buffer(struct buffer_data_page *dpage, int tail, int cpureturn events; } -static int rb_validate_buffer (struct buffer_data_page *dpage,int cpu) +static int rb_validate_buffer (struct buffer_data_page *dpage,int cpu, +struct ring_buffer_cpu_meta *meta) {unsigned long long ts; +unsigned long tail;u64 delta; -int tail; - tail =local_read (&dpage->commit); +/* +* When a sub-buffer is recovered from a read, the commit value may +* have RB_MISSED_* bits set, as these bits are reset on reuse. +* Even after clearing these bits, a commit value greater than the +* subbuf_size is considered invalid. +*/ + tail =local_read (&dpage->commit) & ~RB_MISSED_MASK ; +if (tail > meta->subbuf_size -BUF_PAGE_HDR_SIZE ) +return -1 ;return rb_read_data_buffer (dpage, tail, cpu, &ts, &delta); }
@@ -1964,6 +1978,7 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)struct buffer_page *head_page, *orig_head, *orig_reader;unsigned long entry_bytes =0 ;unsigned long entries =0 ; +int discarded =0 ;int ret;u64 ts;int i;
@@ -1975,14 +1990,19 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer) orig_reader = cpu_buffer->reader_page;/* Do the reader page first */ - ret =rb_validate_buffer (orig_reader->page, cpu_buffer->cpu); + ret =rb_validate_buffer (orig_reader->page, cpu_buffer->cpu, meta);if (ret <0 ) { -pr_info ("Ring buffer reader page is invalid\n" ); - goto invalid; +pr_info ("Ring buffer meta [%d] invalid reader page detected\n" , + cpu_buffer->cpu); + discarded++; +/* Instead of discard whole ring buffer, discard only this sub-buffer. */ +local_set (&orig_reader->entries,0 ); +local_set (&orig_reader->page->commit,0 ); + }else { + entries += ret; + entry_bytes +=rb_page_size (orig_reader); +local_set (&orig_reader->entries, ret); } - entries += ret; - entry_bytes +=local_read (&orig_reader->page->commit); -local_set (&orig_reader->entries, ret); ts = head_page->page->time_stamp;
@@ -2010,7 +2030,7 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)break ;/* Stop rewind if the page is invalid. */ - ret =rb_validate_buffer (head_page->page, cpu_buffer->cpu); + ret =rb_validate_buffer (head_page->page, cpu_buffer->cpu, meta);if (ret <0 )break ;
@@ -2019,7 +2039,7 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)if (ret)local_inc (&cpu_buffer->pages_touched); entries += ret; - entry_bytes +=rb_page_commit (head_page); + entry_bytes +=rb_page_size (head_page); }if (i)pr_info ("Ring buffer [%d] rewound %d pages\n" , cpu_buffer->cpu, i);
@@ -2089,21 +2109,24 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)if (head_page == orig_reader)continue ; - ret =rb_validate_buffer (head_page->page, cpu_buffer->cpu); + ret =rb_validate_buffer (head_page->page, cpu_buffer->cpu, meta);if (ret <0 ) { -pr_info ("Ring buffer meta [%d] invalid buffer page\n" , - cpu_buffer->cpu); - goto invalid; - } - -/* If the buffer has content, update pages_touched */ -if (ret) -local_inc (&cpu_buffer->pages_touched); - - entries += ret; - entry_bytes +=local_read (&head_page->page->commit); -local_set (&head_page->entries, ret); +if (!discarded) +pr_info ("Ring buffer meta [%d] invalid buffer page detected\n" , + cpu_buffer->cpu); + discarded++; +/* Instead of discard whole ring buffer, discard only this sub-buffer. */ +local_set (&head_page->entries,0 ); +local_set (&head_page->page->commit,0 ); + }else { +/* If the buffer has content, update pages_touched */ +if (ret) +local_inc (&cpu_buffer->pages_touched); + entries += ret; + entry_bytes +=rb_page_size (head_page); +local_set (&head_page->entries, ret); + }if (head_page == cpu_buffer->commit_page)break ; }
@@ -2117,7 +2140,10 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)local_set (&cpu_buffer->entries, entries);local_set (&cpu_buffer->entries_bytes, entry_bytes); -pr_info ("Ring buffer meta [%d] is from previous boot!\n" , cpu_buffer->cpu); +pr_info ("Ring buffer meta [%d] is from previous boot!" , cpu_buffer->cpu); +if (discarded) +pr_cont (" (%d pages discarded)" , discarded); +pr_cont ("\n" );return ; invalid:
@@ -3303,12 +3329,6 @@ rb_iter_head_event(struct ring_buffer_iter *iter)return NULL ; } -/* Size is determined by what has been committed */ -static __always_inline unsigned rb_page_size (struct buffer_page *bpage) -{ -return rb_page_commit (bpage) & ~RB_MISSED_MASK ; -} -static __always_inline unsigned rb_commit_index (struct ring_buffer_per_cpu *cpu_buffer) {
@@ -5480,6 +5500,7 @@ rb_update_iter_read_stamp(struct ring_buffer_iter *iter,static struct buffer_page *rb_get_reader_page (struct ring_buffer_per_cpu *cpu_buffer) { +int max_loops = cpu_buffer->ring_meta ? cpu_buffer->nr_pages :3 ;struct buffer_page *reader =NULL ;unsigned long overwrite;unsigned long flags;
@@ -5492,11 +5513,14 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) again:/* * This should normally only loop twice. But because the -* start of the reader inserts an empty page, it causes -* a case where we will loop three times. There should be no -* reason to loop four times (that I know of). +* start of the reader inserts an empty page, it causes a +* case where we will loop three times. There should be no +* reason to loop four times unless the ring buffer is a +* recovered persistent ring buffer. For persistent ring buffers, +* invalid pages are reset during recovery, so there may be more +* than 3 contiguous pages can be empty, but less than nr_pages. */ -if (RB_WARN_ON (cpu_buffer, ++nr_loops >3 )) { +if (RB_WARN_ON (cpu_buffer, ++nr_loops > max_loops)) { reader =NULL ; goto out; }
@@ -5786,12 +5810,14 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)struct ring_buffer_per_cpu *cpu_buffer;struct ring_buffer_event *event;int nr_loops =0 ; +int max_loops;if (ts) *ts =0 ; cpu_buffer = iter->cpu_buffer; buffer = cpu_buffer->buffer; + max_loops = cpu_buffer->ring_meta ? cpu_buffer->nr_pages :3 ;/* * Check if someone performed a consuming read to the buffer
@@ -5814,7 +5840,7 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)* the ring buffer with an active write as the consumer is. * Do not warn if the three failures is reached. */ -if (++nr_loops >3 ) +if (++nr_loops > max_loops)return NULL ;if (rb_per_cpu_empty (cpu_buffer))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 518/621 ring-buffer: Add checking nr_subbufs to persistent ring buffer validation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit 6c001a62c34f13fe1c6a24304c289b387d9e697d ]
Sashiko reported that the code was using meta->nr_subbufs without making sure that it matched the nr_pages + 1 on data that was assuming the two were the same.
Add a check to the persistent ring buffer validation code to make sure that the saved nr_subbufs matches what we expect.
--- kernel/trace/ring_buffer.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/trace/ring_buffer.c +5 -0
@@ -1854,6 +1854,11 @@ static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu,return false; } +if (meta->nr_subbufs != nr_pages +1 ) { +pr_info ("Ring buffer boot meta [%d] invalid nr_subbufs\n" , cpu); +return false; + } + buffers_start = meta->first_buffer; buffers_end = meta->first_buffer + (subbuf_size * meta->nr_subbufs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 519/621 bpf: Mark syscall helpers as sleepable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit d05524794240b52fdc3b6c1220dd05505715824d ]
bpf_sys_bpf() executes the bpf(2) syscall body, which can take mutexes, allocate with GFP_KERNEL, and wait for an RCU grace period. bpf_sys_close() reaches close_fd() and filp_close(), which can sleep as well.
Both helpers are limited to BPF_PROG_TYPE_SYSCALL, whose main program is sleepable. That does not make every callback sleepable: a syscall program can register a bpf_timer callback, and the verifier checks that callback in a non-sleepable context while retaining the syscall helper set.
Without .might_sleep on the prototypes, such a callback can invoke bpf_sys_bpf() from hrtimer softirq context and trigger a scheduling-while-atomic failure. bpf_sys_close() is exposed through the same missing context check.
Set .might_sleep on both prototypes so the existing helper-context check rejects them from timer callbacks and other atomic regions. Calls from the sleepable main body remain valid.
--- kernel/bpf/syscall.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/bpf/syscall.c +2 -0
@@ -6396,6 +6396,7 @@ EXPORT_SYMBOL_NS(kern_sys_bpf, "BPF_INTERNAL");static const struct bpf_func_proto bpf_sys_bpf_proto = { .func = bpf_sys_bpf, .gpl_only = false, + .might_sleep = true, .ret_type =RET_INTEGER , .arg1_type =ARG_ANYTHING , .arg2_type =ARG_PTR_TO_MEM |MEM_RDONLY ,
@@ -6421,6 +6422,7 @@ BPF_CALL_1(bpf_sys_close, u32, fd)static const struct bpf_func_proto bpf_sys_close_proto = { .func = bpf_sys_close, .gpl_only = false, + .might_sleep = true, .ret_type =RET_INTEGER , .arg1_type =ARG_ANYTHING , };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 520/621 bpf: backtracking shouldnt clear outer frame R1-R5 for callbacks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit e3e4f66cc4b72333d0886ae2673c360248987889 ]
When processing calls to bpf_loop() verifier marks R1 (and R4) as precise. R1 tracks loop iterations number and because of the 'callback_depth < R1' mechanics in check_helper_call() must be marked precise. However, precision propagation for R1 was broken, when bpf_loop() call was verified on a second iteration.
Consider the following verification trace:
- main: bpf_loop(nr_loops, callback ...)
- callback: BPF_EXIT
- main: bpf_loop(nr_loops, callback ...)
- ...
While the first visit of the call to bpf_loop() propagated R1 precision as expected, the second call to mark_chain_precision() in the check_helper_call() set R1, but it was immediately reset when backtrack_insn() processed preceding BPF_EXIT in the loop deleted in this patch.
Because of that, the second visit of the call to bpf_loop() injected checkpoint with R1 not marked as precise. Which could trick the verifier into accepting unsafe programs. See the next patch for an example of such program.
Commit is structured in a way to minimize conflicts when 'bpf' would be eventually merged with 'bpf-next'.
--- kernel/bpf/verifier.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
kernel/bpf/verifier.c +17 -20
@@ -4514,37 +4514,34 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,return -EFAULT ; } }else if (opcode ==BPF_EXIT ) { -bool r0_precise; +bool from_subprog_call, r0_precise; + +/* BPF_EXIT in subprog or callback always returns +* right after the call instruction, so by checking +* whether the instruction at subseq_idx-1 is subprog +* call or not we can distinguish actual exit from +* *subprog* from exit from *callback*. In the former +* case, we need to propagate r0 precision, if +* necessary. In the former we never do that. +*/ + from_subprog_call = subseq_idx -1 >=0 && +bpf_pseudo_call (&env->prog->insnsi[subseq_idx -1 ]); + + r0_precise = from_subprog_call &&bt_is_reg_set (bt,BPF_REG_0 );/* Backtracking to a nested function call, 'idx' is a part of * the inner frame 'subseq_idx' is a part of the outer frame. * In case of a regular function call, instructions giving * precision to registers R1-R5 should have been found already. -* In case of a callback, it is ok to have R1-R5 marked for -* backtracking, as these registers are set by the function -* invoking callback. +* In case of a callback from bpf_loop(), R{1,4} in the calling +* frame would be set as precise and that is correct. */ -if (subseq_idx >=0 &&bpf_calls_callback (env, subseq_idx)) -for (i =BPF_REG_1 ; i <=BPF_REG_5 ; i++) -bt_clear_reg (bt, i); -if (bt_reg_mask (bt) &BPF_REGMASK_ARGS ) { +if (from_subprog_call && (bt_reg_mask (bt) &BPF_REGMASK_ARGS )) {verifier_bug (env,"backtracking exit unexpected regs %x" ,bt_reg_mask (bt));return -EFAULT ; } -/* BPF_EXIT in subprog or callback always returns -* right after the call instruction, so by checking -* whether the instruction at subseq_idx-1 is subprog -* call or not we can distinguish actual exit from -* *subprog* from exit from *callback*. In the former -* case, we need to propagate r0 precision, if -* necessary. In the former we never do that. -*/ - r0_precise = subseq_idx -1 >=0 && -bpf_pseudo_call (&env->prog->insnsi[subseq_idx -1 ]) && -bt_is_reg_set (bt,BPF_REG_0 ); -bt_clear_reg (bt,BPF_REG_0 );if (bt_subprog_enter (bt))return -EFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 521/621 bpf: backtrack_insn(): Handle ld_{abs,ind} subprog exit edge
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 387b1baefbb776e3f48dc2261e77a49213f470f7 ]
Nicholas Carlini reported a bug in precision backtracking mechanism for BPF_LD | BPF_{IND,ABS} instructions. These instructions are modelled as two branches:
- fallthrough;
- implicit exit from current subprogram.
The implicit exit case was not handled by the backtrack_insn() function. When backtracking such a path backtrack_insn() did not call bt_subprog_enter(), which meant that backtracking continued manipulating precision marks in a caller frame, while looking at instructions in a callee frame.
This lead to segmentation faults during verification (see the selftest), or unsound state pruning.
--- kernel/bpf/verifier.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
kernel/bpf/verifier.c +19 -6
@@ -4573,16 +4573,29 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,*/ } }else if (class ==BPF_LD ) { -if (!bt_is_reg_set (bt, dreg)) -return 0 ; -bt_clear_reg (bt, dreg);/* It's ld_imm64 or ld_abs or ld_ind. * For ld_imm64 no further tracking of precision * into parent is necessary */ -if (mode ==BPF_IND || mode ==BPF_ABS ) -/* to be analyzed */ -return -ENOTSUPP ; +if (mode ==BPF_IMM ) { +bt_clear_reg (bt, dreg); +return 0 ; + } +/* +* BPF_{IND,ABS} are modelled as two branches: +* - fallthrough; +* - implicit subprogram exit. +* It is necessary to switch current frame if +* implicit subprogram exit branch is backtracked. +*/ +if (mode ==BPF_IND || mode ==BPF_ABS ) { +if (bt_is_reg_set (bt, dreg)) +return -ENOTSUPP ; +if (subseq_idx != idx +1 ) +if (bt_subprog_enter (bt)) +return -EFAULT ; +return 0 ; + } }/* Propagate precision marks to linked registers, to account for * registers marked as precise in this function.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 486/621 bpf: Reject MEM_ALLOC BTF accesses past object bounds
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 9c9ee0324c774490ae953162aaaf4561d222bd93 ]
BTF struct walks relax the struct-size check for accesses through a trailing flexible array. That is valid for ordinary BTF type walking, but PTR_TO_BTF_ID | MEM_ALLOC values point to objects allocated with the static BTF type size.
When walking a MEM_ALLOC object, reject the access before applying the flexible-array relaxation if the access range extends past the struct size. Apply the same policy to struct ID matching so kfunc and kptr type checks do not walk past the allocated object bounds either.
--- include/linux/bpf.h | 2 +- kernel/bpf/btf.c | 17 +++++++++++------ kernel/bpf/verifier.c | 12 ++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-)
include/linux/bpf.h +1 -1
@@ -2830,7 +2830,7 @@ int btf_struct_access(struct bpf_verifier_log *log,bool btf_struct_ids_match (struct bpf_verifier_log *log,const struct btf *btf,u32 id,int off,const struct btf *need_btf,u32 need_type_id, -bool strict); +bool strict,bool walk_flex_arrays); int btf_distill_func_proto(struct bpf_verifier_log *log, struct btf *btf,
kernel/bpf/btf.c +11 -6
@@ -6986,7 +6986,7 @@ enum bpf_struct_walk_result {static int btf_struct_walk (struct bpf_verifier_log *log,const struct btf *btf,const struct btf_type *t,int off,int size,u32 *next_btf_id,enum bpf_type_flag *flag, -const char **field_name) +const char **field_name,bool walk_flex_arrays) {u32 i, moff, mtrue_end, msize =0 , total_nelems =0 ;const struct btf_type *mtype, *elem_type =NULL ;
@@ -7013,11 +7013,14 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, *flag |=PTR_UNTRUSTED ;if (off + size > t->size) { +struct btf_array *array_elem; + +if (!walk_flex_arrays) + goto error; +/* If the last element is a variable size array, we may * need to relax the rule. */ -struct btf_array *array_elem; -if (vlen ==0 ) goto error;
@@ -7280,7 +7283,8 @@ int btf_struct_access(struct bpf_verifier_log *log, t =btf_type_by_id (btf, id); do { - err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag, field_name); + err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag, + field_name, !type_is_alloc(reg->type)); switch (err) { case WALK_PTR:
@@ -7339,7 +7343,7 @@ bool btf_types_are_same(const struct btf *btf1, u32 id1,bool btf_struct_ids_match (struct bpf_verifier_log *log,const struct btf *btf,u32 id,int off,const struct btf *need_btf,u32 need_type_id, -bool strict) +bool strict,bool walk_flex_arrays) {const struct btf_type *type;enum bpf_type_flag flag =0 ;
@@ -7358,7 +7362,8 @@ bool btf_struct_ids_match(struct bpf_verifier_log *log, type =btf_type_by_id (btf, id);if (!type)return false; - err =btf_struct_walk (log, btf, type, off,1 , &id, &flag,NULL ); + err =btf_struct_walk (log, btf, type, off,1 , &id, &flag,NULL , + walk_flex_arrays);if (err !=WALK_STRUCT )return false;
kernel/bpf/verifier.c +8 -4
@@ -5934,7 +5934,8 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,*/ if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id, reg->off, kptr_field->kptr.btf, kptr_field->kptr.btf_id, - kptr_field->type !=BPF_KPTR_UNREF )) + kptr_field->type !=BPF_KPTR_UNREF , + !type_is_alloc (reg->type))) goto bad_type;return 0 ; bad_type:
@@ -9529,7 +9530,8 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id, reg->off, btf_vmlinux, *arg_btf_id, - strict_type_match)) { + strict_type_match, + !type_is_alloc (reg->type))) {verbose (env,"R%d is of type %s but %s is expected\n" , regno,btf_type_name (reg->btf, reg->btf_id),btf_type_name (btf_vmlinux, *arg_btf_id));
@@ -12829,7 +12831,8 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env, reg_ref_t =btf_type_skip_modifiers (reg_btf, reg_ref_id, ®_ref_id); reg_ref_tname =btf_name_by_offset (reg_btf, reg_ref_t->name_off); - struct_same =btf_struct_ids_match (&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match); + struct_same =btf_struct_ids_match (&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match, + !type_is_alloc (reg->type));/* If kfunc is accepting a projection type (ie. __sk_buff), it cannot * actually use it -- it must cast to the underlying type. So we allow * caller to pass in the underlying type.
@@ -13266,7 +13269,8 @@ __process_kf_arg_ptr_to_graph_node(struct bpf_verifier_env *env, et =btf_type_by_id (field->graph_root.btf, field->graph_root.value_btf_id); t =btf_type_by_id (reg->btf, reg->btf_id);if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id,0 , field->graph_root.btf, - field->graph_root.value_btf_id, true)) { + field->graph_root.value_btf_id, true, + !type_is_alloc (reg->type))) { verbose(env, "operation on %s expects arg#1 %s at offset=%d " "in struct %s, but arg is at offset=%d in struct %s\n", btf_field_type_name(head_field_type),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 522/621 ipv6: mcast: annotate data-races around mca_users
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuyang Huang <[email protected]>
[ Upstream commit 56ed77ff6022271e172f043b44193889226e42b0 ]
/proc/net/igmp6 walks IPv6 multicast memberships under RCU and prints mca_users without holding idev->mc_lock, while multicast join and leave paths update the field while holding idev->mc_lock. Annotate this intentional lockless snapshot with READ_ONCE() and the matching writers with WRITE_ONCE().
Stable-dep-of: 0c8f56c583c3 ("ipv6: mcast: use rcu_assign_pointer() for __rcu list updates")
--- net/ipv6/mcast.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
net/ipv6/mcast.c +7 -4
@@ -890,7 +890,7 @@ static struct ifmcaddr6 *mca_alloc(struct inet6_dev *idev, mc->mca_addr = *addr; mc->idev = idev;/* reference taken by caller */ - mc->mca_users =1 ; +WRITE_ONCE (mc->mca_users,1 );/* mca_stamp should be updated upon changes */ mc->mca_cstamp = mc->mca_tstamp = jiffies;refcount_set (&mc->mca_refcnt,1 );
@@ -964,7 +964,7 @@ static int __ipv6_dev_mc_inc(struct net_device *dev,for_each_mc_mclock (idev, mc) {if (ipv6_addr_equal (&mc->mca_addr, addr)) { - mc->mca_users++; +WRITE_ONCE (mc->mca_users, mc->mca_users +1 );ip6_mc_add_src (idev, &mc->mca_addr, mode,0 ,NULL ,0 );mutex_unlock (&idev->mc_lock);in6_dev_put (idev);
@@ -1009,7 +1009,10 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) (ma =mc_dereference (*map, idev)); map = &ma->next) {if (ipv6_addr_equal (&ma->mca_addr, addr)) { -if (--ma->mca_users ==0 ) { +int new_users = ma->mca_users -1 ; + +WRITE_ONCE (ma->mca_users, new_users); +if (new_users ==0 ) { *map = ma->next;igmp6_group_dropped (ma);
@@ -3021,7 +3024,7 @@ static int igmp6_mc_seq_show(struct seq_file *seq, void *v)"%-4d %-15s %pi6 %5d %08X %ld\n" , state->dev->ifindex, state->dev->name, &im->mca_addr, - im->mca_users, im->mca_flags, +READ_ONCE (im->mca_users), im->mca_flags, (im->mca_flags &MAF_TIMER_RUNNING ) ? jiffies_to_clock_t(im->mca_work.timer.expires - jiffies) : 0);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 523/621 ipv6: mcast: use rcu_assign_pointer() for __rcu list updates
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 0c8f56c583c3250408367880c98e4d6fbc929315 ]
Several places in net/ipv6/mcast.c update RCU-protected lists (np->ipv6_mc_list, idev->mc_list, idev->mc_tomb) using direct pointer assignments instead of rcu_assign_pointer():
1. In __ipv6_dev_mc_dec(), unlinking a group from idev->mc_list did:
*map = ma->next;
without rcu_assign_pointer() while concurrent readers traverse idev->mc_list locklessly under rcu_read_lock().
2. In ipv6_sock_mc_drop() and __ipv6_sock_mc_close(), unlinking a group from np->ipv6_mc_list directly assigned *lnk = mc_lst->next and np->ipv6_mc_list = mc_lst->next without rcu_assign_pointer(), racing with lockless readers in inet6_mc_check().
3. In __ipv6_sock_mc_join(), mc_lst->next was initialized to np->ipv6_mc_list via raw assignment before publishing mc_lst.
4. In mld_del_delrec() and __ipv6_dev_mc_inc(), __rcu source pointers passed into rcu_assign_pointer() lacked explicit dereference helpers.
Fix these by consistently using rcu_assign_pointer() along with mc_dereference() / sock_dereference().
--- net/ipv6/mcast.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
net/ipv6/mcast.c +13 -7
@@ -240,7 +240,8 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,return err; } - mc_lst->next = np->ipv6_mc_list; +rcu_assign_pointer (mc_lst->next, +sock_dereference (np->ipv6_mc_list, sk));rcu_assign_pointer (np->ipv6_mc_list, mc_lst);return 0 ;
@@ -300,7 +301,8 @@ int ipv6_sock_mc_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) lnk = &mc_lst->next) {if ((ifindex ==0 || mc_lst->ifindex == ifindex) &&ipv6_addr_equal (&mc_lst->addr, addr)) { - *lnk = mc_lst->next; +rcu_assign_pointer (*lnk, +sock_dereference (mc_lst->next, sk));__ipv6_sock_mc_drop (sk, mc_lst);return 0 ; }
@@ -333,7 +335,8 @@ void __ipv6_sock_mc_close(struct sock *sk)struct ipv6_mc_socklist *mc_lst;while ((mc_lst =sock_dereference (np->ipv6_mc_list, sk)) !=NULL ) { - np->ipv6_mc_list = mc_lst->next; +rcu_assign_pointer (np->ipv6_mc_list, +sock_dereference (mc_lst->next, sk));__ipv6_sock_mc_drop (sk, mc_lst); } }
@@ -798,9 +801,11 @@ static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)if (!pmc)return ;if (pmc_prev) -rcu_assign_pointer (pmc_prev->next, pmc->next); +rcu_assign_pointer (pmc_prev->next, +mc_dereference (pmc->next, idev));else -rcu_assign_pointer (idev->mc_tomb, pmc->next); +rcu_assign_pointer (idev->mc_tomb, +mc_dereference (pmc->next, idev)); im->idev = pmc->idev;if (im->mca_sfmode ==MCAST_INCLUDE ) {
@@ -979,7 +984,7 @@ static int __ipv6_dev_mc_inc(struct net_device *dev,return -ENOMEM ; } -rcu_assign_pointer (mc->next, idev->mc_list); +rcu_assign_pointer (mc->next,mc_dereference (idev->mc_list, idev));rcu_assign_pointer (idev->mc_list, mc);mld_del_delrec (idev, mc);
@@ -1013,7 +1018,8 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr)WRITE_ONCE (ma->mca_users, new_users);if (new_users ==0 ) { - *map = ma->next; +rcu_assign_pointer (*map, +mc_dereference (ma->next, idev));igmp6_group_dropped (ma); inet6_ifmcaddr_notify(idev->dev, ma,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 524/621 net: stmmac: fix dma mapping leak in stmmac_tso_xmit()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit a5d946466a95621fa2769720d59ea336003aa1a5 ]
In stmmac_tso_xmit(), if the DMA mapping of an skb fragment fails, the frame is dropped but the DMA mappings already created for the linear part and for the fragments mapped before the failure are never unmapped, leaking DMA mappings.
Fix the leak by walking back over the descriptors used by the frame and releasing each of them with stmmac_free_tx_buffer(). Moreover, release the descriptors with stmmac_release_tx_desc() unmapping the DMA buffers.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +43 -24
@@ -4100,6 +4100,7 @@ static bool stmmac_vlan_insert(struct stmmac_priv *priv, struct sk_buff *skb,/** * stmmac_tso_allocator - close entry point of the driver * @priv: driver private structure +* @entry: TX queue buffer index * @des: buffer start address * @total_len: total length to fill in descriptors * @last_segment: condition for the last descriptor
@@ -4108,8 +4109,9 @@ static bool stmmac_vlan_insert(struct stmmac_priv *priv, struct sk_buff *skb,* This function fills descriptor and request new descriptors according to * buffer length to fill */ -static void stmmac_tso_allocator (struct stmmac_priv *priv,dma_addr_t des, -int total_len,bool last_segment,u32 queue) +static void stmmac_tso_allocator (struct stmmac_priv *priv,u32 *entry, +dma_addr_t des,int total_len, +bool last_segment,u32 queue) {struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];struct dma_desc *desc;
@@ -4121,14 +4123,13 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, dma_addr_t des,while (tmp_len >0 ) {dma_addr_t curr_addr; - tx_q->cur_tx =STMMAC_NEXT_ENTRY (tx_q->cur_tx, - priv->dma_conf.dma_tx_size); -WARN_ON (tx_q->tx_skbuff[tx_q->cur_tx]); + *entry =STMMAC_NEXT_ENTRY (*entry, priv->dma_conf.dma_tx_size); +WARN_ON (tx_q->tx_skbuff[*entry]);if (tx_q->tbs &STMMAC_TBS_AVAIL ) - desc = &tx_q->dma_entx[tx_q->cur_tx].basic; + desc = &tx_q->dma_entx[*entry].basic;else - desc = &tx_q->dma_tx[tx_q->cur_tx]; + desc = &tx_q->dma_tx[*entry]; curr_addr = des + (total_len - tmp_len);stmmac_set_desc_addr (priv, desc, curr_addr);
@@ -4253,7 +4254,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) {struct dma_desc *desc, *first, *mss_desc =NULL ;struct stmmac_priv *priv =netdev_priv (dev); -unsigned int first_entry, tx_packets; +unsigned int first_entry, entry, tx_packets;struct stmmac_txq_stats *txq_stats;int i, first_tx, nfrags, ndesc;struct stmmac_tx_queue *tx_q;
@@ -4328,22 +4329,24 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) } first_entry = tx_q->cur_tx; -WARN_ON (tx_q->tx_skbuff[first_entry]); + entry = first_entry; + +WARN_ON (tx_q->tx_skbuff[entry]);if (tx_q->tbs &STMMAC_TBS_AVAIL ) - desc = &tx_q->dma_entx[first_entry].basic; + desc = &tx_q->dma_entx[entry].basic;else - desc = &tx_q->dma_tx[first_entry]; + desc = &tx_q->dma_tx[entry]; first = desc;/* first descriptor: fill Headers on Buf1 */ des =dma_map_single (priv->device, skb->data,skb_headlen (skb),DMA_TO_DEVICE );if (dma_mapping_error (priv->device, des)) - goto dma_map_err; + goto error;stmmac_set_desc_addr (priv, first, des); -stmmac_tso_allocator (priv, des + proto_hdr_len, pay_len, +stmmac_tso_allocator (priv, &entry, des + proto_hdr_len, pay_len, (nfrags ==0 ), queue);/* In case two or more DMA transmit descriptors are allocated for this
@@ -4358,10 +4361,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)* this DMA buffer right after the DMA engine completely finishes the * full buffer transmission. */ - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; - tx_q->tx_skbuff_dma[tx_q->cur_tx].len =skb_headlen (skb); - tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = false; - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf_type =STMMAC_TXBUF_T_SKB ; + tx_q->tx_skbuff_dma[entry].buf = des; + tx_q->tx_skbuff_dma[entry].len =skb_headlen (skb); + tx_q->tx_skbuff_dma[entry].map_as_page = false; + tx_q->tx_skbuff_dma[entry].buf_type =STMMAC_TXBUF_T_SKB ;/* Prepare fragments */ for (i =0 ; i < nfrags; i++) {
@@ -4371,16 +4374,17 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)skb_frag_size (frag), DMA_TO_DEVICE);if (dma_mapping_error (priv->device, des)) - goto dma_map_err; + goto error_dma_unmap; -stmmac_tso_allocator (priv, des,skb_frag_size (frag), +stmmac_tso_allocator (priv, &entry, des,skb_frag_size (frag), (i == nfrags -1 ), queue); - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; - tx_q->tx_skbuff_dma[tx_q->cur_tx].len =skb_frag_size (frag); - tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = true; - tx_q->tx_skbuff_dma[tx_q->cur_tx].buf_type =STMMAC_TXBUF_T_SKB ; + tx_q->tx_skbuff_dma[entry].buf = des; + tx_q->tx_skbuff_dma[entry].len =skb_frag_size (frag); + tx_q->tx_skbuff_dma[entry].map_as_page = true; + tx_q->tx_skbuff_dma[entry].buf_type =STMMAC_TXBUF_T_SKB ; } + tx_q->cur_tx = entry; tx_q->tx_skbuff_dma[tx_q->cur_tx].last_segment = true;
@@ -4477,7 +4481,22 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; -dma_map_err: +error_dma_unmap: +for (;;) { +if (tx_q->tbs &STMMAC_TBS_AVAIL ) + desc = &tx_q->dma_entx[first_entry].basic; +else + desc = &tx_q->dma_tx[first_entry]; +stmmac_release_tx_desc (priv, desc, priv->mode); +stmmac_free_tx_buffer (priv, &priv->dma_conf, queue, + first_entry); +if (first_entry == entry) +break ; + + first_entry =STMMAC_NEXT_ENTRY (first_entry, + priv->dma_conf.dma_tx_size); + } +error:dev_err (priv->device,"Tx dma map failed\n" );dev_kfree_skb (skb); priv->xstats.tx_dropped++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 525/621 bpf: check_cond_jmp_op(): properly infer if register is null
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit d3ef6c097ba078e1f8c7239d76a0ce8b61e75095 ]
Nicholas Carlini reported a bug when verifier can incorrectly infer that a pointer is non-null. The bug occurs when two pointers are compared and one of them has a type w/o PTR_MAYBE_NULL flag, but which allows a value to be NULL at runtime.
Here is an example:
// `a` is PTR_TO_MEM | MEM_RDONLY | PTR_UNTRUSTED // `a` is 0 at runtime. // `b` is PTR_TO_MAP_VALUE | PTR_MAYBE_NULL void *a = bpf_rdonly_cast(0, 0); int *b = bpf_map_lookup_elem(...);
if (a == b)
*b = 42; // verifier does not catch null pointer dereference
This happens because of a special case in check_cond_jmp_op(), which attempts to strip PTR_MAYBE_NULL flags from pointer types, when processing comparisons like rA == rB, if either rA or rB can't be null.
The non-null property is derived based on the absence of PTR_MAYBE_NULL flag on rA's or rB's type. But that is not sufficient for types like PTR_TO_MEM, as in the example.
This patch replaces type_may_be_null() call with reg_not_null(), which contains an allowlist of types for which absence of PTR_MAYBE_NULL actually means that the value can't be NULL at runtime.
At the moment, the list in the reg_not_null() omits two types for which PTR_MAYBE_NULL is applicable: PTR_TO_XDP_SOCK and PTR_TO_BUF. In order to remain backward compatible, and assuming that only comparison between pointers of the same type makes sense, this commit extends reg_not_null(). W/o such an extension e.g. verifier_jeq_infer_not_null/null_ptr_to_map_value fails.
reg_not_null() can be extended further, but I deem that out of scope for the fix at hand. Explicit base_type(...) != PTR_TO_BTF_ID checks in the check_cond_jmp_op() can be removed with migration to reg_not_null(), but that is a behavioural change, as the special case would start matching for PTR_TO_BTF_ID that is also is_trusted_reg(). I omit the behavioural change from this commit.
--- kernel/bpf/verifier.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +6 -3
@@ -415,6 +415,8 @@ static bool reg_not_null(const struct bpf_reg_state *reg) type =base_type (type);return type ==PTR_TO_SOCKET || type ==PTR_TO_TCP_SOCK || + type ==PTR_TO_XDP_SOCK || + type ==PTR_TO_BUF || type ==PTR_TO_MAP_VALUE || type ==PTR_TO_MAP_KEY || type == PTR_TO_SOCK_COMMON ||
@@ -17428,7 +17430,6 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,*/ if (!is_jmp32 &&BPF_SRC (insn->code) ==BPF_X &&__is_pointer_value (false, src_reg) &&__is_pointer_value (false, dst_reg) && -type_may_be_null (src_reg->type) !=type_may_be_null (dst_reg->type) &&base_type (src_reg->type) !=PTR_TO_BTF_ID &&base_type (dst_reg->type) !=PTR_TO_BTF_ID ) { eq_branch_regs =NULL ;
@@ -17444,9 +17445,11 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,break ; }if (eq_branch_regs) { -if (type_may_be_null (src_reg->type)) +/* src == dst && dst != NULL => src != NULL */ +if (reg_not_null (dst_reg) &&type_may_be_null (src_reg->type))mark_ptr_not_null_reg (&eq_branch_regs[insn->src_reg]); -else +/* src == dst && src != NULL => dst != NULL */ +if (reg_not_null (src_reg) &&type_may_be_null (dst_reg->type))mark_ptr_not_null_reg (&eq_branch_regs[insn->dst_reg]); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 526/621 printk: Dont WARN on kthread_run failure.
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
[ Upstream commit 72dd0ec09e7cc98ed58ddeac26575e5d1ab8a93d ]
Since __kthread_create_on_node() returns -EINTR upon SIGKILL, we should not use WARN_ON() in order to catch kthread_run() failure.
--- kernel/printk/nbcon.c | 2 +- kernel/printk/printk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/printk/nbcon.c +1 -1
@@ -1340,7 +1340,7 @@ bool nbcon_kthread_create(struct console *con)return true; kt =kthread_run (nbcon_kthread_func, con,"pr/%s%d" , con->name, con->index); -if (WARN_ON (IS_ERR (kt))) { +if (IS_ERR (kt)) {con_printk (KERN_ERR , con,"failed to start printing thread\n" );return false; }
kernel/printk/printk.c +1 -1
@@ -3689,7 +3689,7 @@ static bool legacy_kthread_create(void)lockdep_assert_console_list_lock_held (); kt =kthread_run (legacy_kthread_func,NULL ,"pr/legacy" ); -if (WARN_ON (IS_ERR (kt))) { +if (IS_ERR (kt)) {pr_err ("failed to start legacy printing thread\n" );return false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 527/621 ksmbd: convert tree_conns_lock to rw_semaphore
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 31b9028c77dc279d720412013e95b279b1385aed ]
Converts tree_conns_lock to an rw_semaphore to allow sleeping while the lock is held. Additionally, it simplifies the locking logic in ksmbd_tree_conn_session_logoff() and introduces __ksmbd_tree_conn_disconnect() to avoid redundant locking.
Stable-dep-of: 39f203209671 ("smb/server: fix tree connection leak in smb2_tree_connect()")
--- fs/smb/server/mgmt/tree_connect.c | 33 ++++++++++++++++++++----------- fs/smb/server/mgmt/user_session.c | 2 +- fs/smb/server/mgmt/user_session.h | 2 +- fs/smb/server/smb2pdu.c | 10 +++++----- 4 files changed, 28 insertions(+), 19 deletions(-)
fs/smb/server/mgmt/tree_connect.c +21 -12
@@ -79,8 +79,10 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name) status.tree_conn = tree_conn;atomic_set (&tree_conn->refcount,1 ); +down_write (&sess->tree_conns_lock); ret =xa_err (xa_store (&sess->tree_conns, tree_conn->id, tree_conn,KSMBD_DEFAULT_GFP )); +up_write (&sess->tree_conns_lock);if (ret) { status.ret = -ENOMEM ; goto out_error;
@@ -103,15 +105,11 @@ void ksmbd_tree_connect_put(struct ksmbd_tree_connect *tcon)kfree (tcon); } -int ksmbd_tree_conn_disconnect (struct ksmbd_session *sess, -struct ksmbd_tree_connect *tree_conn) +static int __ksmbd_tree_conn_disconnect (struct ksmbd_session *sess, +struct ksmbd_tree_connect *tree_conn) {int ret; -write_lock (&sess->tree_conns_lock); -xa_erase (&sess->tree_conns, tree_conn->id); -write_unlock (&sess->tree_conns_lock); - ret =ksmbd_ipc_tree_disconnect_request (sess->id, tree_conn->id);ksmbd_release_tree_conn_id (sess, tree_conn->id);ksmbd_share_config_put (tree_conn->share_conf);
@@ -120,12 +118,22 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,return ret; } +int ksmbd_tree_conn_disconnect (struct ksmbd_session *sess, +struct ksmbd_tree_connect *tree_conn) +{ +down_write (&sess->tree_conns_lock); +xa_erase (&sess->tree_conns, tree_conn->id); +up_write (&sess->tree_conns_lock); + +return __ksmbd_tree_conn_disconnect (sess, tree_conn); +} +struct ksmbd_tree_connect *ksmbd_tree_conn_lookup (struct ksmbd_session *sess,unsigned int id) {struct ksmbd_tree_connect *tcon; -read_lock (&sess->tree_conns_lock); +down_read (&sess->tree_conns_lock); tcon =xa_load (&sess->tree_conns, id);if (tcon) {if (tcon->t_state !=TREE_CONNECTED )
@@ -133,7 +141,7 @@ struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess,else if (!atomic_inc_not_zero (&tcon->refcount)) tcon =NULL ; } -read_unlock (&sess->tree_conns_lock); +up_read (&sess->tree_conns_lock);return tcon; }
@@ -147,18 +155,19 @@ int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess)if (!sess)return -EINVAL ; +down_write (&sess->tree_conns_lock);xa_for_each (&sess->tree_conns, id, tc) { -write_lock (&sess->tree_conns_lock);if (tc->t_state ==TREE_DISCONNECTED ) { -write_unlock (&sess->tree_conns_lock); ret = -ENOENT ;continue ; } tc->t_state =TREE_DISCONNECTED ; -write_unlock (&sess->tree_conns_lock); - ret |=ksmbd_tree_conn_disconnect (sess, tc); +xa_erase (&sess->tree_conns, tc->id); + ret |=__ksmbd_tree_conn_disconnect (sess, tc); }xa_destroy (&sess->tree_conns); +up_write (&sess->tree_conns_lock); +return ret; }
fs/smb/server/mgmt/user_session.c +1 -1
@@ -481,8 +481,8 @@ static struct ksmbd_session *__session_create(int protocol)xa_init (&sess->ksmbd_chann_list);xa_init (&sess->rpc_handle_list); sess->sequence_number =1 ; -rwlock_init (&sess->tree_conns_lock);atomic_set (&sess->refcnt,2 ); +init_rwsem (&sess->tree_conns_lock);init_rwsem (&sess->rpc_lock);init_rwsem (&sess->chann_lock);
fs/smb/server/mgmt/user_session.h +1 -1
@@ -61,7 +61,7 @@ struct ksmbd_session {struct ksmbd_file_table file_table;unsigned long last_active; -rwlock_t tree_conns_lock; +struct rw_semaphore tree_conns_lock;atomic_t refcnt;struct rw_semaphore rpc_lock;
fs/smb/server/smb2pdu.c +5 -5
@@ -2051,9 +2051,9 @@ int smb2_tree_connect(struct ksmbd_work *work)if (conn->posix_ext_supported) status.tree_conn->posix_extensions = true; -write_lock (&sess->tree_conns_lock); +down_write (&sess->tree_conns_lock); status.tree_conn->t_state =TREE_CONNECTED ; -write_unlock (&sess->tree_conns_lock); +up_write (&sess->tree_conns_lock); rsp->StructureSize =cpu_to_le16 (16 ); out_err1:/*
@@ -2206,16 +2206,16 @@ int smb2_tree_disconnect(struct ksmbd_work *work)ksmbd_close_tree_conn_fds (work); -write_lock (&sess->tree_conns_lock); +down_write (&sess->tree_conns_lock);if (tcon->t_state ==TREE_DISCONNECTED ) { -write_unlock (&sess->tree_conns_lock); +up_write (&sess->tree_conns_lock); rsp->hdr.Status =STATUS_NETWORK_NAME_DELETED ; err = -ENOENT ; goto err_out; } tcon->t_state =TREE_DISCONNECTED ; -write_unlock (&sess->tree_conns_lock); +up_write (&sess->tree_conns_lock); err =ksmbd_tree_conn_disconnect (sess, tcon);if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 528/621 smb/server: fix tree connection leak in smb2_tree_connect()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ze Tan <[email protected]>
[ Upstream commit 39f2032096715daae5f6fd0f587ca7a474b019df ]
See the procedure below:
smb2_tree_connect
ksmbd_tree_conn_connect
xa_store(&sess->tree_conns, tree_conn->id, tree_conn) ksmbd_counter_inc(KSMBD_COUNTER_TREE_CONNS) ksmbd_share_tree_conn_inc(sc)
ksmbd_iov_pin_rsp // fail
status.ret = KSMBD_TREE_CONN_STATUS_NOMEM
// do not disconnect tree_conn
Disconnect the new tree connection if ksmbd_iov_pin_rsp() fails.
--- fs/smb/server/smb2pdu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +9 -1
@@ -2066,8 +2066,16 @@ int smb2_tree_connect(struct ksmbd_work *work) rsp->ShareFlags =SMB2_SHAREFLAG_MANUAL_CACHING ; rc =ksmbd_iov_pin_rsp (work, rsp,sizeof (struct smb2_tree_connect_rsp )); -if (rc) +if (rc) { +if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) { +down_write (&sess->tree_conns_lock); + status.tree_conn->t_state =TREE_DISCONNECTED ; +up_write (&sess->tree_conns_lock); +ksmbd_tree_conn_disconnect (sess, status.tree_conn); + status.tree_conn =NULL ; + } status.ret =KSMBD_TREE_CONN_STATUS_NOMEM ; + }if (!IS_ERR (treename))kfree (treename);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 487/621 uprobes/x86: Move optimized uprobe from nop5 to nop10
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Olsa <[email protected]>
[ Upstream commit 554ba38456dad8053a1a80afe6ae6da9eff745cc ]
Andrii reported an issue with optimized uprobes [1] that can clobber redzone area with call instruction storing return address on stack where user code may keep temporary data without adjusting rsp.
Fixing this by moving the optimized uprobes on top of 10-bytes nop instruction, so we can squeeze another instruction to escape the redzone area before doing the call, like:
lea -0x80(%rsp), %rsp
call tramp
Note the lea instruction is used to adjust the rsp register without changing the flags.
We use nop10 and following transformation to optimized instructions above and back as suggested by Peterz [2].
Optimize path (int3_update_optimize):
1) Initial state after set_swbp() installed the uprobe:
cc 2e 0f 1f 84 00 00 00 00 00
From offset 0 this is INT3 followed by the tail of the original 10-byte NOP.
After a previous unoptimization bytes 5..9 may still contain the old call instruction, which remains valid for threads already there.
2) Rewrite the LEA tail and call displacement:
cc [8d 64 24 80 e8 d0 d1 d2 d3]
From offset 0 this traps on the uprobe INT3. Bytes 1..9 are not executable entry points while byte 0 is trapped.
3) Publish the first LEA byte:
[48] 8d 64 24 80 e8 d0 d1 d2 d3
From offset 0 this is:
lea -0x80(%rsp), %rsp
call <uprobe-trampoline>Unoptimize path (int3_update_unoptimize):
1) Initial optimized state:
48 8d 64 24 80 e8 d0 d1 d2 d3
Same as 3) above.
2) Trap new entries before restoring the NOP bytes:
[cc] 8d 64 24 80 e8 d0 d1 d2 d3
From offset 0 this traps. A thread that had already executed the LEA can still reach the intact CALL at offset 5.
3) Restore bytes 1..4 of the original NOP while keeping byte 0 trapped and byte 5 as CALL.
cc [2e 0f 1f 84] e8 d0 d1 d2 d3
From offset 0 this still traps. Offset 5 is still the CALL for any thread that was already past the first LEA byte.
4) Publish the first byte of the original NOP:
[66] 2e 0f 1f 84 e8 d0 d1 d2 d3
From offset 0 this is the restored 10-byte NOP; the CALL opcode and displacement are now only NOP operands. Offset 5 still decodes as CALL for a thread that was already there.
Tthere is only a single target uprobe-trampoline for the given nop10 instruction address, so the CALL instruction will not be changed across unoptimization/optimization cycles.
Therefore, any task that is preempted at the CALL instruction is guaranteed to observe that CALL and not anything else.
Note as explained in [2] we need to use following nop10:
PF1 PF2 ESC NOPL MOD SIB DISP32
NOP10: 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 -- cs nopw 0x00000000(%rax,%rax,1)
which means we need to allow 0x2e prefix which maps to INAT_PFX_CS attribute in is_prefix_bad function.
Also changing the uprobe syscall error when called out of uprobe trampoline to -EPROTO, so we are able to detect the fixed kernel.
The optimized uprobe performance stays the same:
uprobe-nop : 3.129 ± 0.013M/s
uprobe-push : 3.045 ± 0.006M/s
uprobe-ret : 1.095 ± 0.004M/s
--> uprobe-nop10 : 7.170 ± 0.020M/s
uretprobe-nop : 2.143 ± 0.021M/s
uretprobe-push : 2.090 ± 0.000M/s
uretprobe-ret : 0.942 ± 0.000M/s
--> uretprobe-nop10: 3.381 ± 0.003M/s
usdt-nop : 3.245 ± 0.004M/s
--> usdt-nop10 : 7.256 ± 0.023M/s[1] https://lore.kernel.org/bpf/[email protected]/
[2] https://lore.kernel.org/bpf/[email protected]/#t
--- arch/x86/kernel/uprobes.c | 292 ++++++++++++++++++++++++++++---------- 1 file changed, 216 insertions(+), 76 deletions(-)
arch/x86/kernel/uprobes.c +216 -76
@@ -276,15 +276,9 @@ static bool is_prefix_bad(struct insn *insn)return false; } -static int uprobe_init_insn (struct arch_uprobe *auprobe,struct insn *insn,bool x86_64) +static int uprobe_init_insn (struct arch_uprobe *auprobe,struct insn *insn) { -enum insn_mode m = x86_64 ?INSN_MODE_64 :INSN_MODE_32 ;u32 volatile *good_insns; -int ret; - - ret =insn_decode (insn, auprobe->insn,sizeof (auprobe->insn), m); -if (ret <0 ) -return -ENOEXEC ;if (is_prefix_bad (insn))return -ENOTSUPP ;
@@ -293,7 +287,7 @@ static int uprobe_init_insn(struct arch_uprobe *auprobe, struct insn *insn, boolif (insn_masking_exception (insn))return -ENOTSUPP ; -if (x86_64) +if (insn->x86_64) good_insns = good_insns_64;else good_insns = good_insns_32;
@@ -636,9 +630,29 @@ struct uprobe_trampoline {unsigned long vaddr; }; + +#define LEA_INSN_SIZE 5 +#define OPT_INSN_SIZE (LEA_INSN_SIZE + CALL_INSN_SIZE) +#define REDZONE_SIZE 0x80 + +static const u8 lea_rsp[] = {0x48 ,0x8d ,0x64 ,0x24 ,0x80 }; + +static bool is_opt_insns (const uprobe_opcode_t *insn) +{ +return !memcmp (insn, lea_rsp,LEA_INSN_SIZE ) && + insn[LEA_INSN_SIZE ] ==CALL_INSN_OPCODE ; +} + +static bool is_swbp_opt_insns (uprobe_opcode_t *insn) +{ +return is_swbp_insn (&insn[0 ]) && + !memcmp (&insn[1 ], &lea_rsp[1 ],LEA_INSN_SIZE -1 ) && + insn[LEA_INSN_SIZE ] ==CALL_INSN_OPCODE ; +} +static bool is_reachable_by_call (unsigned long vtramp,unsigned long vaddr) { -long delta = (long )(vaddr +5 - vtramp); +long delta = (long )(vaddr +OPT_INSN_SIZE - vtramp);return delta >=INT_MIN && delta <=INT_MAX ; }
@@ -651,7 +665,7 @@ static unsigned long find_nearest_trampoline(unsigned long vaddr) };unsigned long low_limit, high_limit;unsigned long low_tramp, high_tramp; -unsigned long call_end = vaddr +5 ; +unsigned long call_end = vaddr +OPT_INSN_SIZE ;if (check_add_overflow (call_end,INT_MIN , &low_limit)) low_limit =PAGE_SIZE ;
@@ -810,7 +824,7 @@ SYSCALL_DEFINE0(uprobe)/* Allow execution only from uprobe trampolines. */ if (!in_uprobe_trampoline (regs->ip)) -return -ENXIO ; +return -EPROTO ; err =copy_from_user (&args, (void __user *)regs->sp,sizeof (args));if (err)
@@ -826,8 +840,8 @@ SYSCALL_DEFINE0(uprobe) regs->ax = args.ax; regs->r11 = args.r11; regs->cx = args.cx; - regs->ip = args.retaddr -5 ; - regs->sp +=sizeof (args); + regs->ip = args.retaddr -OPT_INSN_SIZE ; + regs->sp +=sizeof (args) +REDZONE_SIZE ; regs->orig_ax =-1 ; sp = regs->sp;
@@ -844,12 +858,12 @@ SYSCALL_DEFINE0(uprobe)*/ if (regs->sp != sp) {/* skip the trampoline call */ -if (args.retaddr -5 == regs->ip) - regs->ip +=5 ; +if (args.retaddr -OPT_INSN_SIZE == regs->ip) + regs->ip +=OPT_INSN_SIZE ;return regs->ax; } - regs->sp -=sizeof (args); + regs->sp -=sizeof (args) +REDZONE_SIZE ;/* for the case uprobe_consumer has changed ax/r11/cx */ args.ax = regs->ax;
@@ -857,7 +871,7 @@ SYSCALL_DEFINE0(uprobe) args.cx = regs->cx;/* keep return address unless we are instructed otherwise */ -if (args.retaddr -5 != regs->ip) +if (args.retaddr -OPT_INSN_SIZE != regs->ip) args.retaddr = regs->ip;if (shstk_push (args.retaddr) == -EFAULT )
@@ -891,7 +905,7 @@ asm ("pop %rax\n" "pop %r11\n" "pop %rcx\n" -"ret\n" + "ret $" __stringify(REDZONE_SIZE) "\n""int3\n" ".balign " __stringify(PAGE_SIZE) "\n"".popsection\n"
@@ -909,7 +923,8 @@ late_initcall(arch_uprobes_init);enum {EXPECT_SWBP , -EXPECT_CALL , +EXPECT_OPTIMIZED , +EXPECT_SWBP_OPTIMIZED , };struct write_opcode_ctx {
@@ -917,30 +932,29 @@ struct write_opcode_ctx {int expect; }; -static int is_call_insn (uprobe_opcode_t *insn) -{ -return *insn ==CALL_INSN_OPCODE ; -} -/* -* Verification callback used by int3_update uprobe_write calls to make sure -* the underlying instruction is as expected - either int3 or call. +* Verification callback used by uprobe_write calls to make sure the underlying +* instruction is in the expected stage of the INT3 update sequence. */ static int verify_insn (struct page *page,unsigned long vaddr,uprobe_opcode_t *new_opcode,int nbytes,void *data) {struct write_opcode_ctx *ctx = data; -uprobe_opcode_t old_opcode[5 ]; +uprobe_opcode_t old_opcode[OPT_INSN_SIZE ]; -uprobe_copy_from_page (page, ctx->base, (uprobe_opcode_t *) &old_opcode,5 ); +uprobe_copy_from_page (page, ctx->base, old_opcode,OPT_INSN_SIZE );switch (ctx->expect) {case EXPECT_SWBP :if (is_swbp_insn (&old_opcode[0 ]))return 1 ;break ; -case EXPECT_CALL : -if (is_call_insn (&old_opcode[0 ])) +case EXPECT_OPTIMIZED : +if (is_opt_insns (&old_opcode[0 ])) +return 1 ; +break ; +case EXPECT_SWBP_OPTIMIZED : +if (is_swbp_opt_insns (&old_opcode[0 ]))return 1 ;break ; }
@@ -949,48 +963,122 @@ static int verify_insn(struct page *page, unsigned long vaddr, uprobe_opcode_t * }/* -* Modify multi-byte instructions by using INT3 breakpoints on SMP. +* Modify the optimized instruction by using INT3 breakpoints on SMP. * We completely avoid using stop_machine() here, and achieve the * synchronization using INT3 breakpoints and SMP cross-calls. * (borrowed comment from smp_text_poke_batch_finish) * -* The way it is done: -* - Add an INT3 trap to the address that will be patched -* - SMP sync all CPUs -* - Update all but the first byte of the patched range -* - SMP sync all CPUs -* - Replace the first byte (INT3) by the first byte of the replacing opcode -* - SMP sync all CPUs +* For optimization (int3_update_optimize): +* 1) Start with the uprobe INT3 trap already installed +* 2) Update everything but the first byte +* 3) Replace the first INT3 by the first byte of the LEA instruction +* +* For unoptimization (int3_update_unoptimize): +* 1) Start with the optimized uprobe lea/call instructions +* 2) Add an INT3 trap to the address that will be patched +* 3) Restore the NOP bytes before the call opcode +* 4) Replace the first INT3 by the first byte of the NOP instruction +* +* Note that unoptimization deliberately keeps the call opcode and displacement +* in bytes 5..9. Those bytes become operands of the restored 10-byte NOP. +* +* Since there is only a single target uprobe-trampoline for the given nop10 +* instruction address, the CALL instruction will not be changed across +* unoptimization/optimization cycles. +* Therefore, any task that is preempted at the CALL instruction is guaranteed +* to observe that CALL and not anything else. */ -static int int3_update (struct arch_uprobe *auprobe,struct vm_area_struct *vma, -unsigned long vaddr,char *insn,bool optimize) +static int int3_update_optimize (struct arch_uprobe *auprobe,struct vm_area_struct *vma, +unsigned long vaddr,uprobe_opcode_t *insn) { -uprobe_opcode_t int3 =UPROBE_SWBP_INSN ;struct write_opcode_ctx ctx = { .base = vaddr, };int err;/* -* Write int3 trap. +* 1) Initial state after set_swbp() installed the uprobe: +* cc 2e 0f 1f 84 00 00 00 00 00 * -* The swbp_optimize path comes with breakpoint already installed, -* so we can skip this step for optimize == true. +* After a previous unoptimization bytes 5..9 may still contain the +* old call instruction, which remains valid for threads already there. */ -if (!optimize) { - ctx.expect =EXPECT_CALL ; - err =uprobe_write (auprobe, vma, vaddr, &int3,1 , verify_insn, - true/* is_register */ , false/* do_update_ref_ctr */ , - &ctx); -if (err) -return err; - } +smp_text_poke_sync_each_cpu (); + +/* +* 2) Rewrite the LEA tail and call displacement: +* cc [8d 64 24 80 e8 d0 d1 d2 d3] +*/ + ctx.expect =EXPECT_SWBP ; + err =uprobe_write (auprobe, vma, vaddr +1 , insn +1 , +OPT_INSN_SIZE -1 , verify_insn, + true/* is_register */ , false/* do_update_ref_ctr */ , + &ctx); +if (err) +return err; + +smp_text_poke_sync_each_cpu (); + +/* +* 3) Publish the first LEA byte: +* [48] 8d 64 24 80 e8 d0 d1 d2 d3 +* +* From offset 0 this is: +* lea -0x80(%rsp), %rsp +* call <uprobe-trampoline> +*/ + ctx.expect =EXPECT_SWBP_OPTIMIZED ; + err =uprobe_write (auprobe, vma, vaddr, insn,1 , verify_insn, + true/* is_register */ , false/* do_update_ref_ctr */ , + &ctx); +if (err) + goto error;smp_text_poke_sync_each_cpu (); +return 0 ; -/* Write all but the first byte of the patched range. */ +error: +/* +* In all intermediate states byte 0 is INT3, so EXPECT_SWBP covers every +* case. Restore NOP bytes 1..4, but keep the valid CALL at bytes 5..9 +* for a thread that had already executed the LEA before a previous +* unoptimization. +*/ ctx.expect =EXPECT_SWBP ; - err =uprobe_write (auprobe, vma, vaddr +1 , insn +1 ,4 , verify_insn, +uprobe_write (auprobe, vma, vaddr +1 , auprobe->insn +1 , +LEA_INSN_SIZE -1 , verify_insn, true, false, &ctx); +smp_text_poke_sync_each_cpu (); +return err; +} + +static int int3_update_unoptimize (struct arch_uprobe *auprobe,struct vm_area_struct *vma, +unsigned long vaddr,uprobe_opcode_t *insn) +{ +uprobe_opcode_t int3 =UPROBE_SWBP_INSN ; +struct write_opcode_ctx ctx = { + .base = vaddr, + .expect =EXPECT_OPTIMIZED , + }; +int err; + +/* +* Note the first two uprobe_write calls use is_register=true, because they +* are intermediate patching states while the probe is still active, so +* we force the exclusive anonymous page for the update. +* Also we use do_update_ref_ctr=false because refctr was already updated by +* the initial int3 install. +* +* The last uprobe_write to nop10 instruction is called with is_register=false +* and do_update_ref_ctr=true to trigger the refctr update and to instruct +* uprobe_write to zap the anonymous page if it now matches the file page. +* +* 1) Initial optimized state: +* 48 8d 64 24 80 e8 d0 d1 d2 d3 +* +* 2) Trap new entries before restoring the NOP bytes: +* [cc] 8d 64 24 80 e8 d0 d1 d2 d3 +*/ + err =uprobe_write (auprobe, vma, vaddr, &int3,1 , verify_insn, true/* is_register */ , false/* do_update_ref_ctr */ , &ctx);if (err)
@@ -999,13 +1087,31 @@ static int int3_update(struct arch_uprobe *auprobe, struct vm_area_struct *vma,smp_text_poke_sync_each_cpu ();/* -* Write first byte. +* 3) Restore bytes 1..4 of the original NOP while keeping byte 0 trapped +* and byte 5 as CALL: +* cc [2e 0f 1f 84] e8 d0 d1 d2 d3 +*/ + ctx.expect =EXPECT_SWBP_OPTIMIZED ; + err =uprobe_write (auprobe, vma, vaddr +1 , insn +1 , +LEA_INSN_SIZE -1 , verify_insn, + true/* is_register */ , false/* do_update_ref_ctr */ , + &ctx); +if (err) +return err; + +smp_text_poke_sync_each_cpu (); + +/* +* 4) Publish the first byte of the original NOP: +* [66] 2e 0f 1f 84 e8 d0 d1 d2 d3 * -* The swbp_unoptimize needs to finish uprobe removal together -* with ref_ctr update, using uprobe_write with proper flags. +* From offset 0 this is the restored 10-byte NOP; the CALL opcode and +* displacement are now only NOP operands. Offset 5 still decodes as +* CALL for a thread that was already there. */ + ctx.expect =EXPECT_SWBP ; err =uprobe_write (auprobe, vma, vaddr, insn,1 , verify_insn, - optimize/* is_register */ , !optimize/* do_update_ref_ctr */ , + false/* is_register */ , true/* do_update_ref_ctr */ , &ctx);if (err)return err;
@@ -1017,17 +1123,25 @@ static int int3_update(struct arch_uprobe *auprobe, struct vm_area_struct *vma,static int swbp_optimize (struct arch_uprobe *auprobe,struct vm_area_struct *vma,unsigned long vaddr,unsigned long tramp) { -u8 call[5 ]; +u8 insn[OPT_INSN_SIZE ], *call = &insn[LEA_INSN_SIZE ]; -__text_gen_insn (call,CALL_INSN_OPCODE , (const void *) vaddr, +/* +* We have nop10 instruction (with first byte overwritten to int3), +* changing it to: +* lea -0x80(%rsp), %rsp +* call tramp +*/ +memcpy (insn, lea_rsp,LEA_INSN_SIZE ); +__text_gen_insn (call,CALL_INSN_OPCODE , + (const void *) (vaddr +LEA_INSN_SIZE ), (const void *) tramp,CALL_INSN_SIZE ); -return int3_update (auprobe, vma, vaddr, call, true/* optimize */ ); +return int3_update_optimize (auprobe, vma, vaddr, insn); }static int swbp_unoptimize (struct arch_uprobe *auprobe,struct vm_area_struct *vma,unsigned long vaddr) { -return int3_update (auprobe, vma, vaddr, auprobe->insn, false/* optimize */ ); +return int3_update_unoptimize (auprobe, vma, vaddr, auprobe->insn); }static int copy_from_vaddr (struct mm_struct *mm,unsigned long vaddr,void *dst,int len)
@@ -1049,19 +1163,19 @@ static bool __is_optimized(struct mm_struct *mm, uprobe_opcode_t *insn, unsignedstruct __packed __arch_relative_insn {u8 op;s32 raddr; - } *call = (struct __arch_relative_insn *) insn; + } *call = (struct __arch_relative_insn *)(insn +LEA_INSN_SIZE ); -if (!is_call_insn (insn)) +if (!is_opt_insns (insn))return false; -return __in_uprobe_trampoline (mm, vaddr +5 + call->raddr); +return __in_uprobe_trampoline (mm, vaddr +OPT_INSN_SIZE + call->raddr); }static int is_optimized (struct mm_struct *mm,unsigned long vaddr) { -uprobe_opcode_t insn[5 ]; +uprobe_opcode_t insn[OPT_INSN_SIZE ];int err; - err =copy_from_vaddr (mm, vaddr, &insn,5 ); + err =copy_from_vaddr (mm, vaddr, &insn,OPT_INSN_SIZE );if (err)return err;return __is_optimized (mm, (uprobe_opcode_t *)&insn, vaddr);
@@ -1131,7 +1245,7 @@ static int __arch_uprobe_optimize(struct arch_uprobe *auprobe, struct mm_structvoid arch_uprobe_optimize (struct arch_uprobe *auprobe,unsigned long vaddr) {struct mm_struct *mm = current->mm; -uprobe_opcode_t insn[5 ]; +uprobe_opcode_t insn[OPT_INSN_SIZE ];if (!should_optimize (auprobe))return ;
@@ -1142,7 +1256,7 @@ void arch_uprobe_optimize(struct arch_uprobe *auprobe, unsigned long vaddr)* Check if some other thread already optimized the uprobe for us, * if it's the case just go away silently. */ -if (copy_from_vaddr (mm, vaddr, &insn,5 )) +if (copy_from_vaddr (mm, vaddr, &insn,OPT_INSN_SIZE )) goto unlock;if (!is_swbp_insn ((uprobe_opcode_t *) &insn)) goto unlock;
@@ -1181,16 +1295,32 @@ static bool insn_is_nopl(struct insn *insn) return true; } +static bool is_optimizable_nop10 (struct insn *insn) +{ +static const u8 nop10_prefix[] = { +0x66 ,0x2e ,0x0f ,0x1f ,0x84 + }; + +/* +* Restrict this to the 10-byte NOP form whose last 5 bytes are +* SIB/displacement operands. Unoptimization keeps the call opcode and +* displacement in those bytes, so other NOP encodings are not safe. +*/ +return insn->length ==OPT_INSN_SIZE && + (insn_is_nop (insn) ||insn_is_nopl (insn)) && + !memcmp (insn->kaddr, nop10_prefix,ARRAY_SIZE (nop10_prefix)); +} +static bool can_optimize (struct insn *insn,unsigned long vaddr) { -if (!insn->x86_64 || insn->length !=5 ) +if (!insn->x86_64)return false; -if (!insn_is_nop (insn) && !insn_is_nopl (insn)) +if (!is_optimizable_nop10 (insn))return false;/* We can't do cross page atomic writes yet. */ -return PAGE_SIZE - (vaddr & ~PAGE_MASK ) >=5 ; +return PAGE_SIZE - (vaddr & ~PAGE_MASK ) >=OPT_INSN_SIZE ; }#else /* 32-bit: */ /*
@@ -1577,16 +1707,26 @@ static int push_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)*/ int arch_uprobe_analyze_insn (struct arch_uprobe *auprobe,struct mm_struct *mm,unsigned long addr) { +enum insn_mode m =is_64bit_mm (mm) ?INSN_MODE_64 :INSN_MODE_32 ;u8 fix_ip_or_call =UPROBE_FIX_IP ;struct insn insn;int ret; - ret =uprobe_init_insn (auprobe, &insn,is_64bit_mm (mm)); -if (ret) -return ret; + ret =insn_decode (&insn, auprobe->insn,sizeof (auprobe->insn), m); +if (ret <0 ) +return -ENOEXEC ; -if (can_optimize (&insn, addr)) +/* +* No need to check instruction in uprobe_init_insn in case we +* are on top of optimizable nop10. +*/ +if (can_optimize (&insn, addr)) {set_bit (ARCH_UPROBE_FLAG_CAN_OPTIMIZE , &auprobe->flags); + }else { + ret =uprobe_init_insn (auprobe, &insn); +if (ret) +return ret; + } ret =branch_setup_xol_ops (auprobe, &insn);if (ret != -ENOSYS )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 488/621 dmaengine: xilinx_dma: Fix CPU stall in xilinx_dma_poll_timeout
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Bereza <[email protected]>
[ Upstream commit aa99c4d1d63bbc26a5fc4c667d89b2595743c19d ]
Currently when calling xilinx_dma_poll_timeout with delay_us=0 and a condition that is never fulfilled, the CPU busy-waits for prolonged time and the timeout triggers only with a massive delay causing a CPU stall.
This happens due to a huge underestimation of wall clock time in poll_timeout_us_atomic. Commit 7349a69cf312 ("iopoll: Do not use timekeeping in read_poll_timeout_atomic()") changed the behavior to no longer use ktime_get at the expense of underestimation of wall clock time which appears to be very large for delay_us=0. Instead of timing out after approximately XILINX_DMA_LOOP_COUNT microseconds, the timeout takes XILINX_DMA_LOOP_COUNT * 1000 * (time that the overhead of the for loop in poll_timeout_us_atomic takes) which is in the range of several minutes for XILINX_DMA_LOOP_COUNT=1000000. Fix this by using a non-zero value for delay_us. Use delay_us=10 to keep the delay in the hot path of starting DMA transfers minimal but still avoid CPU stalls in case of unexpected hardware failures.
One-off measurement with delay_us=0 causes the cpu to busy wait around 7 minutes in the timeout case. After applying this patch with delay_us=10 the measured timeout was 1053428 microseconds which is roughly equivalent to the expected 1000000 microseconds specified in XILINX_DMA_LOOP_COUNT.
Add a constant XILINX_DMA_POLL_DELAY_US for delay_us value.
--- drivers/dma/xilinx/xilinx_dma.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +10 -4
@@ -167,6 +167,8 @@/* Delay loop counter to prevent hardware failure */ #define XILINX_DMA_LOOP_COUNT 1000000 +/* Delay between polls (avoid a delay of 0 to prevent CPU stalls) */ +#define XILINX_DMA_POLL_DELAY_US 10/* AXI DMA Specific Registers/Offsets */ #define XILINX_DMA_REG_SRCDSTADDR 0x18
@@ -1316,7 +1318,8 @@ static int xilinx_dma_stop_transfer(struct xilinx_dma_chan *chan)/* Wait for the hardware to halt */ return xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - val &XILINX_DMA_DMASR_HALTED ,0 , + val &XILINX_DMA_DMASR_HALTED , +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT ); }
@@ -1331,7 +1334,8 @@ static int xilinx_cdma_stop_transfer(struct xilinx_dma_chan *chan)u32 val;return xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - val &XILINX_DMA_DMASR_IDLE ,0 , + val &XILINX_DMA_DMASR_IDLE , +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT ); }
@@ -1348,7 +1352,8 @@ static void xilinx_dma_start(struct xilinx_dma_chan *chan)/* Wait for the hardware to start */ err =xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - !(val &XILINX_DMA_DMASR_HALTED ),0 , + !(val &XILINX_DMA_DMASR_HALTED ), +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT );if (err) {
@@ -1783,7 +1788,8 @@ static int xilinx_dma_reset(struct xilinx_dma_chan *chan)/* Wait for the hardware to finish reset */ err =xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMACR , tmp, - !(tmp &XILINX_DMA_DMACR_RESET ),0 , + !(tmp &XILINX_DMA_DMACR_RESET ), +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT );if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 489/621 drm/amd/display: Fix dangling pointer in CRTC reset function
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Evgenii Burenchev <[email protected]>
[ Upstream commit 0aeed866cb938943908c3ba46422128e49d2d080 ]
amdgpu_dm_crtc_reset_state() frees the old state before allocating a new one. If kzalloc() fails, the function returns without updating the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +4 -4
@@ -508,13 +508,13 @@ static void amdgpu_dm_crtc_reset_state(struct drm_crtc *crtc) {struct dm_crtc_state *state; -if (crtc->state) -amdgpu_dm_crtc_destroy_state (crtc, crtc->state); - state =kzalloc (sizeof (*state),GFP_KERNEL ); -if (WARN_ON (!state)) +if (!state)return ; +if (crtc->state) +amdgpu_dm_crtc_destroy_state (crtc, crtc->state); +__drm_atomic_helper_crtc_reset (crtc, &state->base); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 490/621 drm/amd/display: Fix dangling pointer in plane reset function
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Evgenii Burenchev <[email protected]>
[ Upstream commit 98cad4bd1443975d972f4c7f705980da03722a22 ]
amdgpu_dm_plane_drm_plane_reset() frees the old state before allocating a new one. If kzalloc() fails, the function returns without updating the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +4 -6
@@ -1446,17 +1446,15 @@ static const struct drm_plane_helper_funcs dm_primary_plane_helper_funcs = {static void amdgpu_dm_plane_drm_plane_reset (struct drm_plane *plane) { -struct dm_plane_state *amdgpu_state =NULL ; - -if (plane->state) - plane->funcs->atomic_destroy_state (plane, plane->state); +struct dm_plane_state *amdgpu_state; amdgpu_state =kzalloc (sizeof (*amdgpu_state),GFP_KERNEL ); -WARN_ON (amdgpu_state ==NULL ); -if (!amdgpu_state)return ; +if (plane->state) + plane->funcs->atomic_destroy_state (plane, plane->state); +__drm_atomic_helper_plane_reset (plane, &amdgpu_state->base); amdgpu_state->degamma_tf =AMDGPU_TRANSFER_FUNCTION_DEFAULT ; amdgpu_state->hdr_mult =AMDGPU_HDR_MULT_DEFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 491/621 dm-pcache: validate seg_id fields from persistent memory
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit 90c990a68460d7b5720e5634cf650eccdf0f4098 ]
cache_pos_decode(), cache_key_decode() and the last-kset branches of cache_replay(), the writeback worker and the GC worker take a cache segment id from the cache device metadata and index cache->segments[] with it without checking it against cache->n_segs. That metadata is only CRC-protected with a fixed public seed, so whoever supplies the cache device on a table load (CAP_SYS_ADMIN) controls the id; an out-of-range value forms a wild pcache_cache_segment pointer that is dereferenced and written through -- an out-of-bounds read and write driven by on-disk data.
Add cache_seg_id_valid() and reject an out-of-range id at each decode site, failing the operation with -EIO instead of indexing past the array. Bound the id against the initialized-segment count (cache_info.n_segs) rather than the physical device total. A forged cache_info.n_segs below seg_num otherwise leaves segments[cache_info.n_segs..seg_num) as zeroed structs whose data pointer is NULL, so a forged id in that window would still be dereferenced. A later patch guarantees cache_info.n_segs <= seg_num, and a driver-created cache sets the two equal, so valid images are unaffected.
--- drivers/md/dm-pcache/cache.c | 4 ++++ drivers/md/dm-pcache/cache.h | 14 ++++++++++++++ drivers/md/dm-pcache/cache_gc.c | 16 ++++++++++++++-- drivers/md/dm-pcache/cache_key.c | 11 +++++++++++ drivers/md/dm-pcache/cache_writeback.c | 20 ++++++++++++++++---- 5 files changed, 59 insertions(+), 6 deletions(-)
drivers/md/dm-pcache/cache.c +4 -0
@@ -118,6 +118,9 @@ int cache_pos_decode(struct pcache_cache *cache,if (!latest_addr)return -EIO ; +if (!cache_seg_id_valid (cache, latest.cache_seg_id)) +return -EIO ; + pos->cache_seg = &cache->segments[latest.cache_seg_id];if (latest.seg_off >= pos->cache_seg->segment.data_size)
@@ -158,6 +161,7 @@ static int cache_init(struct dm_pcache *pcache) cache->cache_dev = &pcache->cache_dev; cache->n_segs = cache_dev->seg_num;atomic_set (&cache->gc_errors,0 ); +atomic_set (&cache->writeback_errors,0 );spin_lock_init (&cache->seg_map_lock);spin_lock_init (&cache->key_head_lock);
drivers/md/dm-pcache/cache.h +14 -0
@@ -421,6 +421,20 @@ static inline bool cache_seg_is_ctrl_seg(u32 cache_seg_id)return (cache_seg_id ==0 ); } +/** +* cache_seg_id_valid - Validate a cache segment id read from the cache device. +* @cache: Pointer to the pcache_cache structure. +* @cache_seg_id: Segment id decoded from on-media metadata. +* +* On-media segment ids are only protected by a CRC, which an attacker who can +* format the cache device computes over their chosen value. Reject any id that +* would index cache->segments[] out of bounds before it is dereferenced. +*/ +static inline bool cache_seg_id_valid (struct pcache_cache *cache,u32 cache_seg_id) +{ +return cache_seg_id < cache->cache_info.n_segs; +} +/** * cache_key_cutfront - Cuts a specified length from the front of a cache key. * @key: Pointer to pcache_cache_key structure.
drivers/md/dm-pcache/cache_gc.c +14 -2
@@ -74,11 +74,17 @@ static bool need_gc(struct pcache_cache *cache, struct pcache_cache_pos *dirty_t* @cache: Pointer to the pcache_cache structure. * @kset_onmedia: Pointer to the kset_onmedia structure for the last kset. */ -static void last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) +static int last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *cur_seg, *next_seg; +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in gc (n_segs %u)\n" , + kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } + cur_seg = cache->key_tail.cache_seg; next_seg = &cache->segments[kset_onmedia->next_cache_seg_id];
@@ -94,6 +100,8 @@ static void last_kset_gc(struct pcache_cache *cache, struct pcache_cache_kset_onspin_lock (&cache->seg_map_lock);__clear_bit (cur_seg->cache_seg_id, cache->seg_map);spin_unlock (&cache->seg_map_lock); + +return 0 ; }void pcache_cache_gc_fn (struct work_struct *work)
@@ -130,7 +138,11 @@ void pcache_cache_gc_fn(struct work_struct *work)if (dirty_tail.cache_seg == key_tail.cache_seg)break ; -last_kset_gc (cache, kset_onmedia); + ret =last_kset_gc (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->gc_errors); +return ; + }continue ; }
drivers/md/dm-pcache/cache_key.c +11 -0
@@ -103,6 +103,12 @@ int cache_key_decode(struct pcache_cache *cache,return -EIO ; } +if (!cache_seg_id_valid (cache, key_onmedia->cache_seg_id)) { +pcache_dev_err (pcache,"invalid cache_seg_id %u in cache key (n_segs %u)\n" , + key_onmedia->cache_seg_id, cache->n_segs); +return -EIO ; + } + key->cache_pos.cache_seg = &cache->segments[key_onmedia->cache_seg_id]; key->cache_pos.seg_off = key_onmedia->cache_seg_off;
@@ -810,6 +816,11 @@ int cache_replay(struct pcache_cache *cache) goto out; } +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { + ret = -EIO ; + goto out; + } + next_seg = &cache->segments[kset_onmedia->next_cache_seg_id]; pos->cache_seg = next_seg;
drivers/md/dm-pcache/cache_writeback.c +16 -4
@@ -196,12 +196,18 @@ static int cache_kset_insert_tree(struct pcache_cache *cache, struct pcache_cachreturn ret; } -static void last_kset_writeback (struct pcache_cache *cache, +static int last_kset_writeback (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *last_kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *next_seg; +if (!cache_seg_id_valid (cache, last_kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in writeback (n_segs %u)\n" , + last_kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } +pcache_dev_debug (pcache,"last kset, next: %u\n" , last_kset_onmedia->next_cache_seg_id); next_seg = &cache->segments[last_kset_onmedia->next_cache_seg_id];
@@ -211,6 +217,8 @@ static void last_kset_writeback(struct pcache_cache *cache, cache->dirty_tail.seg_off =0 ;cache_encode_dirty_tail (cache);mutex_unlock (&cache->dirty_tail_lock); + +return 0 ; }void cache_writeback_fn (struct work_struct *work)
@@ -244,7 +252,11 @@ void cache_writeback_fn(struct work_struct *work) }if (kset_onmedia->flags &PCACHE_KSET_FLAGS_LAST ) { -last_kset_writeback (cache, kset_onmedia); + ret =last_kset_writeback (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->writeback_errors); + goto unlock; + } delay =0 ; goto queue_work; }
@@ -256,8 +268,8 @@ void cache_writeback_fn(struct work_struct *work) ret =cache_kset_insert_tree (cache, kset_onmedia);if (ret) { - delay =PCACHE_CACHE_WRITEBACK_INTERVAL ; - goto queue_work; +atomic_inc (&cache->writeback_errors); + goto unlock; }cache_wb_tree_writeback (cache,get_kset_onmedia_size (kset_onmedia));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 482/621 usb: gadget: uac: validate rate list length before storing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Ming <[email protected]>
[ Upstream commit 844d83d5964b87919b958ff48405188c6ddae9cc ]
UAC1 and UAC2 configfs rate-list attributes parse a comma-separated list of sampling rates and store each parsed value in fixed-size arrays. The arrays have UAC_MAX_RATES entries, but the store paths do not check that the input contains at most that many tokens before writing through opts->name##s[i++].
Writing more than ten rates therefore writes past the end of the p_srates[] or c_srates[] array in struct f_uac1_opts or struct f_uac2_opts.
With CONFIG_UBSAN_BOUNDS enabled, writing an 11-entry rate list to the UAC1 p_srate attribute reports:
UBSAN: array-index-out-of-bounds drivers/usb/gadget/function/f_uac1.c:1669:1 index 10 is out of range for type 'int [10]' __ubsan_handle_out_of_bounds.cold f_uac1_opts_p_srate_store configfs_write_iter vfs_write ksys_write do_syscall_64
The same reproducer against the UAC2 p_srate attribute reports:
UBSAN: array-index-out-of-bounds drivers/usb/gadget/function/f_uac2.c:2087:1 index 10 is out of range for type 'int [10]' __ubsan_handle_out_of_bounds.cold f_uac2_opts_p_srate_store configfs_write_iter vfs_write ksys_write do_syscall_64
Reject additional tokens once UAC_MAX_RATES entries have been parsed. Also keep the original kstrdup() pointer for kfree(), because strsep() advances the parsing cursor. Freeing the advanced cursor leaks the original buffer on successful parses and can free an interior pointer on some error paths.
--- drivers/usb/gadget/function/f_uac1.c | 13 +++++++++---- drivers/usb/gadget/function/f_uac2.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/usb/gadget/function/f_uac1.c +9 -4
@@ -1594,7 +1594,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \struct f_uac1_opts *opts =to_f_uac1_opts (item); \ -char *split_page =NULL ; \ +char *buf =NULL ; \ +char *split_page; \int ret = -EINVAL ; \char *token; \u32 num; \
@@ -1608,18 +1609,22 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ \ i =0 ; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + buf = kstrdup(page, GFP_KERNEL); \ + split_page = buf; \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ goto end; \ - \ + if (i >= UAC_MAX_RATES) { \ + ret = -EINVAL; \ + goto end; \ + } \ opts->name##s[i++] = num; \ ret = len; \ }; \ \ end: \ - kfree(split_page); \ + kfree(buf); \ mutex_unlock(&opts->lock); \ return ret; \ } \
drivers/usb/gadget/function/f_uac2.c +9 -4
@@ -2012,7 +2012,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \struct f_uac2_opts *opts =to_f_uac2_opts (item); \ -char *split_page =NULL ; \ +char *buf =NULL ; \ +char *split_page; \int ret = -EINVAL ; \char *token; \u32 num; \
@@ -2026,18 +2027,22 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ \ i =0 ; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + buf = kstrdup(page, GFP_KERNEL); \ + split_page = buf; \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ goto end; \ - \ + if (i >= UAC_MAX_RATES) { \ + ret = -EINVAL; \ + goto end; \ + } \ opts->name##s[i++] = num; \ ret = len; \ }; \ \ end: \ - kfree(split_page); \ + kfree(buf); \ mutex_unlock(&opts->lock); \ return ret; \ } \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 530/621 arm64: dts: lx2160a: fix IIC1 pinmux submask rejected by pinctrl-single
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit 6affdda171ca8f2e082e8c4fba56233a2f8c9910 ]
IIC1_PMUX is a single bit field at RCWSR14 bit 10, so the mask for the two iic1 pinmux nodes was narrowed from 0x7 to 0x1 to avoid writing the two reserved bits next to it.
With pinctrl-single,bit-per-mux the driver does not take the supplied mask as the bits to modify. It derives the field from the node's pinctrl-single,function-mask, which is 0x7 here, and then requires the supplied mask to match it exactly:
bit_pos = __ffs(mask); /* 10 */
mask_pos = ((pcs->fmask) << bit_pos); /* 0x7 << 10 = 0x1c00 */
submask = mask & mask_pos; /* 0x400 */
...
if (submask != mask_pos) {
dev_warn(pcs->dev,
"Invalid submask 0x%x for %pOFn at 0x%x\n",
submask, np, offset);
continue;
}A one bit mask gives submask 0x400 against mask_pos 0x1c00, so both nodes are rejected and the pins are never muxed with this message:
pinctrl-single 70010012c.pinmux: Invalid submask 0x400 for iic1-i2c-pins pinctrl-single 70010012c.pinmux: Invalid submask 0x400 for iic1-gpio-pins
The values are not changed:
- 0x0 selects IIC1
- 0x1 << 10 selects GPIO_1[3:2].
--- arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +9 -2
@@ -1864,12 +1864,19 @@ i2c6_i2c7_pins: iic8-iic7-i2c-pins { }; /* RCWSR14 */ + /* + * IIC1_PMUX is a single bit at RCWSR14[10], but bit-per-mux + * uses the mask for the field to clear before applying the + * value. + * So bits 11 and 12, which are reserved, are written as 0 + * on every mux switch, it is harmless. + */ i2c0_pins: iic1-i2c-pins { - pinctrl-single,bits = <0x8 0x0 (0x1 << 10)>; + pinctrl-single,bits = <0x8 0x0 (0x7 << 10)>; }; gpio0_3_2_pins: iic1-gpio-pins { - pinctrl-single,bits = <0x8 (0x1 << 10) (0x1 << 10)>; + pinctrl-single,bits = <0x8 (0x1 << 10) (0x7 << 10)>; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 539/621 drm/aspeed: Balance the display clock enable on teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit ecce445c6489895463b7ddec2af66338287fee4c ]
aspeed_gfx_load() enables the display clock without checking the return value and never disables it on probe failure or removal. devm_clk_get() only releases the clock reference, leaving the enable unbalanced.
Use devm_clk_get_enabled() to handle enable failures and automatically disable and unprepare the clock on probe failure or removal.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/gpu/drm/aspeed/aspeed_gfx_drv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/aspeed/aspeed_gfx_drv.c +2 -3
@@ -190,13 +190,12 @@ static int aspeed_gfx_load(struct drm_device *drm) }reset_control_deassert (priv->rst); - priv->clk =devm_clk_get (drm->dev,NULL ); + priv->clk =devm_clk_get_enabled (drm->dev,NULL );if (IS_ERR (priv->clk)) {dev_err (&pdev->dev, -"missing or invalid clk device tree entry" ); +"failed to get and enable clock\n" );return PTR_ERR (priv->clk); } -clk_prepare_enable (priv->clk);/* Sanitize control registers */ writel (0 , priv->base +CRT_CTRL1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 540/621 drm/vc4: Free the BO cache size list on teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit b41ff8b529278216cba22a5dcdc93fea2a3a9619 ]
vc4_bo_cache_destroy() purges the cached BOs but never frees the size list, leaking it on every unbind.
--- drivers/gpu/drm/vc4/vc4_bo.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/vc4/vc4_bo.c +1 -0
@@ -1054,6 +1054,7 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)cancel_work_sync (&vc4->bo_cache.time_work);vc4_bo_cache_purge (dev); +kfree (vc4->bo_cache.size_list);for (i =0 ; i < vc4->num_labels; i++) {if (vc4->bo_labels[i].num_allocated) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 541/621 net/sched: em_text: reject unterminated algo before autoload
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit c9728fcf2e7fb4a7a8d08ebd9524c3b02ae1a021 ]
This is a follow-up to commit 9c572a83037a ("net/sched: fix potential stack infoleak in em_text_dump()"), which zero-initialised the dump-side struct. Sashiko pointed at a pre-existing bug that exposed the change-side input-validation gap open.
em_text_change() casts the raw netlink attribute payload to struct tcf_em_text and passes conf->algo, a 16-byte array with no enforced NUL terminator, to textsearch_prepare(). On the TS_AUTOLOAD retry textsearch_prepare() calls request_module("ts_%s", algo); vsnprintf() walks %s until it finds a NUL, so an algo[] with no NUL reads past the array into the adjacent struct fields and payload and feeds those bytes to the usermode helper command line. This is an out-of-bounds read and a kernel memory disclosure.
Reject the attribute when no NUL exists within TC_EM_TEXT_ALGOSIZ bytes, matching the check xt_string has had since 3ab720881b6e.
Conditions to recreate the bug:
- CAP_NET_ADMIN on the target netns (namespace-local via unshare -Urn is enough)
- install clsact on an interface, then add a basic filter with one text ematch whose algo[] is 16 bytes with no NUL (e.g. "A"*16) and pattern_len at least 1
- the add fails with -ENOENT and the kernel invokes modprobe with a module name made of "ts_" plus the 16 bytes and the adjacent payload
--- net/sched/em_text.c | 3 +++ 1 file changed, 3 insertions(+)
net/sched/em_text.c +3 -0
@@ -58,6 +58,9 @@ static int em_text_change(struct net *net, void *data, int len,if (len <sizeof (*conf) || len < (sizeof (*conf) + conf->pattern_len))return -EINVAL ; +if (!memchr (conf->algo,'\0' ,sizeof (conf->algo))) +return -EINVAL ; +if (conf->from_layer > conf->to_layer)return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 542/621 amt: send the relays General Query directly from the receive path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Omar Ramadan <[email protected]>
[ Upstream commit afae89de73dd693cfa329580ba0fba63bd3f0a11 ]
An skb queued in a qdisc can outlive the tunnel it references through a raw pointer in skb->cb. For example, with igmp_qrv set to 1 on the relay a tunnel lives for 135s, so a netem delay of 180s on the amt device outlives it; when the tunnel expires and is freed, the subsequent dequeue triggers a use-after-free in amt_dev_xmit().
BUG: KASAN: slab-use-after-free in amt_dev_xmit+0x2763/0x2e20 Call Trace: amt_dev_xmit+0x2763/0x2e20 [drivers/net/amt.c:1262] dev_hard_start_xmit+0x22f/0x620 sch_direct_xmit+0x12e/0xac0 netem_dequeue+0x333/0xc50 net_tx_action+0x35c/0xa60
amt_send_igmp_gq() and amt_send_mld_gq() are only called from amt_request_handler(), inside the rcu_read_lock_bh() section of amt_rcv(). amt_request_handler() already has the tunnel the query is
for: it found or created it inside that section. Queuing the query with dev_queue_xmit() only leads back into amt_dev_xmit(), which strips the Ethernet header and calls amt_send_membership_query() for that tunnel.
Make that call directly from the two senders instead, the same way amt_send_advertisement() transmits from the receive path. The query never waits in a qdisc, the tunnel is only dereferenced inside the RCU section that found or created it, and nothing is stored in skb->cb, so no lookup or refcount is needed. Remove the query branch of amt_dev_xmit(), amt_skb_cb() and struct amt_skb_cb, which have no users left.
Behaviour changes:
- The relay's own General Queries no longer pass through the amt device's egress path: its qdisc, tc egress (clsact/tcx), the netfilter egress hook and packet taps. They are still visible as UDP on the underlay.
- A query that is sent successfully is no longer counted as tx_dropped. The old query branch left through the unlock label, which counted every sent query as dropped.
- A query that reaches amt_dev_xmit() on a relay from elsewhere, such as a userspace querier, is now dropped at the IGMP/MLD type switch. Before, it trusted whatever skb->cb held, and a NULL tunnel hit the WARN_ON(1).
--- drivers/net/amt.c | 48 +++++++++++++++-------------------------------- include/net/amt.h | 4 ---- 2 files changed, 15 insertions(+), 37 deletions(-)
drivers/net/amt.c +15 -33
@@ -80,15 +80,6 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT;static struct mld2_grec mldv2_zero_grec;#endif -static struct amt_skb_cb *amt_skb_cb (struct sk_buff *skb) -{ -BUILD_BUG_ON (sizeof (struct amt_skb_cb ) +sizeof (struct tc_skb_cb ) > - sizeof_field(struct sk_buff, cb)); - -return (struct amt_skb_cb *)((void *)skb->cb + -sizeof (struct tc_skb_cb )); -} -static void __amt_source_gc_work (void ) {struct amt_source_node *snode;
@@ -789,6 +780,11 @@ static void amt_send_request(struct amt_dev *amt, bool v6)rcu_read_unlock (); } +static bool amt_send_membership_query (struct amt_dev *amt, +struct sk_buff *skb, +struct amt_tunnel_list *tunnel, +bool v6); +static void amt_send_igmp_gq (struct amt_dev *amt,struct amt_tunnel_list *tunnel) {
@@ -798,8 +794,11 @@ static void amt_send_igmp_gq(struct amt_dev *amt,if (!skb)return ; -amt_skb_cb (skb)->tunnel = tunnel; -dev_queue_xmit (skb); +skb_pull (skb,sizeof (struct ethhdr )); +if (amt_send_membership_query (amt, skb, tunnel, false)) { + amt->dev->stats.tx_dropped++; +kfree_skb (skb); + } }#if IS_ENABLED (CONFIG_IPV6 )
@@ -883,8 +882,11 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)if (!skb)return ; -amt_skb_cb (skb)->tunnel = tunnel; - dev_queue_xmit(skb); +skb_pull (skb,sizeof (struct ethhdr )); +if (amt_send_membership_query (amt, skb, tunnel, true)) { + amt->dev->stats.tx_dropped++; +kfree_skb (skb); + } }#else static void amt_send_mld_gq (struct amt_dev *amt,struct amt_tunnel_list *tunnel)
@@ -1183,7 +1185,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)#endif bool report = false;struct igmphdr *ih; -bool query = false;struct iphdr *iph;bool data = false;bool v6 = false;
@@ -1201,9 +1202,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)case IGMP_HOST_MEMBERSHIP_REPORT : report = true;break ; -case IGMP_HOST_MEMBERSHIP_QUERY : - query = true; -break ;default : goto free; }
@@ -1225,9 +1223,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)case ICMPV6_MLD2_REPORT : report = true;break ; -case ICMPV6_MGM_QUERY : - query = true; -break ;default : goto free; }
@@ -1258,19 +1253,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) goto free; goto unlock; }else if (amt->mode ==AMT_MODE_RELAY ) { -if (query) { - tunnel =amt_skb_cb (skb)->tunnel; -if (!tunnel) { -WARN_ON (1 ); - goto free; - } - -/* Do not forward unexpected query */ -if (amt_send_membership_query (amt, skb, tunnel, v6)) - goto free; - goto unlock; - } -if (!data) goto free;list_for_each_entry_rcu (tunnel, &amt->tunnel_list, list) {
include/net/amt.h +0 -4
@@ -231,10 +231,6 @@ struct amt_relay_headers { }; } __packed; -struct amt_skb_cb { -struct amt_tunnel_list *tunnel; -}; -struct amt_tunnel_list {struct list_head list;/* Protect All resources under an amt_tunne_list */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 543/621 cxgb4/ch_ktls: disable softirqs around tid_list erases
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Hoon Choi <[email protected]>
[ Upstream commit 4c9dc0faca98084922caeb689579d338cf3e1c29 ]
chcr_ktls_cpl_act_open_rpl() inserts into tid_list from the receive path using xa_insert_bh(). The array is shared by the adapter's connections and initialized with XA_FLAGS_LOCK_BH. However, chcr_ktls_dev_del() and the chcr_ktls_dev_add() error path use xa_erase(), which takes the XArray lock without disabling softirqs.
When cleanup runs with softirqs enabled, a receive softirq for another connection on the same CPU can interrupt the erase and spin on the lock held by the interrupted task. Use xa_erase_bh() at both sites to match the insertion path.
--- .../net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c +2 -2
@@ -389,7 +389,7 @@ static void chcr_ktls_dev_del(struct net_device *netdev,cxgb4_remove_tid (&tx_info->adap->tids, tx_info->tx_chan, tx_info->tid, tx_info->ip_family); -xa_erase (&u_ctx->tid_list, tx_info->tid); +xa_erase_bh (&u_ctx->tid_list, tx_info->tid); } port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
@@ -577,7 +577,7 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,cxgb4_remove_tid (&tx_info->adap->tids, tx_info->tx_chan, tx_info->tid, tx_info->ip_family); -xa_erase (&u_ctx->tid_list, tx_info->tid); +xa_erase_bh (&u_ctx->tid_list, tx_info->tid); put_module:/* release module refcount */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 544/621 tee: optee: fix kernel-doc warnings
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Zaiden <[email protected]>
[ Upstream commit 3faa6774ffc5973af39ac9c4f1fe93aa92ec9407 ]
Fix kernel-doc issues in optee_private.h and optee_msg.h:
- Add missing documentation for struct members: optee_msg_param_value, optee_msg_param, optee_msg_arg, optee, and optee_ffa;
- Ensure member descriptions follow the order of declaration;
- Use consistent formatting (lowercase descriptions and ':' after member names);
- Adjust indentation for better alignment;
This resolves kernel-doc warnings such as missing member descriptions and incorrect prototype documentation.
No functional changes.
Stable-dep-of: 3c0d2f1f431c ("tee: optee: ffa: support shared memory offsets on large-page kernels")
--- drivers/tee/optee/optee_msg.h | 50 +++++++------ drivers/tee/optee/optee_private.h | 120 ++++++++++++++++-------------- 2 files changed, 92 insertions(+), 78 deletions(-)
drivers/tee/optee/optee_msg.h +28 -22
@@ -103,9 +103,9 @@/** * struct optee_msg_param_tmem - temporary memory reference parameter -* @buf_ptr: Address of the buffer -* @size: Size of the buffer -* @shm_ref: Temporary shared memory reference, pointer to a struct tee_shm +* @buf_ptr: address of the buffer +* @size: size of the buffer +* @shm_ref: temporary shared memory reference, pointer to a struct tee_shm * * Secure and normal world communicates pointers as physical address * instead of the virtual address. This is because secure and normal world
@@ -122,9 +122,9 @@ struct optee_msg_param_tmem {/** * struct optee_msg_param_rmem - registered memory reference parameter -* @offs: Offset into shared memory reference -* @size: Size of the buffer -* @shm_ref: Shared memory reference, pointer to a struct tee_shm +* @offs: offset into shared memory reference +* @size: size of the buffer +* @shm_ref: shared memory reference, pointer to a struct tee_shm */ struct optee_msg_param_rmem {u64 offs;
@@ -134,12 +134,12 @@ struct optee_msg_param_rmem {/** * struct optee_msg_param_fmem - FF-A memory reference parameter -* @offs_lower: Lower bits of offset into shared memory reference -* @offs_upper: Upper bits of offset into shared memory reference -* @internal_offs: Internal offset into the first page of shared memory -* reference -* @size: Size of the buffer -* @global_id: Global identifier of the shared memory +* @offs_low: lower bits of offset into shared memory reference +* @offs_high: higher bits of offset into shared memory reference +* @internal_offs: internal offset into the first page of shared memory +* reference +* @size: size of the buffer +* @global_id: global identifier of the shared memory */ struct optee_msg_param_fmem {u32 offs_low;
@@ -151,6 +151,9 @@ struct optee_msg_param_fmem {/** * struct optee_msg_param_value - opaque value parameter +* @a: first opaque value +* @b: second opaque value +* @c: third opaque value * * Value parameters are passed unchecked between normal and secure world. */
@@ -168,6 +171,7 @@ struct optee_msg_param_value {* @fmem: parameter by FF-A registered memory reference * @value: parameter by opaque value * @octets: parameter by octet string +* @u: union holding OP-TEE msg parameter * * @attr & OPTEE_MSG_ATTR_TYPE_MASK indicates if tmem, rmem or value is used in * the union. OPTEE_MSG_ATTR_TYPE_VALUE_* indicates value or octets,
@@ -189,16 +193,18 @@ struct optee_msg_param {/** * struct optee_msg_arg - call argument -* @cmd: Command, one of OPTEE_MSG_CMD_* or OPTEE_MSG_RPC_CMD_* -* @func: Trusted Application function, specific to the Trusted Application, -* used if cmd == OPTEE_MSG_CMD_INVOKE_COMMAND -* @session: In parameter for all OPTEE_MSG_CMD_* except -* OPTEE_MSG_CMD_OPEN_SESSION where it's an output parameter instead -* @cancel_id: Cancellation id, a unique value to identify this request -* @ret: return value -* @ret_origin: origin of the return value -* @num_params: number of parameters supplied to the OS Command -* @params: the parameters supplied to the OS Command +* @cmd: command, one of OPTEE_MSG_CMD_* or OPTEE_MSG_RPC_CMD_* +* @func: Trusted Application function, specific to the Trusted +* Application, used if cmd == OPTEE_MSG_CMD_INVOKE_COMMAND +* @session: in parameter for all OPTEE_MSG_CMD_* except +* OPTEE_MSG_CMD_OPEN_SESSION where it's an output parameter +* instead +* @cancel_id: cancellation id, a unique value to identify this request +* @pad: padding for alignment +* @ret: return value +* @ret_origin: origin of the return value +* @num_params: number of parameters supplied to the OS Command +* @params: the parameters supplied to the OS Command * * All normal calls to Trusted OS uses this struct. If cmd requires further * information than what these fields hold it can be passed as a parameter
drivers/tee/optee/optee_private.h +64 -56
169 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 545/621 tee: optee: ffa: support shared memory offsets on large-page kernels
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mahantesh Salimath <[email protected]>
[ Upstream commit 3c0d2f1f431c51a11253f28763be723ac782fd7a ]
OP-TEE FF-A memory objects use 4 KiB pages, while the kernel page size may be larger. Consequently, tee_shm->offset can be greater than or equal to FFA_PAGE_SIZE, but OP-TEE rejects such a value in internal_offs.
Do not encode the excess page offset in offs_low/offs_high. Those fields describe the logical memref offset and are copied back into tee_param->shm_offs on return. Folding the page offset into them breaks parameter round trips when a memref is reused. They are also ignored by the OPTEE_RPC_CMD_SHM_ALLOC response path, which uses only global_id and internal_offs to construct the shared-memory mobj.
Instead, start the FF-A descriptor at the 4 KiB page containing the shared buffer, the same approach as optee_fill_pages_list() in the SMC ABI. Store the remaining in-page offset in internal_offs and preserve shm_offs in offs_low/offs_high. This keeps internal_offs within the FF-A page size, maps RPC allocations at the correct address, and preserves normal memref offsets across repeated invocations.
Tested on ARMv8-A with 64 KiB PAGE_SIZE. OP-TEE OS ran as a secure partition under Hafnium (SPMC) over FF-A. Verified registered shared memory with tee_shm->offset >= 4 KiB, memref reuse on the same TEEC_Operation, and RPC OPTEE_RPC_CMD_SHM_ALLOC (xtest regression 6007-6009). optee_hello_world, optee_aes, and xtest regression 1005, 1007, 1008, 4001-4003 and 6001-6003 also passed.
--- drivers/tee/optee/ffa_abi.c | 22 ++++++++++++++++++---- drivers/tee/optee/optee_msg.h | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-)
drivers/tee/optee/ffa_abi.c +18 -4
@@ -198,7 +198,8 @@ static int to_msg_param_ffa_mem(struct optee_msg_param *mp,if (shm) {u64 shm_offs = p->u.memref.shm_offs; - mp->u.fmem.internal_offs = shm->offset; + mp->u.fmem.internal_offs =tee_shm_get_page_offset (shm) & + (FFA_PAGE_SIZE -1 ); mp->u.fmem.offs_low = shm_offs; mp->u.fmem.offs_high = shm_offs >>32 ;
@@ -284,14 +285,26 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm, .nattrs = 1, };struct sg_table sgt; +size_t ffa_offs;int rc; +if (!num_pages) +return -EINVAL ; + rc =optee_check_mem_type (start, num_pages);if (rc)return rc; - rc =sg_alloc_table_from_pages (&sgt, pages, num_pages,0 , - num_pages *PAGE_SIZE ,GFP_KERNEL ); +/* +* Start the FF-A descriptor at the 4 KiB page containing the shared +* buffer, skipping unused leading 4 KiB pages when PAGE_SIZE is +* larger. Same approach as optee_fill_pages_list() in the SMC ABI. +* This leaves only the offset into that 4 KiB page for internal_offs. +*/ + ffa_offs =round_down (tee_shm_get_page_offset (shm),FFA_PAGE_SIZE ); + rc =sg_alloc_table_from_pages (&sgt, pages, num_pages, ffa_offs, + num_pages *PAGE_SIZE - ffa_offs, +GFP_KERNEL );if (rc)return rc; args.sg = sgt.sgl;
@@ -458,7 +471,8 @@ static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx, .attr = OPTEE_MSG_ATTR_TYPE_FMEM_OUTPUT, .u.fmem.size = tee_shm_get_size(shm), .u.fmem.global_id = shm->sec_world_id, - .u.fmem.internal_offs = shm->offset, + .u.fmem.internal_offs = tee_shm_get_page_offset(shm) & + (FFA_PAGE_SIZE - 1), }; arg->ret =TEEC_SUCCESS ;
drivers/tee/optee/optee_msg.h +2 -2
@@ -136,8 +136,8 @@ struct optee_msg_param_rmem {* struct optee_msg_param_fmem - FF-A memory reference parameter * @offs_low: lower bits of offset into shared memory reference * @offs_high: higher bits of offset into shared memory reference -* @internal_offs: internal offset into the first page of shared memory -* reference +* @internal_offs: offset into the first 4 KiB page of the FF-A shared +* memory region * @size: size of the buffer * @global_id: global identifier of the shared memory */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 546/621 ice: Restore Ordered MMIO Writes for Tx Doorbells
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan Fraschetti <[email protected]>
[ Upstream commit 7a579dec8423bba7bec96fcfcb2e30838b0858ee ]
The DQL accounting state which tracks the number of bytes queued for the NIC to transmit, namely dql->num_queued, is updated by the ICE driver when it invokes __netdev_tx_sent_queue(). Subsequently the driver updates the hardware queue tail allowing the NIC to begin processing the work queue. The queue accounting update should be ordered before the NIC begins transmitting descriptors.
The transmit path currently updates the hardware doorbell using writel_relaxed(), which (on arm64) does not provide the same ordering guarantees between writes to normal memory and writes to MMIO registers that writel() does. This introduces a potential race where the NIC begins transmitting descriptors before the dql->num_queued update is globally visible. If the NIC finishes before the update is observed by dql_completed(), it detects an invalid state where more bytes have been completed than have been queued. When this happens the following BUG_ON is triggered.
BUG_ON(count > num_queued - dql->num_completed);
This has been observed and manifests as the following crash (note that the trace has been trimmed) in an environment with sustained network load that uses an Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02) on an arm64 machine. Replacing writel_relaxed() with writel() in a test kernel eliminated the crash in the user's workload, which previously reproduced the issue reliably.
kernel BUG at lib/dynamic_queue_limits.c:99
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP pc : dql_completed+0x268/0x2a0 lr : ice_clean_tx_irq+0x1d4/0x620 [ice] Call trace: dql_completed+0x268/0x2a0 (P) ice_napi_poll+0x94/0x520 [ice] __napi_poll+0x48/0x3f0 net_rx_action+0x194/0x420
This restores the behaviour prior to commit ccde82e90946 ("ice: add E830 Earliest TxTime First Offload support"), which changed the notification mechanism from writel() to writel_relaxed().
--- drivers/net/ethernet/intel/ice/ice_txrx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_txrx.c +2 -2
@@ -1800,10 +1800,10 @@ ice_tx_map(struct ice_tx_ring *tx_ring, struct ice_tx_buf *first, } } tstamp_ring->next_to_use = j; -writel_relaxed (j, tstamp_ring->tail); +writel (j, tstamp_ring->tail); }else { ring_kick: -writel_relaxed (i, tx_ring->tail); +writel (i, tx_ring->tail); }return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 547/621 nvmet: return Invalid Field for invalid NSIDs feature 82h
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit d99bc5b456fd63be46c8bda20dbf6ede93d2fc11 ]
The Reservation Notification Mask feature (FID 82h) defines its own status code for namespaces that do not support reservations:
"If a Set Features command or a Get Features command attempts to access the Reservation Notification Mask on a namespace that does not support reservations or is invalid, then that command is aborted with status code of Invalid Field in Command."
-- NVMe Base Specification, section 5.2.26.1.33
The Set Features handler routes the namespace lookup through nvmet_req_find_ns(), which returns Invalid Namespace or Format for an unknown NSID. That is the correct status for the generic namespace-scoped admin commands, but not for this feature: a Set Features 82h naming a nonexistent NSID is aborted with Invalid Namespace or Format instead of Invalid Field in Command.
Translate the lookup failure to Invalid Field in Command. The broadcast NSID, the namespace-without-reservations case and everything else keep their current behavior.
--- drivers/nvme/target/pr.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvme/target/pr.c +4 -0
@@ -51,6 +51,8 @@ u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask)if (nsid !=U32_MAX ) { status =nvmet_req_find_ns (req); +if (status == (NVME_SC_INVALID_NS |NVME_STATUS_DNR )) +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;if (status)return status;if (!req->ns->pr.enable)
@@ -75,6 +77,8 @@ u16 nvmet_get_feat_resv_notif_mask(struct nvmet_req *req)u16 status; status =nvmet_req_find_ns (req); +if (status == (NVME_SC_INVALID_NS |NVME_STATUS_DNR )) +return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ;if (status)return status;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 548/621 nvmet: use the local P2P device on metadata allocation failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Hoon Choi <[email protected]>
[ Upstream commit 4aa9c0f377a4de5e8fddce76b34ee4529639a1ff ]
nvmet_req_alloc_p2pmem_sgls() assigns req->p2p_dev only after the data and metadata SGL allocations succeed. If the data allocation succeeds but the metadata allocation fails, out_free_sg passes req->p2p_dev to pci_p2pmem_free_sgl() before that assignment has taken place.
Pass the local p2p_dev argument instead, so cleanup uses the same PCI device as the successful data allocation.
--- drivers/nvme/target/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
@@ -1301,7 +1301,7 @@ static int nvmet_req_alloc_p2pmem_sgls(struct pci_dev *p2p_dev,return 0 ; out_free_sg: -pci_p2pmem_free_sgl (req->p2p_dev, req->sg); +pci_p2pmem_free_sgl (p2p_dev, req->sg); out_err:return -ENOMEM ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 531/621 arm64: dts: lx2160a: fix the iic5 spi3 pinmux offset and value
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit f14f4dc8ea3810f8ed4f0f3ea13f8bba3e2b0f04 ]
The iic5-spi3-pins node has both of its first two cells wrong.
The offset selects the register within the node's reg range, where:
0x0 is RCWSR12,
0x4 is RCWSR13,
0x8 is RCWSR14.
An offset of 0x3 is not one of them and is not even aligned for the declared 32 bit register width. It is the only node in this pinmux that does not use 0x0, 0x4 neither 0x8.
The value is wrong too:
IIC5_PMUX is RCWSR12[11:9] and it encodes 0b000 for IIC5, 0b001 for GPIO_1[25:24],
0b010 for SDHC1_CLK_SYNC_OUT/IN,
0b011 for {IIC5_SCL,IIC5_SDA} = {SPI3_SOUT,SPI3_SIN}.
This node selects the last of those, so it needs 0x3, not the 0x2, which is the value of the neighbouring sdhc1 clock sync node it was copied from.
--- arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +1 -1
@@ -1779,7 +1779,7 @@ esdhc0_clksync_pins: iic5-sdhc-clk-pins { }; dspi2_miso_mosi_pins: iic5-spi3-pins { - pinctrl-single,bits = <0x3 (0x2 << 9) (0x7 << 9)>; + pinctrl-single,bits = <0x0 (0x3 << 9) (0x7 << 9)>; }; i2c5_pins: iic6-i2c-pins {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/621 arm64/boot: Dont set PMUv3p9 FGT2 bits without PMUv3
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit b52ef450139f5632d7e53e6fd5f5ec46c7029dac ]
On a CPU with FGT2 and an IMPLEMENTATION DEFINED PMU (PMUVer 0b1111), __init_el2_fgt2 sets the PMUv3p9 bits in HDFGRTR2_EL2 and HDFGWTR2_EL2, which are RES0 there. The macro only checks that PMUVer is at least PMUv3p9, and 0b1111 passes.
Exclude 0b1111 before the compare, as __init_el2_debug does.
--- arch/arm64/include/asm/el2_setup.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/include/asm/el2_setup.h +3 -2
@@ -412,8 +412,9 @@mov x2, xzr mrs x1, id_aa64dfr0_el1 ubfx x1, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 - cmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9 - b.lt .Lskip_pmuv3p9_\@ + cmp x1, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF + ccmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9, #8, ne + b.lt .Lskip_pmuv3p9_\@ // Skip if < PMUv3p9 or IMP_DEF orr x0, x0, #HDFGRTR2_EL2_nPMICNTR_EL0 orr x0, x0, #HDFGRTR2_EL2_nPMICFILTR_EL0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 550/621 zloop: zero out only the unread tail of short reads
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shin'ichiro Kawasaki <[email protected]>
[ Upstream commit 58304e139cb3fa640da74bc02101f0926d0607e2 ]
zloop_complete_rq() handles a short read from a zone's backing file by zero-filling every bio in the request. This is correct when the entire request is beyond the written part of the zone. When a read request straddles the boundary between written and unwritten data, read_iter() returns a partial byte count and zloop then zeroes the whole request even for the partially read area with valid data.
Such an unexpected zero data read was observed with fio test script t/zbd/test-zbd-support and its test case 69, failing with "bad magic header 0".
Avoid the unexpected zero data read by zeroing out only the unread tail part. When read data size cmd->ret is smaller than the request size, call the new helper function zloop_fill_zero_rq() that walks through each bio_vec and fills zeros from the specified start offset.
--- drivers/block/zloop.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/block/zloop.c +24 -7
@@ -568,6 +568,27 @@ static void zloop_cmd_workfn(struct work_struct *work) current->flags = orig_flags; } +static void zloop_fill_zero_rq (struct request *rq,unsigned int zero_from) +{ +struct req_iterator iter; +struct bio_vec bv; +unsigned int pos =0 ; +unsigned int end, off; + +rq_for_each_segment (bv, rq, iter) { + end = pos + bv.bv_len; +if (end > zero_from) { +if (pos < zero_from) + off = zero_from - pos; +else + off =0 ; +memzero_page (bv.bv_page, bv.bv_offset + off, + bv.bv_len - off); + } + pos = end; + } +} +static void zloop_complete_rq (struct request *rq) {struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);
@@ -582,13 +603,9 @@ static void zloop_complete_rq(struct request *rq)pr_err ("Zone %u: failed read sector %llu, %llu sectors\n" , zone_no, cmd->sector, cmd->nr_sectors); -if (cmd->ret >=0 && cmd->ret !=blk_rq_bytes (rq)) { -/* short read */ -struct bio *bio; - -__rq_for_each_bio (bio, rq) -zero_fill_bio (bio); - } +/* Short read. Zero out the unread tail beyond cmd->ret. */ +if (cmd->ret >=0 && cmd->ret !=blk_rq_bytes (rq)) +zloop_fill_zero_rq (rq, cmd->ret);break ;case REQ_OP_WRITE :case REQ_OP_ZONE_APPEND :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 551/621 btrfs: always return -EIOCBQUEUED after btrfs_uring_read_extent_endio
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit 80a8dbb30d2b00b9c671b02bd73f700f6d20100f ]
If all bios finish before btrfs_encoded_read_regular_fill_pages() returns, it calls btrfs_uring_read_extent_endio() and previously returned the I/O status. A negative errno then made btrfs_uring_read_extent() unlock and free while btrfs_uring_read_finished() did the same again.
Return -EIOCBQUEUED so only the deferred path cleans up.
--- fs/btrfs/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/inode.c +3 -4
@@ -9499,7 +9499,6 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,struct completion sync_reads;unsigned long i =0 ;struct btrfs_bio *bbio; -int ret;/* * Fast path for synchronous reads which completes in this call, io_uring
@@ -9546,10 +9545,10 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,if (uring_ctx) {if (refcount_dec_and_test (&priv->pending_refs)) { - ret =blk_status_to_errno (READ_ONCE (priv->status)); -btrfs_uring_read_extent_endio (uring_ctx, ret); +int error =blk_status_to_errno (READ_ONCE (priv->status)); + +btrfs_uring_read_extent_endio (uring_ctx, error);kfree (priv); -return ret; }return -EIOCBQUEUED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 552/621 btrfs: free iov when btrfs_uring_read_extent() fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit a8ea92830b3e0e163d4e829bdcb17ca83c0f951c ]
After btrfs_uring_read_extent(), the caller always jumped to out_acct. That skips kfree(data->iov), which is only correct for -EIOCBQUEUED where the deferred path owns the iov. On failure, fall through to out_free instead.
--- fs/btrfs/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.c +2 -2
@@ -4928,8 +4928,8 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue cached_state, disk_bytenr, disk_io_size, count, data->args.compression, data->iov, cmd); - - goto out_acct; +if (ret == -EIOCBQUEUED ) + goto out_acct; } out_free:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 553/621 btrfs: unlock inode and extent in caller when io_uring read extent fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit b6e8add5d79d1f6f819a054c833bab452bd7365d ]
btrfs_uring_read_extent() runs only after btrfs_encoded_read() has taken the inode shared lock and the extent lock. On failure it used to unlock in out_fail, and a pages-array allocation failure returned -ENOMEM without unlocking at all.
Unlock in the caller instead on all failure returns, matching the copy_to_user() error path. The deferred -EIOCBQUEUED path still unlocks in btrfs_uring_read_finished().
--- fs/btrfs/ioctl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/ioctl.c +3 -4
@@ -4659,7 +4659,7 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int isssize_t page_offset;ssize_t ret; -/* The inode lock has already been acquired in btrfs_uring_read_extent. */ +/* The inode lock has already been acquired in btrfs_encoded_read(). */ btrfs_lockdep_inode_acquire (inode, i_rwsem);if (priv->err) {
@@ -4725,7 +4725,6 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter, struct iovec *iov, struct io_uring_cmd *cmd) { struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp)); -struct extent_io_tree *io_tree = &inode->io_tree;struct page **pages =NULL ;struct btrfs_uring_priv *priv =NULL ;unsigned long nr_pages;
@@ -4781,8 +4780,6 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,return -EIOCBQUEUED ; out_fail: -btrfs_unlock_extent (io_tree, start, lockend, &cached_state); -btrfs_inode_unlock (inode,BTRFS_ILOCK_SHARED );kfree (priv);for (int i =0 ; i < nr_pages; i++) {if (pages[i])
@@ -4930,6 +4927,8 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue data->iov, cmd);if (ret == -EIOCBQUEUED ) goto out_acct; +btrfs_unlock_extent (io_tree, start, lockend, &cached_state); +btrfs_inode_unlock (inode,BTRFS_ILOCK_SHARED ); } out_free:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 554/621 btrfs: fix xattr replace when multiple xattrs are packed in the same item
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 858bee1c77857aabcc2327cd32dd8266332de332 ]
If we have a btrfs_dir_item item that packs multiple xattrs and then we replace the value of one of them (with the setxattr(2) family of syscalls) with another value of a different size, we end up not having a fully initialized btrfs_dir_item, resulting in a corruption that the tree checker will detect at extent buffer writeback time.
This is because in btrfs_setxattr() when we find a btrfs_dir_item with multiple xattrs (due to the crc32c hash of their name being the same) we delete one of the xattr items (btrfs_dir_item) and then insert a new one, but the deletion and insertion results in shifting existing data in the leaf and therefore when the new value of a xattr has a different size, the new btrfs_dir_item is placed in a leaf section that was not initialized and we only copy the value's data and set the value's length in the new btrfs_dir_item, without setting the name, the name's length, the key (which must be all zeroes for xattrs), flags (BTRFS_FT_XATTR) and transaction ID.
The following script reproduces the issue:
$ cat test.sh #!/bin/bash
DEV=/dev/sdi
MNT=/mnt/sdi
mkfs.btrfs -f $DEV
mount $DEV $MNT
touch $MNT/testfile
# Add two xattrs that, on btrfs, have the same hash (crc32c) for their
# name and therefore are packed into the same btrfs_dir_item. setfattr -n user.foobar -v 123 $MNT/testfile setfattr -n user.WvG1c1Td -v qwerty $MNT/testfile
# Verify the xattrs are present. echo "xattrs before:" getfattr --absolute-names --dump $MNT/testfile
# Now replace the value of the foobar xattr with a significantly larger
# value. setfattr -n user.foobar -v abcdefghijklmnopqrstuvwxyz $MNT/testfile
# Check the xattrs have the expected values. echo "xattrs after:" getfattr --absolute-names --dump $MNT/testfile
umount $MNT
Running it:
$ ./test.sh (...) xattrs before: # file: /mnt/sdi/testfile user.WvG1c1Td="qwerty" user.foobar="123"
xattrs after:
# file: /mnt/sdi/testfile
user.WvG1c1Td="qwerty"
So the "user.foobar" xattr is missing and there was a transaction abort when unmounting the fs with the following traces in dmesg:
$ dmesg [869800.159271] BTRFS warning (device sdi): access to eb bytenr 30474240 len 16384 out of range start 16015 len 25964 [869800.159293] ------------[ cut here ]------------ [869800.159296] WARNING: fs/btrfs/extent_io.c:4408 at report_eb_range+0x44/0x60 [btrfs], CPU#8: getfattr/2605179 [869800.168961] Modules linked in: btrfs dm_thin_pool (...) [869800.190527] CPU: 8 UID: 0 PID: 2605179 Comm: getfattr Tainted: G W 7.3.0-rc3-btrfs-next-244+ #1 PREEMPT(full) [869800.193726] Tainted: [W]=WARN [869800.194502] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014 [869800.197576] RIP: 0010:report_eb_range+0x44/0x60 [btrfs] [869800.198985] Code: 48 8b 7b 18 (...) [869800.203531] RSP: 0018:ffffce4541937d58 EFLAGS: 00010246 [869800.204609] RAX: 0000000000000000 RBX: ffff8dde054b8738 RCX: 0000000000000000 [869800.206137] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffffffffc04c92a0 [869800.207645] RBP: 0000000000003e8f R08: 0000000000000000 R09: 3fffffffffefffff [869800.226175] R10: ffffce4541937a88 R11: 0000000000000003 R12: 000000000000656c [869800.227594] R13: ffff8dde14be800f R14: 000000000000656c R15: 0000000000000069 [869800.229097] FS: 00007f59023bb780(0000) GS:ffff8de5788ed000(0000) knlGS:0000000000000000 [869800.231137] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [869800.232321] CR2: 0000558dc45e6a78 CR3: 0000000765b16004 CR4: 0000000000370ef0 [869800.233783] Call Trace: [869800.234330] <TASK> [869800.234791] read_extent_buffer+0x4d/0x100 [btrfs] [869800.235898] btrfs_listxattr+0x199/0x240 [btrfs] [869800.236912] vfs_listxattr+0x51/0xa0 [869800.237683] listxattr+0x7e/0x100 [869800.238398] path_listxattrat+0x9e/0x190 [869800.239117] do_syscall_64+0x89/0x470 [869800.239877] entry_SYSCALL_64_after_hwframe+0x76/0x7e [869800.240914] RIP: 0033:0x7f59024cdcb7 [869800.241686] Code: f0 ff ff 73 (...) [869800.245353] RSP: 002b:00007ffd056dcdb8 EFLAGS: 00000246 ORIG_RAX: 00000000000000c2 [869800.246892] RAX: ffffffffffffffda RBX: 00007ffd056df2e2 RCX: 00007f59024cdcb7 [869800.248853] RDX: 0000000000006600 RSI: 0000558dc45e0470 RDI: 00007ffd056df2e2 [869800.250514] RBP: 00007ffd056df2e2 R08: 0000000000006600 R09: 0000000000006600 [869800.252295] R10: 0000000000000004 R11: 0000000000000246 R12: 00000000ffffff9c [869800.254105] R13: 0000558dc45e0470 R14: 0000000000006600 R15: 0000000000000000 [869800.255931] </TASK> [869800.256529] ---[ end trace 0000000000000000 ]--- [869800.260071] page: refcount:2 mapcount:0 mapping:000000007ccfc77f index:0x1d10 pfn:0x608c69 [869800.260075] memcg:ffff8dde00344d40 [869800.260076] aops:btree_aops [btrfs] ino:1 [869800.260151] flags: 0x17fffc00000402a(uptodate|lru|private|writeback|node=0|zone=2|lastcpupid=0x1ffff) [869800.260154] raw: 017fffc00000402a fffff4adc773d4c8 fffff4adc48f3d88 ffff8de36504ba30 [869800.260155] raw: 0000000000001d10 ffff8dde054b8738 00000002ffffffff ffff8dde00344d40 [869800.260156] page dumped because: eb page dump [869800.260157] BTRFS critical (device sdi): corrupt leaf: root=5 block=30474240 slot=5 ino=257, invalid location key type, have 46, expect 132 or 1 [869800.260161] BTRFS info (device sdi): leaf 30474240 gen 9 total ptrs 6 free space 15629 owner 5 [869800.260163] BTRFS info (device sdi): refs 3 lock_owner 0 current 2550294 [869800.260164] item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160 [869800.260165] inode generation 3 transid 0 size 0 nbytes 16384 [869800.260166] block group 0 mode 40755 links 1 uid 0 gid 0 [869800.260167] rdev 0 sequence 0 flags 0x0 [869800.260168] atime 1790340637.0 [869800.260169] ctime 1790340637.0 [869800.260169] mtime 1790340637.0 [869800.260170] otime 1790340637.0 [869800.260170] item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12 [869800.260172] index 0 name_len 2 [869800.260172] item 2 key (256 DIR_ITEM 982728850) itemoff 16073 itemsize 38 [869800.260173] location key (257 1 0) type 1 [869800.260174] transid 9 data_len 0 name_len 8 [869800.260175] item 3 key (257 INODE_ITEM 0) itemoff 15913 itemsize 160 [869800.260176] inode generation 9 transid 9 size 0 nbytes 0 [869800.260177] block group 0 mode 100664 links 1 uid 0 gid 0 [869800.260177] rdev 0 sequence 0 flags 0x0 [869800.260178] atime 1790340638.38778502 [869800.260179] ctime 1790340638.38778502 [869800.260179] mtime 1790340638.38778502 [869800.260180] otime 1790340638.38778502 [869800.260180] item 4 key (257 INODE_REF 256) itemoff 15895 itemsize 18 [869800.260181] index 2 name_len 8 [869800.260182] item 5 key (257 XATTR_ITEM 751495445) itemoff 15779 itemsize 116 [869800.260183] location key (0 0 0) type 8 [869800.266052] transid 9 data_len 6 name_len 13 [869800.266053] location key (8243121639454149888 46 7229457603934778967) type 0 [869800.266055] transid 113 data_len 26 name_len 0 [869800.266056] location key (8608196880778817904 120 162425) type 9 [869800.266057] transid 8391162079612502016 data_len 26982 name_len 25964 [869800.266058] BTRFS error (device sdi): block=30474240 write time tree block corruption detected [869800.266091] ------------[ cut here ]------------ [869800.266092] WARNING: fs/btrfs/disk-io.c:336 at btree_csum_one_bio+0x20b/0x220 [btrfs], CPU#7: kworker/u50:7/2550294 [869800.268392] Modules linked in: btrfs dm_thin_pool (...) [869800.365851] CPU: 7 UID: 0 PID: 2550294 Comm: kworker/u50:7 Tainted: G W 7.3.0-rc3-btrfs-next-244+ #1 PREEMPT(full) [869800.368937] Tainted: [W]=WARN [869800.369834] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014 [869800.372778] Workqueue: writeback wb_workfn (flush-btrfs-3821) [869800.374314] RIP: 0010:btree_csum_one_bio+0x20b/0x220 [btrfs] [869800.375915] Code: 89 44 24 04 (...) [869800.380639] RSP: 0018:ffffce4548e3f7d0 EFLAGS: 00010246 [869800.382008] RAX: 0000000000000000 RBX: ffff8dde054b8738 RCX: 0000000000000000 [869800.383850] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff8de091c2ddc0 [869800.385710] RBP: ffff8dde196a2000 R08: 0000000000000000 R09: 3fffffffffefffff [869800.387388] R10: ffffce4548e3f500 R11: 0000000000000003 R12: ffffce4548e3f7d8 [869800.388973] R13: ffff8dde196a2000 R14: ffff8de36504b750 R15: ffff8dde4c497b00 [869800.390414] FS: 0000000000000000(0000) GS:ffff8de5788ad000(0000) knlGS:0000000000000000 [869800.392002] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [869800.393160] CR2: 000055cd6e92ad5c CR3: 00000007cb264001 CR4: 0000000000370ef0 [869800.394595] Call Trace: [869800.395113] <TASK> [869800.395570] btrfs_submit_bbio+0x872/0x890 [btrfs] [869800.397284] write_meta_extent_buffer+0x70/0x80 [btrfs] [869800.398940] btree_writepages+0x141/0x4f0 [btrfs] [869800.400426] ? get_random_u32+0x8a/0xf0 [869800.401417] ? build_slab_freelist+0x47/0x130 [869800.402574] ? preempt_count_add+0x6b/0xa0 [869800.403633] ? _raw_spin_lock_irqsave+0x23/0x50 [869800.404807] ? _raw_spin_unlock_irqrestore+0x22/0x40 [869800.406085] ? alloc_from_new_slab+0x18f/0x330 [869800.407223] do_writepages+0xc6/0x160 [869800.408191] ? refill_objects+0xd8/0x300 [869800.409211] __writeback_single_inode+0x42/0x350 [869800.410408] writeback_sb_inodes+0x231/0x560 [869800.411511] wb_writeback+0x8a/0x300 [869800.412440] wb_workfn+0xbf/0x460 [869800.413291] ? _raw_spin_unlock+0x14/0x30 [869800.414328] ? finish_task_switch.isra.0+0xb9/0x380 [869800.415105] process_one_work+0x1d1/0x3d0 [869800.416633] worker_thread+0x1c4/0x330 [869800.417467] ? __pfx_worker_thread+0x10/0x10 [869800.418452] kthread+0xfc/0x130 [869800.419257] ? __pfx_kthread+0x10/0x10 [869800.420089] ret_from_fork+0x1f7/0x2c0 [869800.420863] ? __pfx_kthread+0x10/0x10 [869800.421654] ret_from_fork_asm+0x1a/0x30 [869800.422484] </TASK> [869800.422953] ---[ end trace 0000000000000000 ]--- [869800.424005] BTRFS error (device sdi state A): Transaction 9 aborted (-EIO) [869800.424010] BTRFS: error (device sdi state A) in __btrfs_run_delayed_items:1162: errno=-5 IO failure [869800.424011] BTRFS info (device sdi state EA): forced readonly [869800.424013] BTRFS warning (device sdi state EA): Skipping commit of aborted transaction. [869800.424014] BTRFS: error (device sdi state EA) in cleanup_transaction:2076: errno=-5 IO failure
Fix this by always setting all fields in the new btrfs_dir_item when we replace an existing xattr.
--- fs/btrfs/xattr.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/btrfs/xattr.c +9 -0
@@ -161,6 +161,7 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,const u16 old_data_len =btrfs_dir_data_len (leaf, di);const u32 item_size =btrfs_item_size (leaf, slot);const u32 data_size =sizeof (*di) + name_len + size; +unsigned long name_ptr;unsigned long data_ptr;char *ptr;
@@ -189,8 +190,16 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode, ptr =btrfs_item_ptr (leaf, slot, char); ptr +=btrfs_item_size (leaf, slot) - data_size; di = (struct btrfs_dir_item *)ptr; +memzero_extent_buffer (leaf, (unsigned long )ptr + + offsetof(struct btrfs_dir_item , location), +sizeof (struct btrfs_disk_key )); +btrfs_set_dir_flags (leaf, di,BTRFS_FT_XATTR ); +btrfs_set_dir_transid (leaf, di, trans->transid); +btrfs_set_dir_name_len (leaf, di, name_len);btrfs_set_dir_data_len (leaf, di, size); + name_ptr = (unsigned long )(di +1 ); data_ptr = ((unsigned long )(di +1 )) + name_len; +write_extent_buffer (leaf, name, name_ptr, name_len);write_extent_buffer (leaf, value, data_ptr, size); }else {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 555/621 btrfs: fix lost error return value in btrfs_listxattr()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 41c8899d59898f6fa51ceebd2b6e55257191a8ee ]
If the input buffer does not have enough space to store the current xattr, we set 'iter_ret' to -ERANGE and then do "break", but that only exits the while loop over the xattrs in the current btrfs_dir_item, and then we continue the btrfs_for_each_slot() iteration, which overwrites the value of 'iter_ret' causing us to lose the error return value and proceed as if the buffer has enough space.
Fix this by returning -ERANGE directly (the path is automatically freed) instead of breaking from the while loop.
--- fs/btrfs/xattr.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/xattr.c +2 -4
@@ -329,10 +329,8 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)if (!size) goto next; -if (!buffer || (name_len +1 ) > size_left) { - iter_ret = -ERANGE ; -break ; - } +if (!buffer || (name_len +1 ) > size_left) +return -ERANGE ;read_extent_buffer (leaf, buffer, name_ptr, name_len); buffer[name_len] ='\0' ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/621 drm/xe/mmio: Fix xe_mmio_wait32() to honor delay/sleep maximums
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Previn <[email protected]>
[ Upstream commit e7ed652b1312ffcb9ea2153946615856b5097c78 ]
Check for overflow in udelay use in __xe_mmio_wait32 and avoid growing delays becoming intollerably large by capping the in-loop wait time.
v7: - Change assisted-by to "LLM" (Rodrigo).
- Move the max-wait macro to outside the function (Rodrigo).
v6: - Fix commit message to remove items dropped in v5. Fix the
use of MAX_UDELAY_MS for microsecond unit. (Shasiko review).
v5: - Simplify: don't introduce additional redesign and
use min_t with a backoff to cap wait. (Rodrigo).
v4: - Simplify using poll_timeout_us and poll_timeout_us_atomic and
update all callers to never use a param for atomic (Jani)
v3: - Use div64_s64 kernel API for 32-bit vs 64-bit division.
v2: - Fixed checkpatch failure.
- Added helper for 64-bit DIV_ROUND_UP on 32-bit CPU (Shasiko review). Fixed bug max range in usleep_range(Shasiko review)
--- drivers/gpu/drm/xe/xe_mmio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_mmio.c +3 -2
@@ -283,6 +283,7 @@ u64 xe_mmio_read64_2x32(struct xe_mmio *mmio, struct xe_reg reg)return (u64 )udw <<32 | ldw; } +#define __XE_MMIO_WAIT_MAX_BACKOFF_100MS (100 * USEC_PER_MSEC)static int __xe_mmio_wait32 (struct xe_mmio *mmio,struct xe_reg reg,u32 mask,u32 val,u32 timeout_us,u32 *out_val,bool atomic,bool expect_match) {
@@ -313,10 +314,10 @@ static int __xe_mmio_wait32(struct xe_mmio *mmio, struct xe_reg reg, u32 mask, u wait =ktime_us_delta (end, cur);if (atomic) -udelay (wait); +udelay (min_t (s64, wait, (MAX_UDELAY_MS *1000 )));else usleep_range (wait, wait <<1 ); - wait <<=1 ; + wait =min_t (s64, wait <<1 , __XE_MMIO_WAIT_MAX_BACKOFF_100MS); }if (ret !=0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/621 net: make dev_xdp_sb_prog_count() see programs attached through a link
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit d333c8bca6dc3c5e978f6698d39dd799f3b0dc8d ]
ethtool refuses to enable tcp-data-split on a device running a single-buffer XDP program (which can't deal with the payload landing in a separate buffer). dev_xdp_sb_prog_count() only looks at xdp_state[].prog though, ignoring bpf_link integration. Get the prog pointer from dev_xdp_prog(), which will consult both.
bpf_xdp_link_update() needs a bit of a touch-up, too, since ethtool calls dev_xdp_sb_prog_count() with just the instance lock (for ops-locked devices) - we now have to make sure the link updates happen under that lock.
Spotted by AI while reviewing the XDP propagation series, verified and tested on netdevsim with a C test along these lines:
link = bpf_program__attach_xdp(prog, ifindex);
system("ethtool -G eth0 tcp-data-split on")--- net/core/dev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
net/core/dev.c +7 -4
@@ -10206,13 +10206,15 @@ EXPORT_SYMBOL_GPL(dev_xdp_prog_count);u8 dev_xdp_sb_prog_count (struct net_device *dev) { +struct bpf_prog *prog;u8 count =0 ;int i; -for (i =0 ; i < __MAX_XDP_MODE; i++) -if (dev->xdp_state[i].prog && - !dev->xdp_state[i].prog->aux->xdp_has_frags) +for (i =0 ; i < __MAX_XDP_MODE; i++) { + prog =dev_xdp_prog (dev, i); +if (prog && !prog->aux->xdp_has_frags) count++; + }return count; }
@@ -10592,11 +10594,12 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog, bpf_op =dev_xdp_bpf_op (xdp_link->dev, mode); err =dev_xdp_install (xdp_link->dev, mode, bpf_op,NULL , xdp_link->flags, new_prog); +if (!err) + old_prog =xchg (&link->prog, new_prog);netdev_unlock_ops (xdp_link->dev);if (err) goto out_unlock; - old_prog =xchg (&link->prog, new_prog);bpf_prog_put (old_prog); out_unlock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 558/621 riscv: vector: Fix data pointer constraints in context save/restore
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Troy Mitchell <[email protected]>
[ Upstream commit 572b25f3a6453d8e7fc28cc0cefe41ed15be166c ]
The standard vector save/restore asm advances datap but declares it as input-only. An inlined caller reusing the original pointer may therefore use the advanced address instead.
Declare datap as read-write so the compiler can preserve the original pointer when needed.
--- arch/riscv/include/asm/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/vector.h +2 -2
@@ -224,7 +224,7 @@ static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to,"add %1, %1, %0\n\t" "vse8.v v24, (%1)\n\t" ".option pop\n\t" - : "=&r" (vl) : "r" (datap) : "memory"); + : "=&r" (vl), "+r" (datap) : : "memory"); } riscv_v_disable(); }
@@ -260,7 +260,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_"add %1, %1, %0\n\t" "vle8.v v24, (%1)\n\t" ".option pop\n\t" - : "=&r" (vl) : "r" (datap) : "memory"); + : "=&r" (vl), "+r" (datap) : : "memory"); } __vstate_csr_restore(restore_from);riscv_v_disable ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 532/621 mount: refuse MOVE_MOUNT_SET_GROUP on an unbindable mount
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit a2b42babc912e4fb428cbb42adb4f6e1e067113d ]
do_set_group() only accepts mounts as targets that are neither shared nor a slave. That encompasses undindable mounts.
If the source mount is a slave mount the target mount will end up with source's master as its master. It keeps T_UNBINDABLE. That means we get a mount that is both unbindable and a slave:
mount --bind /tmp/src /tmp/src mount --make-shared /tmp/src mount --bind /tmp/src /tmp/b mount --make-slave /tmp/b mount --bind /tmp/src /tmp/c mount --make-unbindable /tmp/c move_mount(b, "", c, "", MOVE_MOUNT_SET_GROUP) grep /tmp/c /proc/self/mountinfo ... /tmp/c ... master:646 unbindable ...
This property cannot be produced any other way. change_mnt_propagation() drops the master when it makes a mount unbindable (iow, it becomes private) and doesn't touch an unbindable mount when it is supposed to turned into a slave mount.
End-result is that the unbindable-slave mount receives everything propagated from its master's peer group while it can't be bind mounted itself. Not sure what that's supposed to do.
On the other side: if the source mount is shared, the target mount drops T_UNBINDABLE because because set_mnt_shared() clears T_SHARED_MASK.
So teach do_set_group() to refuse an unbindable target mount the same way a shared or slave target mount is refused.
The main user of MOVE_MOUNT_SET_GROUP is CRIU which restores sharing first and applies MS_UNBINDABLE afterwards. It never hits this.
--- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namespace.c +1 -1
@@ -3379,7 +3379,7 @@ static int do_set_group(const struct path *from_path, const struct path *to_pathreturn -EINVAL ;/* Setting sharing groups is only allowed on private mounts */ -if (IS_MNT_SHARED (to) ||IS_MNT_SLAVE (to)) +if (IS_MNT_SHARED (to) ||IS_MNT_SLAVE (to) ||IS_MNT_UNBINDABLE (to))return -EINVAL ;/* From should not be private */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 559/621 riscv: vector: Fix output operands in context save
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aurelien Jarno <[email protected]>
[ Upstream commit 55b1276ef9c1c27e8a2b2c5e8ef0515b5ad0332c ]
The __vstate_csr_save() inline assembly declares vcsr as an output operand while the assembly only writes vstart, vtype, and vl. Remove it as it is later saved by the C code.
--- arch/riscv/include/asm/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/vector.h +2 -2
@@ -131,8 +131,8 @@ static __always_inline void __vstate_csr_save(struct __riscv_v_ext_state *dest) "csrr %0, " __stringify(CSR_VSTART) "\n\t" "csrr %1, " __stringify(CSR_VTYPE) "\n\t" "csrr %2, " __stringify(CSR_VL) "\n\t" - : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl), - "=r" (dest->vcsr) : :); + : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl) + : :);if (has_xtheadvector ()) {unsigned long status;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 560/621 wifi: mt76: dont return TXQ when exceeding max non-AQL packets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Bauer <[email protected]>
[ Upstream commit 964f870e090e9c88a41e2890333421204cc0bdf4 ]
mt76_txq_send_burst does check if the number of non-AQL frames exceeds the maximum. In this case the queue is returned to ieee80211_return_txq when iterating over the scheduled TXQs in mt76_txq_schedule_list.
This has the effect of inserting said TXQ at the head of the list. This means the loop will get the same TXQ again, which will terminate the scheduling round. TXQs following in the list thus never get scheduled for transmission.
This can manifest in high latency low throughput or broken connections for said STAs.
Check if the non-AQL packet count exceeds the limit and not return the TXQ in this case.
Schedule all TXQs for the STA in case the non-AQL limit can be satisfied again.
Stable-dep-of: 752770d7a58c ("wifi: mt76: account non-AQL frames per peer rather than per link")
--- drivers/net/wireless/mediatek/mt76/tx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/net/wireless/mediatek/mt76/tx.c +16 -0
@@ -227,7 +227,9 @@ mt76_tx_check_non_aql(struct mt76_dev *dev, struct mt76_wcid *wcid, struct sk_buff *skb) {struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb); +struct ieee80211_sta *sta;int pending; +int i;if (!wcid || info->tx_time_est)return ;
@@ -235,6 +237,17 @@ mt76_tx_check_non_aql(struct mt76_dev *dev, struct mt76_wcid *wcid, pending =atomic_dec_return (&wcid->non_aql_packets);if (pending <0 )atomic_cmpxchg (&wcid->non_aql_packets, pending,0 ); + + sta =wcid_to_sta (wcid); +if (!sta || pending !=MT_MAX_NON_AQL_PKT -1 ) +return ; + +for (i =0 ; i <ARRAY_SIZE (sta->txq); i++) { +if (!sta->txq[i]) +continue ; + +ieee80211_schedule_txq (dev->hw, sta->txq[i]); + } } void __mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid_idx, struct sk_buff *skb,
@@ -538,6 +551,9 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)if (!wcid ||test_bit (MT_WCID_FLAG_PS , &wcid->flags))continue ; +if (atomic_read (&wcid->non_aql_packets) >=MT_MAX_NON_AQL_PKT ) +continue ; + phy =mt76_dev_phy (dev, wcid->phy_idx);if (test_bit (MT76_RESET , &phy->state) || phy->offchannel)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 561/621 wifi: mac80211: add AQL support for multicast packets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 836c1addd3bf42d47ca5f7a5780a7ec52abf332e ]
Excessive multicast traffic with little competing unicast traffic can easily flood hardware queues, leading to throughput issues. Additionally, filling the hardware queues with too many packets breaks FQ for multicast data. Fix this by enabling AQL for multicast packets.
Stable-dep-of: 752770d7a58c ("wifi: mt76: account non-AQL frames per peer rather than per link")
--- include/net/cfg80211.h | 1 + include/net/mac80211.h | 3 ++- net/mac80211/debugfs.c | 13 ++++++++-- net/mac80211/ieee80211_i.h | 2 ++ net/mac80211/main.c | 1 + net/mac80211/sta_info.c | 17 ++++++++++++- net/mac80211/sta_info.h | 3 ++- net/mac80211/status.c | 5 ++-- net/mac80211/tx.c | 52 ++++++++++++++++++++------------------ 9 files changed, 66 insertions(+), 31 deletions(-)
include/net/cfg80211.h +1 -0
@@ -3655,6 +3655,7 @@ enum wiphy_params_flags {/* The per TXQ device queue limit in airtime */ #define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L 5000#define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H 12000 +#define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_MC 50000/* The per interface airtime threshold to switch to lower queue limit */ #define IEEE80211_AQL_THRESHOLD 24000
include/net/mac80211.h +2 -1
@@ -1212,6 +1212,7 @@ ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *rate)* @status_data: internal data for TX status handling, assigned privately, * see also &enum ieee80211_status_data for the internal documentation * @status_data_idr: indicates status data is IDR allocated ID for ack frame +* @tx_time_mc: TX time estimate is for a multicast frame, used internally * @tx_time_est: TX time estimate in units of 4us, used internally * @control: union part for control data * @control.rates: TX rates array to try
@@ -1249,8 +1250,8 @@ struct ieee80211_tx_info { status_data_idr:1, status_data:13, hw_queue:4, + tx_time_mc:1, tx_time_est:10; -/* 1 free bit */ union { struct {
net/mac80211/debugfs.c +11 -2
@@ -210,11 +210,13 @@ static ssize_t aql_pending_read(struct file *file,"VI %u us\n" "BE %u us\n" "BK %u us\n" +"MC %u us\n" "total %u us\n" ,atomic_read (&local->aql_ac_pending_airtime[IEEE80211_AC_VO ]),atomic_read (&local->aql_ac_pending_airtime[IEEE80211_AC_VI ]),atomic_read (&local->aql_ac_pending_airtime[IEEE80211_AC_BE ]),atomic_read (&local->aql_ac_pending_airtime[IEEE80211_AC_BK ]), +atomic_read (&local->aql_mc_pending_airtime), atomic_read(&local->aql_total_pending_airtime));return simple_read_from_buffer (user_buf, count, ppos, buf, len);
@@ -239,7 +241,8 @@ static ssize_t aql_txq_limit_read(struct file *file,"VO %u %u\n" "VI %u %u\n" "BE %u %u\n" -"BK %u %u\n" , +"BK %u %u\n" +"MC %u\n" , local->aql_txq_limit_low[IEEE80211_AC_VO ], local->aql_txq_limit_high[IEEE80211_AC_VO ], local->aql_txq_limit_low[IEEE80211_AC_VI],
@@ -247,7 +250,8 @@ static ssize_t aql_txq_limit_read(struct file *file, local->aql_txq_limit_low[IEEE80211_AC_BE ], local->aql_txq_limit_high[IEEE80211_AC_BE ], local->aql_txq_limit_low[IEEE80211_AC_BK ], - local->aql_txq_limit_high[IEEE80211_AC_BK]); + local->aql_txq_limit_high[IEEE80211_AC_BK ], + local->aql_txq_limit_mc);return simple_read_from_buffer (user_buf, count, ppos, buf, len); }
@@ -273,6 +277,11 @@ static ssize_t aql_txq_limit_write(struct file *file,else buf[count] ='\0' ; +if (sscanf (buf,"mcast %u" , &q_limit_low) ==1 ) { + local->aql_txq_limit_mc = q_limit_low; +return count; + } +if (sscanf (buf,"%u %u %u" , &ac, &q_limit_low, &q_limit_high) !=3 )return -EINVAL ;
net/mac80211/ieee80211_i.h +2 -0
@@ -1424,10 +1424,12 @@ struct ieee80211_local {spinlock_t handle_wake_tx_queue_lock;u16 airtime_flags; +u32 aql_txq_limit_mc;u32 aql_txq_limit_low[IEEE80211_NUM_ACS ];u32 aql_txq_limit_high[IEEE80211_NUM_ACS ];u32 aql_threshold;atomic_t aql_total_pending_airtime; +atomic_t aql_mc_pending_airtime;atomic_t aql_ac_pending_airtime[IEEE80211_NUM_ACS ];const struct ieee80211_ops *ops;
net/mac80211/main.c +1 -0
@@ -984,6 +984,7 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,spin_lock_init (&local->rx_path_lock);spin_lock_init (&local->queue_stop_reason_lock); + local->aql_txq_limit_mc =IEEE80211_DEFAULT_AQL_TXQ_LIMIT_MC ;for (i =0 ; i <IEEE80211_NUM_ACS ; i++) {INIT_LIST_HEAD (&local->active_txqs[i]);spin_lock_init (&local->active_txq_lock[i]);
net/mac80211/sta_info.c +16 -1
@@ -2440,13 +2440,28 @@ EXPORT_SYMBOL(ieee80211_sta_recalc_aggregates);void ieee80211_sta_update_pending_airtime (struct ieee80211_local *local,struct sta_info *sta,u8 ac, -u16 tx_airtime,bool tx_completed) +u16 tx_airtime,bool tx_completed, +bool mcast) {int tx_pending;if (!wiphy_ext_feature_isset (local->hw.wiphy,NL80211_EXT_FEATURE_AQL ))return ; +if (mcast) { +if (!tx_completed) { +atomic_add (tx_airtime, &local->aql_mc_pending_airtime); +return ; + } + + tx_pending =atomic_sub_return (tx_airtime, + &local->aql_mc_pending_airtime); +if (tx_pending <0 ) +atomic_cmpxchg (&local->aql_mc_pending_airtime, + tx_pending,0 ); +return ; + } +if (!tx_completed) {if (sta) atomic_add(tx_airtime,
net/mac80211/sta_info.h +2 -1
@@ -147,7 +147,8 @@ struct airtime_info {void ieee80211_sta_update_pending_airtime (struct ieee80211_local *local,struct sta_info *sta,u8 ac, -u16 tx_airtime,bool tx_completed); +u16 tx_airtime,bool tx_completed, +bool mcast);struct sta_info ;
net/mac80211/status.c +3 -2
@@ -752,7 +752,7 @@ static void ieee80211_report_used_skb(struct ieee80211_local *local,ieee80211_sta_update_pending_airtime (local, sta,skb_get_queue_mapping (skb), tx_time_est, - true); + true, info->tx_time_mc);rcu_read_unlock (); }
@@ -1161,10 +1161,11 @@ void ieee80211_tx_status_ext(struct ieee80211_hw *hw,/* Do this here to avoid the expensive lookup of the sta * in ieee80211_report_used_skb(). */ +bool mcast =IEEE80211_SKB_CB (skb)->tx_time_mc;ieee80211_sta_update_pending_airtime (local, sta,skb_get_queue_mapping (skb), tx_time_est, - true); + true, mcast);ieee80211_info_set_tx_time_est (IEEE80211_SKB_CB (skb),0 ); }
net/mac80211/tx.c +28 -24
102 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 562/621 wifi: mac80211: add ieee80211_txq_aql_pending()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 9a197e71eb7b45860e37a9f3bdf61a843781ae12 ]
Add a function to allow drivers to query the pending AQL airtime for a given txq, for both unicast and broadcast.
This will be used for mt76 to limit buffering in AP mode for power-save stations.
Stable-dep-of: 752770d7a58c ("wifi: mt76: account non-AQL frames per peer rather than per link")
--- include/net/mac80211.h | 11 +++++++++++ net/mac80211/tx.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+)
include/net/mac80211.h +11 -0
@@ -6607,6 +6607,17 @@ void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid,bool ieee80211_txq_airtime_check (struct ieee80211_hw *hw,struct ieee80211_txq *txq); +/** +* ieee80211_txq_aql_pending - get pending AQL airtime for a txq +* +* @hw: pointer obtained from ieee80211_alloc_hw() +* @txq: pointer obtained from station or virtual interface +* +* Return: pending airtime (in usec) for the given txq. +*/ +u32 ieee80211_txq_aql_pending (struct ieee80211_hw *hw, +struct ieee80211_txq *txq); +/** * ieee80211_iter_keys - iterate keys programmed into the device * @hw: pointer obtained from ieee80211_alloc_hw()
net/mac80211/tx.c +18 -0
@@ -4233,6 +4233,24 @@ bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw, }EXPORT_SYMBOL (ieee80211_txq_airtime_check); +u32 ieee80211_txq_aql_pending (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct sta_info *sta; + +if (unlikely (txq->tid ==IEEE80211_NUM_TIDS )) +return 0 ; + +if (!txq->sta) +return atomic_read (&local->aql_mc_pending_airtime); + + sta = container_of(txq->sta, struct sta_info, sta); + +return atomic_read (&sta->airtime[txq->ac].aql_tx_pending); +} +EXPORT_SYMBOL (ieee80211_txq_aql_pending); +static bool ieee80211_txq_schedule_airtime_check (struct ieee80211_local *local,u8 ac) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 563/621 wifi: mt76: add PS buffering support for HW-managed TIM drivers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit a547b414bf7ea9877456b5630573293cc0e2cae7 ]
Add MT_DRV_HW_PS_BUFFERING flag for drivers where firmware controls the TIM bit based on buffered frames. Instead of blocking all TX to PS stations (which starves firmware and prevents TIM from being set), allow limited frame delivery using AQL pending airtime as the throttle. Replenish the firmware buffer on TX completion.
Add mt76_sta_ps_transition() helper for drivers to call from MCU PS sync events.
Stable-dep-of: 752770d7a58c ("wifi: mt76: account non-AQL frames per peer rather than per link")
--- drivers/net/wireless/mediatek/mt76/mt76.h | 3 + .../wireless/mediatek/mt76/mt76_connac_mcu.h | 1 + drivers/net/wireless/mediatek/mt76/tx.c | 77 +++++++++++++++++-- 3 files changed, 75 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
@@ -533,6 +533,7 @@ struct mt76_hw_cap {#define MT_DRV_HW_MGMT_TXQ BIT(4)#define MT_DRV_AMSDU_OFFLOAD BIT(5)#define MT_DRV_IGNORE_TXS_FAILED BIT(6) +#define MT_DRV_HW_PS_BUFFERING BIT(7)struct mt76_driver_ops {u32 drv_flags;
@@ -1518,6 +1519,8 @@ void mt76_release_buffered_frames(struct ieee80211_hw *hw, u16 tids, int nframes, enum ieee80211_frame_release_type reason, bool more_data); +void mt76_sta_ps_transition (struct mt76_dev *dev,struct mt76_wcid *wcid, +bool ps);bool mt76_has_tx_pending (struct mt76_phy *phy);int mt76_update_channel (struct mt76_phy *phy);void mt76_update_survey (struct mt76_phy *phy);
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +1 -0
@@ -1057,6 +1057,7 @@ enum {MCU_UNI_EVENT_IE_COUNTDOWN =0x09 ,MCU_UNI_EVENT_COREDUMP =0x0a ,MCU_UNI_EVENT_BSS_BEACON_LOSS =0x0c , +MCU_UNI_EVENT_PS_SYNC =0x0d ,MCU_UNI_EVENT_SCAN_DONE =0x0e ,MCU_UNI_EVENT_RDD_REPORT =0x11 , MCU_UNI_EVENT_ROC = 0x27,
drivers/net/wireless/mediatek/mt76/tx.c +71 -6
119 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 564/621 wifi: mt76: account non-AQL frames per peer rather than per link
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 752770d7a58c821c17909c3ca67f9f14ab146a40 ]
The driver increments wcid->non_aql_packets when a frame goes to the hardware queue. The completion path decrements the counter again.
For an MLO peer, the hardware reports the completion on the link that it used for the transmission. This link can differ from the link that the driver queued the frame on. In that case, the increment and the decrement go to different link wcids, and the count drifts upwards until it blocks the station.
Keep the count on the wcid of the primary link, like the other peer-wide state.
--- drivers/net/wireless/mediatek/mt76/mt76.h | 7 +++++++ drivers/net/wireless/mediatek/mt76/tx.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76.h +7 -0
@@ -1403,6 +1403,13 @@ mtxq_to_txq(struct mt76_txq *mtxq) return container_of(ptr, struct ieee80211_txq, drv_priv); } +/* peer-wide state uses the wcid of the primary link */ +static inline struct mt76_wcid * +mt76_wcid_primary (struct mt76_wcid *wcid) +{ +return wcid->def_wcid ? wcid->def_wcid : wcid; +} +static inline struct ieee80211_sta *wcid_to_sta (struct mt76_wcid *wcid) {
drivers/net/wireless/mediatek/mt76/tx.c +8 -3
@@ -234,6 +234,8 @@ mt76_tx_check_non_aql(struct mt76_dev *dev, struct mt76_wcid *wcid,if (!wcid || info->tx_time_est)return ; + wcid =mt76_wcid_primary (wcid); + pending =atomic_dec_return (&wcid->non_aql_packets);if (pending <0 )atomic_cmpxchg (&wcid->non_aql_packets, pending,0 );
@@ -344,7 +346,8 @@ __mt76_tx_queue_skb(struct mt76_phy *phy, int qid, struct sk_buff *skb,if (!non_aql)return idx; - pending =atomic_inc_return (&wcid->non_aql_packets); +/* the hardware can report the completion on a different link */ + pending =atomic_inc_return (&mt76_wcid_primary (wcid)->non_aql_packets);if (stop && pending >=MT_MAX_NON_AQL_PKT ) *stop = true;
@@ -498,7 +501,8 @@ mt76_txq_send_burst(struct mt76_phy *phy, struct mt76_queue *q,return 0 ; } -if (atomic_read (&wcid->non_aql_packets) >=MT_MAX_NON_AQL_PKT ) +if (atomic_read (&mt76_wcid_primary (wcid)->non_aql_packets) >= +MT_MAX_NON_AQL_PKT )return 0 ; skb =mt76_txq_dequeue (phy, mtxq);
@@ -595,7 +599,8 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)continue ; } -if (atomic_read (&wcid->non_aql_packets) >=MT_MAX_NON_AQL_PKT ) +if (atomic_read (&mt76_wcid_primary (wcid)->non_aql_packets) >= +MT_MAX_NON_AQL_PKT )continue ;if (dev->queue_ops->tx_cleanup && q->queued +2 *MT_TXQ_FREE_THR >= q->ndesc) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 565/621 wifi: mt76: route nullfunc frames to PSD/ALTX queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 331e766e75d2a64b5c1f38aadfcfcf31d264f43e ]
ieee80211_is_data() returns true for nullfunc/QoS-nullfunc frames, so they bypass the PSD queue routing and go through the regular VO data queue. This means firmware processes them through the normal TID queue instead of the ALTX queue, which doesn't guarantee immediate transmission.
Use ieee80211_is_data_present() instead, which returns false for both management frames and nullfunc/QoS-nullfunc (no payload), routing them to MT_TXQ_PSD. Firmware maps PSD to the ALTX queue, which transmits immediately without PS buffering.
This only affects frames from the mt76_tx() pending path. Regular mac80211 TXQ scheduling is unchanged.
Stable-dep-of: 7c2e6b43c308 ("wifi: mt76: use ALTX queue for packets to disassociated stations")
--- drivers/net/wireless/mediatek/mt76/tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/tx.c +1 -1
@@ -671,7 +671,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid, if ((dev->drv->drv_flags & MT_DRV_HW_MGMT_TXQ) && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) && - !ieee80211_is_data(hdr->frame_control) && + !ieee80211_is_data_present(hdr->frame_control) && (!ieee80211_is_bufferable_mmpdu(skb) || ieee80211_is_deauth(hdr->frame_control) || ieee80211_is_disassoc(hdr->frame_control) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 566/621 wifi: mt76: use ALTX queue for packets to disassociated stations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 7c2e6b43c3082c2242ecfa5875b2b4b2cd06140f ]
Running these packets through regular buffering queues could cause them to hang, especially when the packets were for stations that in disassoc state.
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt7996/main.c | 1 + drivers/net/wireless/mediatek/mt76/tx.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +2 -0
@@ -802,6 +802,7 @@ __mt7915_drop_sta(void *ptr, u8 *mac, struct ieee80211_vif *vif) msta = (struct mt7915_sta *)sta->drv_priv;mt7915_mcu_add_sta (data->dev, vif, sta,CONN_STATE_DISCONNECT , false); + msta->wcid.tx_info &= ~MT_WCID_TX_INFO_SET ; msta->wcid.sta_disabled =1 ; msta->wcid.sta =0 ; }
@@ -866,6 +867,7 @@ int mt7915_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,mt7915_mac_twt_teardown_flow (dev, msta, i);mt7915_mcu_add_sta (dev, vif, sta,CONN_STATE_DISCONNECT , false); + msta->wcid.tx_info &= ~MT_WCID_TX_INFO_SET ; msta->wcid.sta_disabled =1 ; msta->wcid.sta =0 ;return 0 ;
drivers/net/wireless/mediatek/mt76/mt7996/main.c +1 -0
@@ -1274,6 +1274,7 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,else if (sta->mlo && links ==BIT (link_id))/* last link */ mt7996_mcu_teardown_mld_sta (dev, link, msta_link); + msta_link->wcid.tx_info &= ~MT_WCID_TX_INFO_SET ; msta_link->wcid.sta_disabled =1 ; msta_link->wcid.sta =0 ; links = links & ~BIT (link_id);
drivers/net/wireless/mediatek/mt76/tx.c +2 -1
@@ -672,7 +672,8 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,if ((dev->drv->drv_flags &MT_DRV_HW_MGMT_TXQ ) && !(info->flags &IEEE80211_TX_CTL_HW_80211_ENCAP ) && !ieee80211_is_data_present (hdr->frame_control) && - (!ieee80211_is_bufferable_mmpdu (skb) || + (!(wcid->tx_info &MT_WCID_TX_INFO_SET ) || + !ieee80211_is_bufferable_mmpdu (skb) ||ieee80211_is_deauth (hdr->frame_control) ||ieee80211_is_disassoc (hdr->frame_control) || head == &wcid->tx_offchannel))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 567/621 wifi: mt76: mt7925: restore the legacy BSS after MLO teardown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aaron Ma <[email protected]>
[ Upstream commit 8f9e5807671ee97cacf1957f4a09e43f4f1017a9 ]
Removing the last link of an MLD interface leaves the firmware with the MLD BSS and DEV entry: the removal loop skips the deflink, and the hweight16(mvif->valid_links) fallback reads the stale pre-update valid_links, which is still non-zero. The entry keeps the per-link MAC address, so every subsequent legacy association fails authentication until the interface is removed or the module is reloaded.
Remove the deflink BSS and add it back as a legacy BSS on the transition to zero links.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +12 -0
@@ -2089,6 +2089,18 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mvif->valid_links = new_links; +/* Restore the legacy BSS after disabling MLO */ +if (old_links && !new_links) { +mt792x_mac_link_bss_remove (dev, &mvif->bss_conf, + &mvif->sta.deflink); + err =mt7925_mac_link_bss_add (dev, &vif->bss_conf, + &mvif->sta.deflink); +if (err <0 ) { +mt792x_mutex_release (dev); +return err; + } + } +mt792x_mutex_release (dev);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 568/621 wifi: mt76: mt7996: fix struct mt7996_mcu_wed_rro_ba_delete_event layout
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Gong <[email protected]>
[ Upstream commit 9c9e4e4c8b45873e53774ab8207825b37b7565ec ]
Correct the definition of struct mt7996_mcu_wed_rro_ba_delete_event to match the 12-byte event record layout observed from firmware.
The event TLV sent by firmware is 12 bytes in length rather than 8 bytes. It contains an additional 4 bytes that appear to be wlan_id and tid. For example, a captured batch deletion of sessions 8, 9, and 10 (TIDs 6, 0, and 1) shows:
00000000: 02 00 0c 00 08 00 01 00 06 00 00 00 02 00 0c 00 00000010: 09 00 01 00 00 00 00 00 02 00 0c 00 0a 00 01 00 00000020: 01 00 00 00
The previous 8-byte structure corrupts the parsing of subsequent TLVs, leading to unhandled delete events and erroneous session deletions. Consequently, clients that create and tear down BA sessions in batches (such as Apple Wi-Fi clients) fail to properly clean up stale sessions, causing HW_RRO to be lost upon subsequent reassociations.
--- drivers/net/wireless/mediatek/mt76/mt7996/mcu.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +3 -0
@@ -249,6 +249,9 @@ struct mt7996_mcu_wed_rro_ba_delete_event {__le16 len;__le16 session_id; +__le16 wlan_id; +u8 tid; +u8 __rsv1;u8 __rsv2[2 ]; } __packed;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 533/621 fs: move mntput_no_expire() slowpath into a dedicated routine
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mateusz Guzik <[email protected]>
[ Upstream commit bfef6e1f3488fc09ae966cb4dd2cb09f73cff791 ]
In the stock variant the compiler spills several registers on the stack and employs stack smashing protection, adding even more code + a branch on exit..
The actual fast path is small enough that the compiler inlines it for all callers -- the symbol is no longer emitted.
Forcing noinline on it just for code-measurement purposes shows the fast path dropping from 111 to 39 bytes.
Stable-dep-of: 7eb84d54fac5 ("fs: don't let a migrating task hide its reference from do_umount()")
--- fs/namespace.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
fs/namespace.c +22 -16
@@ -1342,26 +1342,12 @@ static void delayed_mntput(struct work_struct *unused) } static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput); -static void mntput_no_expire (struct mount *mnt) +static void noinline mntput_no_expire_slowpath(struct mount *mnt) {LIST_HEAD (list);int count; -rcu_read_lock (); -if (likely (READ_ONCE (mnt->mnt_ns))) { -/* -* Since we don't do lock_mount_hash() here, -* ->mnt_ns can change under us. However, if it's -* non-NULL, then there's a reference that won't -* be dropped until after an RCU delay done after -* turning ->mnt_ns NULL. So if we observe it -* non-NULL under rcu_read_lock(), the reference -* we are dropping is not the final one. -*/ -mnt_add_count (mnt,-1 ); -rcu_read_unlock (); -return ; - } +VFS_BUG_ON (mnt->mnt_ns);lock_mount_hash ();/* * make sure that if __legitimize_mnt() has not seen us grab
@@ -1412,6 +1398,26 @@ static void mntput_no_expire(struct mount *mnt)cleanup_mnt (mnt); } +static void mntput_no_expire (struct mount *mnt) +{ +rcu_read_lock (); +if (likely (READ_ONCE (mnt->mnt_ns))) { +/* +* Since we don't do lock_mount_hash() here, +* ->mnt_ns can change under us. However, if it's +* non-NULL, then there's a reference that won't +* be dropped until after an RCU delay done after +* turning ->mnt_ns NULL. So if we observe it +* non-NULL under rcu_read_lock(), the reference +* we are dropping is not the final one. +*/ +mnt_add_count (mnt,-1 ); +rcu_read_unlock (); +return ; + } +mntput_no_expire_slowpath (mnt); +} +void mntput (struct vfsmount *mnt) {if (mnt) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 569/621 wifi: mt76: mt7915: disable rx napi when removing device
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Cavallari <[email protected]>
[ Upstream commit 916c484d29d82f45c281da2786fcd6a1284430ce ]
Unloading the mt7915e module with a MT7916 triggers multiples WARN in __netif_napi_del_locked() and in page_pool_disable_direct_recycling() because the driver does not disable the napi before destroying it.
This is troublesome since on MT7916 it is required to unload the module and reinsert it with a different enable_6ghz parameter to change the frequency. The system generally becomes unstable after reinserting the module.
Fix it by disabling rx napi inside mt7915e itself, even through napi rx is enabled in the mt76 generic code. Disabling it in the mt76 generic code was previously attempted and reverted because napi was disabled too late and rx handlers could access freed structures. Note that the tx side is enabled and disabled by the mt76 generic code.
It is disabled in mt7915_stop_hardware() since, unlike mt7915_unregister_device(), is it also called in the probe path if an error happens after rx napi is enabled.
--- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +6 -0
@@ -1201,6 +1201,12 @@ static void mt7915_unregister_ext_phy(struct mt7915_dev *dev)static void mt7915_stop_hardware (struct mt7915_dev *dev) { +int i; + +mt76_for_each_q_rx (&dev->mt76, i) { +if (!mt76_queue_is_wed_rro (&dev->mt76.q_rx[i])) +napi_disable (&dev->mt76.napi[i]); + }mt7915_mcu_exit (dev);mt76_connac2_tx_token_put (&dev->mt76);mt7915_dma_cleanup (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 570/621 wifi: mt76: mt7925: dont put the band auto marker in TGID
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 5796b2bf9ff718342773ac760d86eb126c112a4f ]
band_idx starts out as 0xff, which tells the firmware to pick the band on its own. A remain-on-channel grant normally writes a real index over it before anything else looks. Two cases never see that: an MLD station throws the grant away, and an AP has no association to trigger one.
The TX descriptor reads the same field into a two-bit slot, so the marker comes out as 3. Every data frame from those two goes out tagged band 3. Beacons are fine, they reach the firmware separately and never build a descriptor.
Same numbers on an MT7925 and on a Netgear A9000:
stock patched station, one link 0x00000001 0x00000001 station, two links 0x00003001 0x00000001 AP 0x00003013 0x00000013 real band index, STA 0x00001001 0x00001001 real band index, AP 0x00001013 0x00001013
Only the marker cases move.
--- drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +2 -1
@@ -780,7 +780,8 @@ mt7925_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi, val =FIELD_PREP (MT_TXD1_WLAN_IDX , wcid->idx) |FIELD_PREP (MT_TXD1_OWN_MAC , omac_idx); -if (band_idx) +/* 0xff means BAND_AUTO to the firmware, and TGID cannot encode it */ +if (band_idx && band_idx !=0xff ) val |=FIELD_PREP (MT_TXD1_TGID , band_idx); txwi[1 ] =cpu_to_le32 (val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 571/621 wifi: mt76: mt792x: treat 0xff ACPI SAR entries as no limit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junjie Cao <[email protected]>
[ Upstream commit 45f53d98cbaa078907b6a300ff3974dfb5ae8776 ]
Some ASUS firmware carries 0xff in MTGS power slots. The driver narrows the byte to s8, so the slot reads as -1 in its 0.5 dBm units, wins the min() against the regulatory limit and caps every rate the driver programs. On an ASUS Zenbook 14 UM3406HA (MT7922) all six MTGS tables hold 0xff in every power byte, and txpower_sku shows tmac 3 on every supported OFDM/HT/VHT/HE rate against EEPROM entries of 25-39, under both the FR and the world regulatory domain. Huy Nguyen Dinh Quang saw the same clamp on a Vivobook S 14 M5406WA, with 5 GHz TX at ~40 Mbps, and proposed skipping the geo entry.
Skip a geo entry whose power byte is 0xff. The MTDS entry is narrowed the same way on its way into the geo lookup, so give it the same treatment, and clamp the dynamic value plus offset at 127 so a no-limit entry cannot wrap.
--- .../wireless/mediatek/mt76/mt792x_acpi_sar.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c +14 -4
@@ -279,10 +279,18 @@ mt792x_asar_get_geo_pwr(struct mt792x_phy *phy,if (idx >= max)return dyn_power; - geo_power = (band_pwr + idx)->pwr; - dyn_power += (band_pwr + idx)->offset; + band_pwr += idx; -return min (geo_power, dyn_power); +/* Some OEM tables carry 0xff here; narrowed to s8 that is -1 and +* wins the min() below. Take it as no limit. +*/ +if (band_pwr->pwr ==0xff ) +return dyn_power; + + geo_power = band_pwr->pwr; + +return min_t (int, geo_power, +min_t (int, dyn_power + band_pwr->offset,127 )); } static s8
@@ -315,7 +323,9 @@ mt792x_asar_range_pwr(struct mt792x_phy *phy,else band =NL80211_BAND_2GHZ ; -return mt792x_asar_get_geo_pwr (phy, band, limit[idx]); +/* 0xff: no dynamic limit, see mt792x_asar_get_geo_pwr() */ +return mt792x_asar_get_geo_pwr (phy, band, + limit[idx] ==0xff ?127 : limit[idx]); }int mt792x_init_acpi_sar_power (struct mt792x_phy *phy,bool set_default)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 572/621 wifi: mt76: mt792x: pick the SAR table layout from the table itself
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit af97bf5a7e72da9026de184676df8e2fa57e1058 ]
The SAR power tables are parsed with a version byte from a different ACPI table, never their own.
Some firmware declares version 1 and ships version 2 tables. The entries then start a byte early, and the 6 GHz limits the table carries are dropped, because the older layout has no room for them.
ASUS GA503RM, MTCL declares v1:
MTGS 28 bytes v1: (28-6) % 5 = 2, no fit v2: 3 tables MTDS 19 bytes v1: (19-6) % 6 = 1, no fit v2: 1 table
The layouts accept disjoint lengths, so take whichever one fits and keep it per table.
--- .../wireless/mediatek/mt76/mt792x_acpi_sar.c | 110 +++++++++++------- .../wireless/mediatek/mt76/mt792x_acpi_sar.h | 2 + 2 files changed, 73 insertions(+), 39 deletions(-)
drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c +71 -39
@@ -108,68 +108,98 @@ mt792x_asar_acpi_read_mtcl(struct mt792x_dev *dev, u8 **table, u8 *version)return ret; } +/* A table's layout is decided by the version byte in MTCL, but some firmware +* labels a version 2 table as version 1. Accept whichever layout the table +* actually has: for every accepted entry count the two do not overlap, since +* one is 6 + 5n bytes and the other 7 + 7n. +*/ +static bool +mt792x_asar_fits (u8 *table,int len,int prelen,int sarlen,int nr_off, +int min,int max) +{ +int tblcnt; + +if (len < prelen || (len - prelen) % sarlen) +return false; + + tblcnt = (len - prelen) / sarlen; +if (tblcnt < min || tblcnt > max) +return false; + +return tblcnt == table[nr_off]; +} +/* MTDS : Dynamic SAR Power Table */ static int -mt792x_asar_acpi_read_mtds (struct mt792x_dev *dev,u8 **table,u8 version) +mt792x_asar_acpi_read_mtds (struct mt792x_dev *dev,u8 **table,u8 version, +u8 *used) { -int len, ret, sarlen, prelen, tblcnt; -bool enable; +int len, ret; +u8 *t; ret =mt792x_acpi_read (dev, MT792x_ACPI_MTDS, table, &len);if (ret)return ret; + t = *table; +/* Table content validation */ -switch (version) { -case 1 : - enable = ((struct mt792x_asar_dyn *)*table)->enable; - sarlen =sizeof (struct mt792x_asar_dyn_limit ); - prelen =sizeof (struct mt792x_asar_dyn ); -break ; -case 2 : - enable = ((struct mt792x_asar_dyn_v2 *)*table)->enable; - sarlen =sizeof (struct mt792x_asar_dyn_limit_v2 ); - prelen =sizeof (struct mt792x_asar_dyn_v2 ); -break ; -default : +if (mt792x_asar_fits (t, len,sizeof (struct mt792x_asar_dyn ), +sizeof (struct mt792x_asar_dyn_limit ), + offsetof(struct mt792x_asar_dyn , nr_tbl), + MT792x_ASAR_MIN_DYN, MT792x_ASAR_MAX_DYN)) + *used =1 ; +else if (mt792x_asar_fits (t, len,sizeof (struct mt792x_asar_dyn_v2 ), +sizeof (struct mt792x_asar_dyn_limit_v2 ), + offsetof(struct mt792x_asar_dyn_v2 , nr_tbl), + MT792x_ASAR_MIN_DYN, MT792x_ASAR_MAX_DYN)) + *used =2 ; +else return -EINVAL ; - } - tblcnt = (len - prelen) / sarlen; -if (!enable || - tblcnt > MT792x_ASAR_MAX_DYN || tblcnt < MT792x_ASAR_MIN_DYN) +if (!t[offsetof(struct mt792x_asar_dyn , enable)])return -EINVAL ; +if (version && *used != version) +dev_info (dev->mt76.dev, +"MTDS is v%u, MTCL says v%u; using v%u\n" , + *used, version, *used); +return 0 ; }/* MTGS : Geo SAR Power Table */ static int -mt792x_asar_acpi_read_mtgs (struct mt792x_dev *dev,u8 **table,u8 version) +mt792x_asar_acpi_read_mtgs (struct mt792x_dev *dev,u8 **table,u8 version, +u8 *used) { -int len, ret, sarlen, prelen, tblcnt; +int len, ret; +u8 *t; ret =mt792x_acpi_read (dev, MT792x_ACPI_MTGS, table, &len);if (ret)return ret; + t = *table; +/* Table content validation */ -switch (version) { -case 1 : - sarlen =sizeof (struct mt792x_asar_geo_limit ); - prelen =sizeof (struct mt792x_asar_geo ); -break ; -case 2 : - sarlen =sizeof (struct mt792x_asar_geo_limit_v2 ); - prelen =sizeof (struct mt792x_asar_geo_v2 ); -break ; -default : +if (mt792x_asar_fits (t, len,sizeof (struct mt792x_asar_geo ), +sizeof (struct mt792x_asar_geo_limit ), + offsetof(struct mt792x_asar_geo , nr_tbl), + MT792x_ASAR_MIN_GEO, MT792x_ASAR_MAX_GEO)) + *used =1 ; +else if (mt792x_asar_fits (t, len,sizeof (struct mt792x_asar_geo_v2 ), +sizeof (struct mt792x_asar_geo_limit_v2 ), + offsetof(struct mt792x_asar_geo_v2 , nr_tbl), + MT792x_ASAR_MIN_GEO, MT792x_ASAR_MAX_GEO)) + *used =2 ; +else return -EINVAL ; - } - tblcnt = (len - prelen) / sarlen; -if (tblcnt > MT792x_ASAR_MAX_GEO || tblcnt < MT792x_ASAR_MIN_GEO) -return -EINVAL ; +if (version && *used != version) +dev_info (dev->mt76.dev, +"MTGS is v%u, MTCL says v%u; using v%u\n" , + *used, version, *used);return 0 ; }
@@ -205,14 +235,16 @@ int mt792x_init_acpi_sar(struct mt792x_dev *dev) asar->countrylist =NULL ; } - ret =mt792x_asar_acpi_read_mtds (dev, (u8 **)&asar->dyn, asar->ver); + ret =mt792x_asar_acpi_read_mtds (dev, (u8 **)&asar->dyn, asar->ver, + &asar->dyn_ver);if (ret) {devm_kfree (dev->mt76.dev, asar->dyn); asar->dyn =NULL ; }/* MTGS is optional */ - ret =mt792x_asar_acpi_read_mtgs (dev, (u8 **)&asar->geo, asar->ver); + ret =mt792x_asar_acpi_read_mtgs (dev, (u8 **)&asar->geo, asar->ver, + &asar->geo_ver);if (ret) {devm_kfree (dev->mt76.dev, asar->geo); asar->geo =NULL ;
@@ -254,7 +286,7 @@ mt792x_asar_get_geo_pwr(struct mt792x_phy *phy,break ; } -if (asar->ver ==1 ) { +if (asar->geo_ver ==1 ) { band_pwr = &asar->geo->tbl[idx].band[0 ]; max =ARRAY_SIZE (asar->geo->tbl[idx].band); }else {
@@ -305,7 +337,7 @@ mt792x_asar_range_pwr(struct mt792x_phy *phy,if (!capa)return 127 ; -if (asar->ver ==1 ) { +if (asar->dyn_ver ==1 ) { limit = &asar->dyn->tbl[0 ].frp[0 ]; max =ARRAY_SIZE (asar->dyn->tbl[0 ].frp); }else {
drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h +2 -0
@@ -105,6 +105,8 @@ struct mt792x_asar_fg {struct mt792x_acpi_sar {u8 ver; +u8 dyn_ver; +u8 geo_ver;union {struct mt792x_asar_dyn *dyn;struct mt792x_asar_dyn_v2 *dyn_v2;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 573/621 Revert "wifi: ath12k: add panic handler"
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingying Tang <[email protected]>
[ Upstream commit 05165f7b3b9ab6817fe216c24f90755b7c5e15f3 ]
ath12k_core_panic_handler() is invoked via atomic_notifier_call_chain(), which runs inside an RCU read-side critical section. The current code calls ath12k_pci_sw_reset() synchronously from this context, which eventually reaches mhi_device_get_sync() and schedule_timeout(), triggering a voluntary context switch within RCU.
Call trace: rcu_note_context_switch+0x4c4/0x508 (P) __schedule+0xbc/0x1204 schedule+0x34/0x110 schedule_timeout+0x84/0x11c __mhi_device_get_sync+0x164/0x228 [mhi] mhi_device_get_sync+0x1c/0x3c [mhi] ath12k_wifi7_pci_bus_wake_up+0x20/0x2c [ath12k_wifi7] ath12k_pci_read32+0x58/0x350 [ath12k] ath12k_pci_clear_dbg_registers+0x28/0xb8 [ath12k] ath12k_pci_panic_handler+0x20/0x44 [ath12k] ath12k_core_panic_handler+0x28/0x3c [ath12k] notifier_call_chain+0x78/0x1c0 atomic_notifier_call_chain+0x3c/0x5c
Revert change "wifi: ath12k: add panic handler" to avoid this issue.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3
--- drivers/net/wireless/ath/ath12k/core.c | 33 +------------------------- drivers/net/wireless/ath/ath12k/core.h | 3 --- drivers/net/wireless/ath/ath12k/hif.h | 9 ------- drivers/net/wireless/ath/ath12k/pci.c | 8 ------- 4 files changed, 1 insertion(+), 52 deletions(-)
drivers/net/wireless/ath/ath12k/core.c +1 -32
@@ -1733,29 +1733,6 @@ int ath12k_core_pre_init(struct ath12k_base *ab)return 0 ; } -static int ath12k_core_panic_handler (struct notifier_block *nb, -unsigned long action,void *data) -{ - struct ath12k_base *ab = container_of(nb, struct ath12k_base, - panic_nb); - -return ath12k_hif_panic_handler (ab); -} - -static int ath12k_core_panic_notifier_register (struct ath12k_base *ab) -{ - ab->panic_nb.notifier_call = ath12k_core_panic_handler; - -return atomic_notifier_chain_register (&panic_notifier_list, - &ab->panic_nb); -} - -static void ath12k_core_panic_notifier_unregister (struct ath12k_base *ab) -{ -atomic_notifier_chain_unregister (&panic_notifier_list, - &ab->panic_nb); -} -static inline bool ath12k_core_hw_group_create_ready (struct ath12k_hw_group *ag) {
@@ -2148,18 +2125,13 @@ int ath12k_core_init(struct ath12k_base *ab)struct ath12k_hw_group *ag;int ret; - ret =ath12k_core_panic_notifier_register (ab); -if (ret) -ath12k_warn (ab,"failed to register panic handler: %d\n" , ret); -mutex_lock (&ath12k_hw_group_mutex); ag =ath12k_core_hw_group_assign (ab);if (!ag) {mutex_unlock (&ath12k_hw_group_mutex);ath12k_warn (ab,"unable to get hw group\n" ); - ret = -ENODEV ; - goto err_unregister_notifier; +return -ENODEV ; }mutex_unlock (&ath12k_hw_group_mutex);
@@ -2184,8 +2156,6 @@ int ath12k_core_init(struct ath12k_base *ab) err_unassign_hw_group:ath12k_core_hw_group_unassign (ab); -err_unregister_notifier: -ath12k_core_panic_notifier_unregister (ab);return ret; }
@@ -2194,7 +2164,6 @@ void ath12k_core_deinit(struct ath12k_base *ab) {ath12k_core_hw_group_destroy (ab->ag);ath12k_core_hw_group_unassign (ab); -ath12k_core_panic_notifier_unregister (ab); }void ath12k_core_free (struct ath12k_base *ab)
drivers/net/wireless/ath/ath12k/core.h +0 -3
@@ -15,7 +15,6 @@#include <linux/ctype.h> #include <linux/firmware.h> #include <linux/of_reserved_mem.h> -#include <linux/panic_notifier.h> #include <linux/average.h> #include <linux/of.h> #include "qmi.h"
@@ -1221,8 +1220,6 @@ struct ath12k_base {#endif /* CONFIG_ACPI */ -struct notifier_block panic_nb; -struct ath12k_hw_group *ag;struct ath12k_wsi_info wsi_info;enum ath12k_firmware_mode fw_mode;
drivers/net/wireless/ath/ath12k/hif.h +0 -9
@@ -30,7 +30,6 @@ struct ath12k_hif_ops {void (*ce_irq_enable)(struct ath12k_base *ab);void (*ce_irq_disable)(struct ath12k_base *ab);void (*get_ce_msi_idx)(struct ath12k_base *ab,u32 ce_id,u32 *msi_idx); -int (*panic_handler)(struct ath12k_base *ab);void (*coredump_download)(struct ath12k_base *ab); };
@@ -149,14 +148,6 @@ static inline void ath12k_hif_power_down(struct ath12k_base *ab, bool is_suspend ab->hif.ops->power_down (ab, is_suspend); } -static inline int ath12k_hif_panic_handler (struct ath12k_base *ab) -{ -if (!ab->hif.ops->panic_handler) -return NOTIFY_DONE ; - -return ab->hif.ops->panic_handler (ab); -} -static inline void ath12k_hif_coredump_download (struct ath12k_base *ab) {if (ab->hif.ops->coredump_download)
drivers/net/wireless/ath/ath12k/pci.c +0 -8
@@ -1523,13 +1523,6 @@ void ath12k_pci_power_down(struct ath12k_base *ab, bool is_suspend)ath12k_pci_sw_reset (ab_pci->ab, false); } -static int ath12k_pci_panic_handler (struct ath12k_base *ab) -{ -ath12k_pci_sw_reset (ab, false); - -return NOTIFY_OK ; -} -static const struct ath12k_hif_ops ath12k_pci_hif_ops = { .start = ath12k_pci_start, .stop = ath12k_pci_stop,
@@ -1547,7 +1540,6 @@ static const struct ath12k_hif_ops ath12k_pci_hif_ops = { .ce_irq_enable = ath12k_pci_hif_ce_irq_enable, .ce_irq_disable = ath12k_pci_hif_ce_irq_disable, .get_ce_msi_idx = ath12k_pci_get_ce_msi_idx, - .panic_handler = ath12k_pci_panic_handler,#ifdef CONFIG_ATH12K_COREDUMP .coredump_download = ath12k_pci_coredump_download,#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 574/621 ASoC: adau1372: allow sleepy powerdown GPIOs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alvin Šipraga <[email protected]>
[ Upstream commit 64dd172bbffe6135d79a06ddad53dd2da4d8bd62 ]
gpiod_set_value() emits a WARN when the GPIO provider indicates that it can sleep, as is typical for I2C controlled GPIO expanders. Since the powerdown GPIO is only manipulated in process context, use the _cansleep variant instead. This lets the driver use sleepy GPIOs to power off the chip.
--- sound/soc/codecs/adau1372.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sound/soc/codecs/adau1372.c +3 -4
@@ -799,7 +799,7 @@ static int adau1372_set_power(struct adau1372 *adau1372, bool enable)if (ret)return ret;if (adau1372->pd_gpio) -gpiod_set_value (adau1372->pd_gpio,0 ); +gpiod_set_value_cansleep (adau1372->pd_gpio,0 );if (adau1372->switch_mode) adau1372->switch_mode (adau1372->dev);
@@ -819,8 +819,7 @@ static int adau1372_set_power(struct adau1372 *adau1372, bool enable)ADAU1372_CLK_CTRL_PLL_EN , 0);regcache_cache_only (adau1372->regmap, true); -if (adau1372->pd_gpio) -gpiod_set_value (adau1372->pd_gpio,1 ); +gpiod_set_value_cansleep (adau1372->pd_gpio,1 );clk_disable_unprepare (adau1372->mclk);return ret; }
@@ -837,7 +836,7 @@ static int adau1372_set_power(struct adau1372 *adau1372, bool enable)* map. No need to do any register writes to manually * turn things off. */ -gpiod_set_value (adau1372->pd_gpio,1 ); +gpiod_set_value_cansleep (adau1372->pd_gpio,1 );regcache_mark_dirty (adau1372->regmap); }else { regmap_update_bits(adau1372->regmap, ADAU1372_REG_CLK_CTRL,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 575/621 ASoC: adau1372: fix invalid default state of output ASRC and DAC muxes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alvin Šipraga <[email protected]>
[ Upstream commit 36d0e05815ce84266c8b138cd4f84c3feeaf15f4 ]
The chip has strange power-on reset values for the registers that control the output ASRC and DAC source muxes - the values are actually marked "Reserved" in the datasheet [1]. This means that until the underlying kcontrols are modified, the codec will not function as expected.
The registers in question are:
register / field reset value valid values
ASRCO_SOURCE_0_1 0x10 ASRC_OUT_SOURCE0 0 4 .. 16 ASRC_OUT_SOURCE1 1 4 .. 16 ASRCO_SOURCE_2_3 0x10 ASRC_OUT_SOURCE2 2 4 .. 16 ASRC_OUT_SOURCE3 3 4 .. 16 DAC_SOURCE_0_1 0x10 DAC_SOURCE_0 0 12 .. 13 DAC_SOURCE_1 1 12 .. 13
Set some sane defaults during the driver probe:
ADC Decimator0 -> Output ASRC0
ADC Decimator1 -> Output ASRC1
ADC Decimator2 -> Output ASRC2
ADC Decimator3 -> Output ASRC3
Input ASRC0 -> DAC0
Input ASRC1 -> DAC1
With this, the chip will behave as advertised by the default kcontrol state exposed by the driver.
[1] https://www.analog.com/media/en/technical-documentation/data-sheets/ADAU1372.pdf
--- sound/soc/codecs/adau1372.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
sound/soc/codecs/adau1372.c +11 -0
@@ -1003,6 +1003,17 @@ int adau1372_probe(struct device *dev, struct regmap *regmap,regmap_write (regmap,ADAU1372_REG_OP_STAGE_MUTE ,0x0 ); +/* +* Set sane default values for the Output ASRC and DAC input muxes, +* since the power-on reset defaults are invalid "Reserved" states. +*/ +regmap_write (regmap,ADAU1372_REG_ASRCO_SOURCE_0_1 , +0x54 );/* Decimator0, Decimator1 */ +regmap_write (regmap,ADAU1372_REG_ASRCO_SOURCE_2_3 , +0x76 );/* Decimator2, Decimator3 */ +regmap_write (regmap,ADAU1372_REG_DAC_SOURCE , +0xdc );/* Input ASRC0, Input ASRC1 */ +regmap_write (regmap,0x7 ,0x01 );/* CLOCK OUT */ return devm_snd_soc_register_component (dev, &adau1372_driver, &adau1372_dai_driver,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 534/621 fs: dont let a migrating task hide its reference from do_umount()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 7eb84d54fac5002bd975d1de8fd61d57e89172ab ]
propagate_mount_busy() uses mnt_get_count() via do_refcount_check() to figure out whether a synchronous umount may proceed or not by summing the per-CPU mnt_count counter under mount_lock.
The fastpath for mntget() and mntput() doesn't require that lock. A task that already holds a reference and takes another one on a cpu the loop has summed can get migrated and drops that reference again on another cpu. The loop might not have reached that cpu yet. That ends up undercounting. The original reference of the task is missed and umount() ends up succeeding with the file still open. The mount is destroyed later when the task mntput()s so it degrades to a lazy umount.
That's basically the umount(2) variant of commit 9ea0a46ca2c3 ("fix mntput/mntput race") closed for the final mntput(). The same cpu-migration caused a UAF.
Luckily this isn't a UAF. It's just a hidden reference pinning the mount but it's wrong nonetheless.
Like the other race it's a narrow window but I can reproduce it reliably with some patching. The debug patch below prints the sum the loop computed next to an immediate re-sum of the same counters. It reports who drops the last reference to that mount later:
# --- a/fs/namespace.c # +++ b/fs/namespace.c # @@ -34,6 +34,8 @@ # #include <linux/mnt_idmapping.h> # #include <linux/pidfs.h> # #include <linux/nstree.h>
# +#include <linux/debugfs.h>
# +#include <linux/delay.h>
#
# #include "pnode.h"
# #include "internal.h"
# @@ -263,17 +265,48 @@
# #endif
# }
#
# +static u32 mnt_get_count_delay_ms;
# +static int mnt_get_count_debug_id;
# +
# +static int __init mnt_get_count_debug_init(void)
# +{
# + debugfs_create_u32("mnt_get_count_delay_ms", 0600, NULL,
# + &mnt_get_count_delay_ms);
# + return 0;
# +}
# +late_initcall(mnt_get_count_debug_init);
# +
# /*
# * vfsmount lock must be held for write
# */
# int mnt_get_count(struct mount *mnt)
# {
# #ifdef CONFIG_SMP
# - int count = 0;
# + static int seen[NR_CPUS];
# + bool slow = mnt_get_count_delay_ms &&
# + !(mnt->mnt.mnt_flags & MNT_UMOUNT);
# + int count = 0, again = 0;
# int cpu;
#
# for_each_possible_cpu(cpu) {
# - count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count;
# + seen[cpu] = per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count;
# + count += seen[cpu];
# + if (slow)
# + mdelay(mnt_get_count_delay_ms);
# + }
# + if (slow) {
# + for_each_possible_cpu(cpu) {
# + int now;
# +
# + now = per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count;
# + again += now;
# + pr_err("mount %d: cpu%d read %d, now %d\n",
# + mnt->mnt_id, cpu, seen[cpu], now);
# + }
# + mnt_get_count_debug_id = mnt->mnt_id;
# + pr_err("mount %d: sum %d, re-sum %d, %ps\n",
# + mnt->mnt_id, count, again,
# + __builtin_return_address(0));# }
#
# return count;
# @@ -1350,6 +1383,9 @@
# smp_mb();
# mnt_add_count(mnt, -1);
# count = mnt_get_count(mnt);
# + if (count == 0 && mnt->mnt_id == mnt_get_count_debug_id)
# + pr_err("mount %d: last put by %s (%d)\n", mnt->mnt_id,
# + current->comm, task_pid_nr(current));
# if (count != 0) {
# WARN_ON(count < 0);
# rcu_read_unlock();A task holds open a directory fd on a tmpfs. A synchronous rumount() of the tmpfs sums up. Concurrently a task calls fchdir() on that fd on CPU 0 and fchdir()s back to / on CPU 3. This will cause a path_get() and a path_put() with a migration in between without mount_lock held.
Adding a delay per CPU makes the count loop miss the get in a cpu it already visited but count the put in one it hasn't.
The reproducer, run as root with debugfs mounted:
/* * gcc -static -o umount-torn umount-torn.c */ #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <sched.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/wait.h> #define KNOB "/sys/kernel/debug/mnt_get_count_delay_ms" #define MNT "/mnt/x"
static int kmsg;
static void pin(int cpu)
{
cpu_set_t s;
CPU_ZERO(&s);
CPU_SET(cpu, &s);
sched_setaffinity(0, sizeof(s), &s);
}
static void knob(const char *v)
{
int fd = open(KNOB, O_WRONLY);
write(fd, v, strlen(v));
close(fd);
}
int main(void)
{
int last = sysconf(_SC_NPROCESSORS_ONLN) - 1;
int p[2], fd, ret;
pid_t pid;
char c;
kmsg = open("/dev/kmsg", O_WRONLY);
mkdir(MNT, 0755);
mount("none", MNT, "tmpfs", 0, NULL);
fd = open(MNT "/f", O_WRONLY | O_CREAT, 0644);
write(fd, "still here\n", 11);
close(fd);
pipe(p);
pid = fork();
if (pid == 0) {
int dirfd = open(MNT, O_RDONLY | O_DIRECTORY);
int rootfd = open("/", O_RDONLY | O_DIRECTORY);
struct stat st;
char buf[16];
/* one get/put pair while the umount is summing */
usleep(150000);
pin(0);
fchdir(dirfd); /* mntget() */
dprintf(kmsg, "holder %d: get on cpu %d\n", getpid(),
sched_getcpu());
pin(last);
fchdir(rootfd); /* mntput() */
dprintf(kmsg, "holder %d: put on cpu %d\n", getpid(),
sched_getcpu());
/* the umount has returned, is the fd still good? */
read(p[0], &c, 1);
fd = openat(dirfd, "f", O_RDONLY);
ret = read(fd, buf, sizeof(buf));
dprintf(kmsg, "holder %d: fstat %d openat %d read %d\n",
getpid(), fstat(dirfd, &st), fd, ret);
_exit(0);
}
pin(1);
knob("100");
ret = umount2(MNT, 0);
knob("0");
if (ret)
dprintf(kmsg, "umount: %s\n", strerror(errno));
else
dprintf(kmsg, "umount: 0\n");
write(p[1], "x", 1);
waitpid(pid, NULL, 0);
return 0;
}The log shows the busy check summing 2 and when read right after it reads 3. The loop read CPU 0 before the get landed there and CPU 3 after the put did. The umount succeeds while there's still someone with an fd. The mount is then dropped when the fd goes:
[ 2.511944] holder 90: get on cpu 0 [ 2.512023] holder 90: put on cpu 3 [ 2.671388] mount 28: cpu0 read 1, now 2 [ 2.671398] mount 28: cpu1 read 2, now 2 [ 2.671401] mount 28: cpu2 read 0, now 0 [ 2.671404] mount 28: cpu3 read -1, now -1 [ 2.671407] mount 28: sum 2, re-sum 3, propagate_mount_busy [ 2.671773] umount: 0 [ 2.672963] holder 90: fstat 0 openat 8 read 11 [ 2.673663] mount 28: last put by umount-torn (90)
Easy fix would be to order mntget() against the loop that sums up. But that's a full barrier and a flag test in mntget() afaict. No bueno... That would cost every path_get().
So learn from SRCU. Keep gets and puts in separate per-cpu counters and make mnt_get_count() sum all puts first and all gets second with a full barrier in between.
A put is always after its own get (hopefully...) independent of the cpu the task is on. So a put the first pass counted must have its get visible to the second pass. Ergo, we can't undercount.
This is the two pass sum srcu_readers_active_idx_check() does for srcu_locks and srcu_unlocks. mntget() keeps a single this_cpu_inc(). mntput() gains an smp_wmb() before its increment, a compiler barrier on x86 and a store fence on the weakly ordered architectures, since the two counters are two words and a put stored after a get could otherwise become visible before it. The counters are unsigned so the difference stays right after they wrap.
The count can still come out high when a get is counted whose put the first pass did not see. We don't care. A task can only take a new reference if:
(1) it holds one already
(2) through __legitimize_mnt() which the seqcount orders against the write side
So a get in this window means someone has a reference and -EBUSY is correct. The final mntput() is unchanged. Once ->mnt_ns is NULL every put takes the slow path under mount_lock and so no put is in flight while it counts. Here's an attempted proof for that crap:
(i) A put never becomes visible before its get. Within one task the smp_wmb() in mntput_no_expire() orders every earlier store before the increment of the puts.
Any task that migrated in between had its stores flushed by the scheduler. When that reference is handed to another task that's trivially true.
(ii) The double count in mnt_get_count() is ordered via smp_mb(). That
keeps every read of the puts counter before every read of the gets counter.
(iii) We never undercount by (ii).
(iv) There are no spurious counts/differences. A get is counted only if
it happened and a put is left out only if it hasn't happened when the counter was read. With (iii) this means it's equivalent to the old count whenever nothing is taken or dropped during the loop.
(v) do_umount() holds a reference and mount_lock hence. New references come from: (v.a) __legitimize_mnt() managed by the seqcount. Either it's smp_mb() made the get visible to the loop or it takes the lock and waits for the loop. By (iii) a mount with a additional references is refused. By (iv) refusing the umount just means that any additional reference existed, same as the old counter.
(vi) mntput_no_expire_slowpath() runs with ->mnt_ns already NULL. Hence,
every other put must take the slowpath as well and hangs on mount_lock.
The grace period in namespace_unlock() will make every fast path do a put that still saw ->mnt_ns.
No put is in flight during the loop.
A get that is in flight comes from a task holding another reference. That must be included by the count or from __legitimize_mnt() as in (v).
Ergo, zero means the last reference and non-zero means a reference is live.
(vii) may_umount() uses propagate_mount_busy() as well and
may_umount_tree() sums mnt_get_count() itself.
With this patch the race is dead:
[ 3.066786] mount 28: sum 3, re-sum 3, propagate_mount_busy [ 3.105867] umount: Device or resource busy [ 3.106047] holder 90: fstat 0 openat 8 read 11
--- fs/mount.h | 3 ++- fs/namespace.c | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 19 deletions(-)
fs/mount.h +2 -1
@@ -30,7 +30,8 @@ struct mnt_namespace { } __randomize_layout;struct mnt_pcp { -int mnt_count; +unsigned int mnt_gets; +unsigned int mnt_puts;int mnt_writers; };
fs/namespace.c +30 -18
101 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 535/621 Bluetooth: btintel_pcie: fix TX descriptor bounds check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravindra <[email protected]>
[ Upstream commit baa53af641c9e3644e717b8dfd1b95a55a0c111b ]
btintel_pcie_prepare_tx() uses tfd_index to access the TFD and data buffer arrays before the index is advanced modulo txq->count. An index equal to txq->count is one past the end of both arrays, so reject it in the bounds check.
--- drivers/bluetooth/btintel_pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bluetooth/btintel_pcie.c +1 -1
@@ -358,7 +358,7 @@ static int btintel_pcie_send_sync(struct btintel_pcie_data *data, tfd_index = data->ia.tr_hia[BTINTEL_PCIE_TXQ_NUM ]; -if (tfd_index > txq->count) +if (tfd_index >= txq->count)return -ERANGE ;if (skb->len >BTINTEL_PCIE_BUFFER_SIZE -BTINTEL_PCIE_HCI_TYPE_LEN ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 536/621 Bluetooth: btintel_pcie: Add shared HW reset for clean start
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sai Teja Aluvala <[email protected]>
[ Upstream commit 1465494e8d07426fa41c0021530cccb2a1ac38fa ]
Reset shared Bluetooth hardware after mapping the BAR and before setting up MSI-X interrupts, so stale device state is cleared before IRQ handlers and interrupt masks are configured.
Propagate reset errors so probe aborts rather than continuing when the reset fails.
--- drivers/bluetooth/btintel_pcie.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/bluetooth/btintel_pcie.c +7 -0
@@ -1643,6 +1643,13 @@ static int btintel_pcie_config_pcie(struct pci_dev *pdev,if (IS_ERR (data->base_addr))return PTR_ERR (data->base_addr); +/* Do shared hardware reset to ensure a clean start before +* configuring interrupts. +*/ + err =btintel_pcie_reset_bt (data); +if (err) +return err; + err =btintel_pcie_setup_irq (data);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 537/621 drm/dp: dont mark the AUX backlight enabled when enabling failed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleg Keri <[email protected]>
[ Upstream commit 707ce102521496c67860d81221b20c56d8255f2f ]
If drm_edp_backlight_enable() fails, dp_aux_backlight_update_status() still marks the backlight as enabled. From then on every brightness change only updates the level and the enable is never retried, so the panel stays dark until something blanks and unblanks the backlight.
Return the error instead, so the next update tries to enable again.
--- drivers/gpu/drm/display/drm_dp_helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_dp_helper.c +3 -1
@@ -4378,7 +4378,9 @@ static int dp_aux_backlight_update_status(struct backlight_device *bd)if (!backlight_is_blank (bd)) {if (!bl->enabled) { -drm_edp_backlight_enable (bl->aux, &bl->info, brightness); + ret =drm_edp_backlight_enable (bl->aux, &bl->info, brightness); +if (ret) +return ret; bl->enabled = true;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 538/621 gpio: exar: initialize the ID before registering its cleanup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Hoon Choi <[email protected]>
[ Upstream commit 4d69e74034b208588636ecc177e0dd43a7696af3 ]
devm_add_action_or_reset() invokes the cleanup action immediately when registering the action fails. gpio_exar_probe() currently stores the allocated ID in exar_gpio only after registering the action, so that failure makes exar_devm_ida_free() release ID 0. If the allocated ID is nonzero, this leaks that ID and can free ID 0 belonging to another device.
Store the ID before registering the cleanup action so both the immediate failure path and normal device teardown release the correct allocation.
--- drivers/gpio/gpio-exar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-exar.c +1 -1
@@ -199,6 +199,7 @@ static int gpio_exar_probe(struct platform_device *pdev) index =ida_alloc (&ida_index,GFP_KERNEL );if (index <0 )return index; + exar_gpio->index = index; ret =devm_add_action_or_reset (dev, exar_devm_ida_free, exar_gpio);if (ret)
@@ -214,7 +215,6 @@ static int gpio_exar_probe(struct platform_device *pdev) exar_gpio->gpio_chip.set = exar_set_value; exar_gpio->gpio_chip.base =-1 ; exar_gpio->gpio_chip.ngpio = ngpios; - exar_gpio->index = index; exar_gpio->first_pin = first_pin; ret =devm_gpiochip_add_data (dev, &exar_gpio->gpio_chip, exar_gpio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 529/621 arm64: dts: lx2160a: fix incorrect pinmux
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit 8188a59dd6782786556b18f515090b79cb701c45 ]
For gpio1 value set for pinctrl is outside the mask and so will do nothing.
Add the missing offset for value field to be the same as the mask as expected.
--- arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +3 -3
@@ -1799,7 +1799,7 @@ fspi_data74_pins: xspi1-data74-pins { }; gpio1_31_28_pins: xspi1-data74-gpio-pins { - pinctrl-single,bits = <0x0 0x1 (0x7 << 15)>; + pinctrl-single,bits = <0x0 (0x1 << 15) (0x7 << 15)>; }; fspi_data30_pins: xspi1-data30-pins {
@@ -1807,7 +1807,7 @@ fspi_data30_pins: xspi1-data30-pins { }; gpio1_27_24_pins: xspi1-data30-gpio-pins { - pinctrl-single,bits = <0x0 0x1 (0x7 << 18)>; + pinctrl-single,bits = <0x0 (0x1 << 18) (0x7 << 18)>; }; fspi_dqs_sck_cs10_pins: xspi1-base-pins {
@@ -1815,7 +1815,7 @@ fspi_dqs_sck_cs10_pins: xspi1-base-pins { }; gpio1_23_20_pins: xspi1-base-gpio-pins { - pinctrl-single,bits = <0x0 0x1 (0x7 << 21)>; + pinctrl-single,bits = <0x0 (0x1 << 21) (0x7 << 21)>; }; esdhc0_cmd_data30_clk_vsel_pins: sdhc1-base-sdhc-vsel-pins {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 577/621 spi: sg2044-nor: Return transfer errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Han Gao <[email protected]>
[ Upstream commit e130c54fbb603f9aeacf5029789b4a2c8c48f416 ]
The transfer helpers return errors, but both dispatchers discard them. Return these errors to the SPI memory layer instead of reporting success.
--- drivers/spi/spi-sg2044-nor.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/spi/spi-sg2044-nor.c +9 -8
@@ -307,15 +307,15 @@ static ssize_t sg2044_spifmc_tran_cmd(struct sg2044_spifmc *spifmc,return 0 ; } -static void sg2044_spifmc_trans (struct sg2044_spifmc *spifmc, -const struct spi_mem_op *op) +static int sg2044_spifmc_trans (struct sg2044_spifmc *spifmc, +const struct spi_mem_op *op) {if (op->data.dir ==SPI_MEM_DATA_IN ) -sg2044_spifmc_read (spifmc, op); +return sg2044_spifmc_read (spifmc, op);else if (op->data.dir ==SPI_MEM_DATA_OUT ) -sg2044_spifmc_write (spifmc, op); +return sg2044_spifmc_write (spifmc, op);else -sg2044_spifmc_tran_cmd (spifmc, op); +return sg2044_spifmc_tran_cmd (spifmc, op); } static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc,
@@ -389,19 +389,20 @@ static int sg2044_spifmc_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) {struct sg2044_spifmc *spifmc; +int ret; spifmc =spi_controller_get_devdata (mem->spi->controller);mutex_lock (&spifmc->lock);if (op->addr.nbytes ==0 ) -sg2044_spifmc_trans_reg (spifmc, op); + ret =sg2044_spifmc_trans_reg (spifmc, op);else -sg2044_spifmc_trans (spifmc, op); + ret =sg2044_spifmc_trans (spifmc, op);mutex_unlock (&spifmc->lock); -return 0 ; +return ret; }static const struct spi_controller_mem_ops sg2044_spifmc_mem_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 586/621 pfcp: make sure the SEID is linear before reading it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haishuang Yan <[email protected]>
[ Upstream commit 23609bce9e1de525d1d0e73fc68c6e7971d0b49e ]
pfcp_encap_recv() only makes sure that the UDP header and the 4 byte PFCP header are in the linear area. When the S flag is set, pfcp_session_recv() then reads the 8 byte SEID that follows, which is not covered by the pskb_may_pull() check.
A short PFCP packet with the S flag set, or one whose session header lies in a fragment, therefore makes pfcp_session_recv() read beyond the end of the packet data, and whatever it finds there is stored in the tunnel metadata that flower later classifies on.
Pull up to the end of the SEID before reading it, and drop packets that are too short to contain it. Reload the header pointer afterwards since pskb_may_pull() may reallocate the skb head.
Use offsetofend() rather than sizeof(struct pfcphdr_session): the structure is not packed, so its size is 16 bytes because of the alignment of the __be64 member, while the header on the wire is only 12 bytes, and valid session messages would be dropped.
--- drivers/net/pfcp.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/pfcp.c +7 -0
@@ -64,6 +64,13 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) goto drop; unparsed =pfcp_hdr (skb); +if (unparsed->flags &PFCP_SEID_FLAG ) { +if (unlikely (!pskb_may_pull (skb,PFCP_HLEN + + offsetofend(struct pfcphdr_session, + seid)))) + goto drop; + unparsed =pfcp_hdr (skb); + }ip_tunnel_flags_zero (flags); tun_dst = udp_tun_rx_dst(skb, sk->sk_family, flags, 0,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 587/621 bnxt_en: Add bnxt_clear_bars() helper
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Chan <[email protected]>
[ Upstream commit 8f5d59b9cfa69beab3b52cca621bb301c5af98aa ]
In bnxt_io_slot_reset(), we clear the 6 BAR registers. Add a helper function to do that. The helper will be used again in the next patch.
Stable-dep-of: 386f887c8290 ("bnxt_en: Fix driver init in kdump kernel")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -6
@@ -16832,6 +16832,14 @@ void bnxt_print_device_info(struct bnxt *bp)pcie_print_link_status (bp->pdev); } +static void bnxt_clear_bars (struct pci_dev *pdev) +{ +int off; + +for (off =PCI_BASE_ADDRESS_0 ; off <=PCI_BASE_ADDRESS_5 ; off +=4 ) +pci_write_config_dword (pdev, off,0 ); +} +static int bnxt_init_one (struct pci_dev *pdev,const struct pci_device_id *ent) {struct bnxt_hw_resc *hw_resc;
@@ -17306,7 +17314,6 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)struct bnxt *bp =netdev_priv (netdev);int retry =0 ;int err =0 ; -int off;netdev_info (bp->dev,"PCI Slot Reset\n" );
@@ -17330,11 +17337,8 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)* write the BARs to 0 to force restore, in case of fatal error. */ if (test_and_clear_bit (BNXT_STATE_PCI_CHANNEL_IO_FROZEN , - &bp->state)) { -for (off =PCI_BASE_ADDRESS_0 ; - off <=PCI_BASE_ADDRESS_5 ; off +=4 ) -pci_write_config_dword (bp->pdev, off,0 ); - } + &bp->state)) +bnxt_clear_bars (pdev);pci_restore_state (pdev);pci_save_state (pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 588/621 bnxt_en: Fix driver init in kdump kernel
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Chan <[email protected]>
[ Upstream commit 386f887c8290f0747dd0180e98ec7a82811bc506 ]
Fix and strengthen the FLR sequence when initializing in the kdump kernel. If the NIC is behind a PCIe switch in synthetic (smart) mode, the switch may need to see that the BARs have been initialized before it will pass mem read/write TLPs to the NIC.
On a Dell system with a PEX89144 PCIe switch, echo c > /proc/sysrq-trigger will trigger fatal AER without this patch:
bnxt_en 0000:67:00.0: enabling device (0000 -> 0002)
[Hardware Error]: Hardware error from APEI Generic Hardware Error Source: 5 [Hardware Error]: event severity: recoverable
[Hardware Error]: Error 0, type: fatal
[Hardware Error]: section_type: PCIe error
[Hardware Error]: port_type: 5, upstream switch port
...
Add a new bnxt_kdump_reset() to do the expanded FLR sequence in the kdump kernel. We now disable bus master and memory, save the PCI state, do the FLR, clear the BARs, and restore the PCI state. The BARs have to be cleared to ensure that they get re-initialized and visible to the PCIe switch.
Since it is the kdump kernel, we make every effort to continue in the best possible way even if pci_save_state() or pcie_flr() returns error. After FLR, we poll for an additional 5 seconds before aborting in case the device is not properly returning CRS. This is similar to the 5-second wait in bnxt_io_slot_reset().
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 45 ++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +40 -5
@@ -16840,6 +16840,43 @@ static void bnxt_clear_bars(struct pci_dev *pdev)pci_write_config_dword (pdev, off,0 ); } +/* Clear any pending DMA transactions from crash kernel while loading driver in +* capture kernel. +*/ +static int bnxt_kdump_reset (struct pci_dev *pdev) +{ +int rc, i; +u16 cmd; + +pci_read_config_word (pdev,PCI_COMMAND , &cmd); + cmd &= ~(PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY ); +pci_write_config_word (pdev,PCI_COMMAND , cmd); + +if (pci_save_state (pdev)) +dev_warn (&pdev->dev,"Failed to save PCI state, PCI restore may be incomplete\n" ); + + rc =pcie_flr (pdev); +if (rc) +dev_warn (&pdev->dev,"pcie_flr() failed (rc: %d), trying to continue\n" , + rc); + +/* In case device is not returning CRS, wait 5 seconds longer */ +for (i =0 ; i <50 ; i++) { +pci_read_config_word (pdev,PCI_COMMAND , &cmd); +if (!PCI_POSSIBLE_ERROR (cmd)) +break ; +msleep (100 ); + } +if (PCI_POSSIBLE_ERROR (cmd)) { +dev_err (&pdev->dev,"PCI config space inaccessible after FLR, aborting\n" ); +return -ENODEV ; + } + +bnxt_clear_bars (pdev); +pci_restore_state (pdev); +return 0 ; +} +static int bnxt_init_one (struct pci_dev *pdev,const struct pci_device_id *ent) {struct bnxt_hw_resc *hw_resc;
@@ -16855,12 +16892,10 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)return -ENODEV ; } -/* Clear any pending DMA transactions from crash kernel -* while loading driver in capture kernel. -*/ if (is_kdump_kernel ()) { -pci_clear_master (pdev); -pcie_flr (pdev); + rc =bnxt_kdump_reset (pdev); +if (rc) +return rc; } max_irqs =bnxt_get_max_irq (pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 589/621 bnxt_en: Delay for 5 seconds after AER DPC for all chips
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Chan <[email protected]>
[ Upstream commit 07f44433355f70fa97d4c44b4c0d2e86adc082fb ]
The FW on all chips is requiring a 5-second delay after Downstream Port Containment (DPC) AER. The previously added 900 msec delay was not long enough in all cases because the chip's CRS (Configuration Request Retry Status) mechanism is not always reliable.
Stable-dep-of: 2e52da27096d ("bnxt_en: Re-write the BARs following any type of PCIe errors")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -3
@@ -17352,9 +17352,14 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)netdev_info (bp->dev,"PCI Slot Reset\n" ); -if (!(bp->flags &BNXT_FLAG_CHIP_P5_PLUS ) && -test_bit (BNXT_STATE_PCI_CHANNEL_IO_FROZEN , &bp->state)) -msleep (900 ); +if (test_bit (BNXT_STATE_PCI_CHANNEL_IO_FROZEN , &bp->state)) { +/* After DPC, the chip should return CRS when the vendor ID +* config register is read until it is ready. On all chips, +* this is not happening reliably so add a 5-second delay as a +* workaround. +*/ +msleep (5000 ); + }netdev_lock (netdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 590/621 bnxt_en: Drop pci_save_state() after pci_restore_state()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
[ Upstream commit 04ae0d54c1b11a622b8b0f502675135c7d9dab61 ]
Commit 383d89699c50 ("treewide: Drop pci_save_state() after pci_restore_state()") sought to purge all superfluous invocations of pci_save_state() from the tree.
Unfortunately the commit missed one invocation in the Broadcom NetXtreme-C/E driver. Drop it.
Stable-dep-of: 2e52da27096d ("bnxt_en: Re-write the BARs following any type of PCIe errors")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -1
@@ -17380,7 +17380,6 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev) &bp->state))bnxt_clear_bars (pdev);pci_restore_state (pdev); -pci_save_state (pdev);bnxt_inv_fw_health_reg (bp);bnxt_try_map_fw_health_reg (bp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 591/621 bnxt_en: Re-write the BARs following any type of PCIe errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavan Chebbi <[email protected]>
[ Upstream commit 2e52da27096d9dbc487f303bbc10d44ad837a8c4 ]
Currently the driver zeroes the BARs only when fatal PCIe errors are reported so that pci_restore_state() restores it. However firmware handles both fatal and non-fatal errors the same way when it sees the slot reset resulting from the PCI_ERS_RESULT_NEED_RESET return code from the driver. This means that we must re-write the BARs post recovery even during non-fatal errors. Otherwise we will see that every MMIO access returns all-ones and the firmware appears dead.
Zero-out the BARs during PCIe error recovery regardless of type of PCIe error, and make the wait after the hot reset unconditional.
Disable memory decode and bus mastering before rewriting the BARs so the device doesn't decode a half-updated address, bailing out if config space is still inaccessible. Defer pci_enable_device() until after the BAR rewrite and restore, so the device isn't re-enabled while its BARs are still being rewritten, then re-enable the device and re-assert bus mastering. Guard the same Command register cleanup on the re-enable failure path against an inaccessible device.
Skip re-enabling the device in bnxt_io_slot_reset() if it is already enabled, so enable_cnt does not go unbalanced. A concurrent bnxt_fw_reset_task() can also be re-enabling the same device in its ENABLE_DEV state, so guard that call the same way.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 107 ++++++++++++---------- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 - 2 files changed, 60 insertions(+), 48 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +60 -47
@@ -15293,7 +15293,7 @@ static void bnxt_fw_reset_task(struct work_struct *work)if (test_and_clear_bit (BNXT_STATE_FW_ACTIVATE_RESET , &bp->state) && !test_bit (BNXT_STATE_FW_ACTIVATE , &bp->state))bnxt_dl_remote_reload (bp); -if (pci_enable_device (bp->pdev)) { +if (!pci_is_enabled (bp->pdev) &&pci_enable_device (bp->pdev)) {netdev_err (bp->dev,"Cannot re-enable PCI device\n" ); rc = -ENODEV ; goto fw_reset_abort;
@@ -17316,10 +17316,8 @@ static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,* so we disable bus master to prevent any potential bad DMAs before * freeing kernel memory. */ -if (state == pci_channel_io_frozen) { -set_bit (BNXT_STATE_PCI_CHANNEL_IO_FROZEN , &bp->state); +if (state == pci_channel_io_frozen)bnxt_fw_fatal_close (bp); - }if (netif_running (netdev))__bnxt_close_nic (bp, true, true);
@@ -17349,65 +17347,80 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)struct bnxt *bp =netdev_priv (netdev);int retry =0 ;int err =0 ; +u16 cmd;netdev_info (bp->dev,"PCI Slot Reset\n" ); -if (test_bit (BNXT_STATE_PCI_CHANNEL_IO_FROZEN , &bp->state)) { -/* After DPC, the chip should return CRS when the vendor ID -* config register is read until it is ready. On all chips, -* this is not happening reliably so add a 5-second delay as a -* workaround. -*/ -msleep (5000 ); - } +/* After a PCIe hot reset, the chip should return CRS when the +* vendor ID config register is read until it is ready. On all +* chips, this is not happening reliably so add a 5-second delay +* as a workaround. +*/ +msleep (5000 );netdev_lock (netdev); -if (pci_enable_device (pdev)) { +pci_read_config_word (pdev,PCI_COMMAND , &cmd); +if (PCI_POSSIBLE_ERROR (cmd)) {dev_err (&pdev->dev, -"Cannot re-enable PCI device after reset.\n" ); - }else { -pci_set_master (pdev); -/* Upon fatal error, our device internal logic that latches to -* BAR value is getting reset and will restore only upon -* rewriting the BARs. -* -* As pci_restore_state() does not re-write the BARs if the -* value is same as saved value earlier, driver needs to -* write the BARs to 0 to force restore, in case of fatal error. -*/ -if (test_and_clear_bit (BNXT_STATE_PCI_CHANNEL_IO_FROZEN , - &bp->state)) -bnxt_clear_bars (pdev); -pci_restore_state (pdev); +"PCI config space inaccessible after reset\n" ); + goto reset_exit; + } -bnxt_inv_fw_health_reg (bp); -bnxt_try_map_fw_health_reg (bp); +/* Upon PCIe error, our device internal logic that latches to +* BAR value is getting reset and will restore only upon +* rewriting the BARs. +* +* As pci_restore_state() does not re-write the BARs if the +* value is same as saved value earlier, driver needs to +* write the BARs to 0 to force restore. +*/ +pci_clear_master (pdev); +pci_read_config_word (pdev,PCI_COMMAND , &cmd); + cmd &= ~PCI_COMMAND_MEMORY ; +pci_write_config_word (pdev,PCI_COMMAND , cmd); -/* In some PCIe AER scenarios, firmware may take up to -* 10 seconds to become ready in the worst case. -*/ -do { - err =bnxt_try_recover_fw (bp); -if (!err) -break ; - retry++; - }while (retry <BNXT_FW_SLOT_RESET_RETRY ); +bnxt_clear_bars (pdev); +pci_restore_state (pdev); -if (err) { -dev_err (&pdev->dev,"Firmware not ready\n" ); - goto reset_exit; +if (!pci_is_enabled (pdev) &&pci_enable_device (pdev)) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after reset.\n" ); +pci_read_config_word (pdev,PCI_COMMAND , &cmd); +if (!PCI_POSSIBLE_ERROR (cmd)) { + cmd &= ~(PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY ); +pci_write_config_word (pdev,PCI_COMMAND , cmd); } + goto reset_exit; + } +pci_set_master (pdev); - err =bnxt_hwrm_func_reset (bp); +bnxt_inv_fw_health_reg (bp); +bnxt_try_map_fw_health_reg (bp); + +/* In some PCIe AER scenarios, firmware may take up to +* 10 seconds to become ready in the worst case. +*/ +do { + err =bnxt_try_recover_fw (bp);if (!err) - result =PCI_ERS_RESULT_RECOVERED ; +break ; + retry++; + }while (retry <BNXT_FW_SLOT_RESET_RETRY ); -/* IRQ will be initialized later in bnxt_io_resume */ -bnxt_ulp_irq_stop (bp); -bnxt_clear_int_mode (bp); +if (err) { +dev_err (&pdev->dev,"Firmware not ready\n" ); + goto reset_exit; } + err =bnxt_hwrm_func_reset (bp); +if (!err) + result =PCI_ERS_RESULT_RECOVERED ; + +/* IRQ will be initialized later in bnxt_io_resume */ +bnxt_ulp_irq_stop (bp); +bnxt_clear_int_mode (bp); + reset_exit:clear_bit (BNXT_STATE_IN_FW_RESET , &bp->state);bnxt_clear_reservations (bp, true);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +0 -1
@@ -2449,7 +2449,6 @@ struct bnxt {#define BNXT_STATE_ABORT_ERR 5#define BNXT_STATE_FW_FATAL_COND 6#define BNXT_STATE_DRV_REGISTERED 7 -#define BNXT_STATE_PCI_CHANNEL_IO_FROZEN 8#define BNXT_STATE_NAPI_DISABLED 9#define BNXT_STATE_L2_FILTER_RETRY 10#define BNXT_STATE_FW_ACTIVATE 11
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 592/621 flow_dissector: avoid u16 truncation of hlen in bpf_flow_dissect()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit f202578efc738b883cfa04889eb97328914265a7 ]
bpf_flow_dissect() sanitizes the offsets returned by the BPF program with clamp_t(u16, ..., hlen).
If hlen is bigger than 65535, the upper bound is truncated before the comparison. For instance, with hlen == 65536, both nhoff and thoff are forced to zero, even if the program returned sane values.
This is the same class of bug as the one fixed in commit 99bda1ecbd56 ("flow_dissector: avoid u16 truncation of skb->len when computing thoff"). That fix does not cover the BPF path, because __skb_flow_dissect() returns early when a BPF flow dissector handles the packet.
struct bpf_flow_keys stores nhoff and thoff as u16, so cap hlen to U16_MAX before clamping.
Found by sashiko while reviewing the commit above.
--- net/core/flow_dissector.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/flow_dissector.c +2 -0
@@ -1023,6 +1023,8 @@ u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, result =bpf_prog_run_pin_on_cpu (prog, ctx); +/* bpf_flow_keys offsets are u16: do not let @hlen be truncated. */ + hlen =min_t (int, hlen,U16_MAX ); flow_keys->nhoff =clamp_t (u16, flow_keys->nhoff, nhoff, hlen); flow_keys->thoff =clamp_t (u16, flow_keys->thoff, flow_keys->nhoff, hlen);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 593/621 drm/imagination: Fix reference and vm_bo handling in remap()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gyeyoung Baek <[email protected]>
[ Upstream commit 196d4d10c1b33ae176685ff42a9994a5952b1d0f ]
When a map overlaps part of an existing mapping, pvr_vm_gpuva_remap() splits the mapping into prev/next parts covering what the request did not take, instead of creating something new. It gets two things wrong.
- A GEM reference is taken for each part but it's never needed and never dropped, so it leaks one reference per split (remap-next-in-2m in tests/imagination/pvr_vm_map.c):
CRITICAL: 33558528 bytes of shmem still held after close
- The parts still belong to the original object being split, but pvr_vm_gpuva_remap() links them to ctx->gpuvm_bo, the new object's vm_bo:
prev_va --obj--> BO_A BO_B <--obj-- vm_bo (ctx->gpuvm_bo)
\___________link___________/ (mismatch: BO_A != BO_B) drm_gpuva_link() catches the mismatch:
WARNING: drivers/gpu/drm/drm_gpuvm.c:2108 at drm_gpuva_link+0x2ec/0x310
drm_WARN_ON(obj != vm_bo->obj)
Call trace:
drm_gpuva_link
pvr_vm_gpuva_remap
__drm_gpuvm_sm_map
pvr_vm_map
pvr_ioctl_vm_map Link them to op->remap.unmap->va->vm_bo instead.
The locking of the GPUVA lists of the other objects touched by a split is not addressed here; it is handled by switching the GPUVM to immediate mode.
--- drivers/gpu/drm/imagination/pvr_vm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/imagination/pvr_vm.c +4 -4
@@ -417,6 +417,8 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void *op_ctx)static int pvr_vm_gpuva_remap (struct drm_gpuva_op *op,void *op_ctx) { +/* The split parts belong to the object of the mapping being split. */ +struct drm_gpuvm_bo *vm_bo = op->remap.unmap->va->vm_bo;struct pvr_vm_bind_op *ctx = op_ctx;u64 va_start =0 , va_range =0 ;int err;
@@ -432,14 +434,12 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)drm_gpuva_remap (&ctx->prev_va->base, &ctx->next_va->base, &op->remap);if (op->remap.prev) { -pvr_gem_object_get (gem_to_pvr_gem (ctx->prev_va->base.gem.obj)); -drm_gpuva_link (&ctx->prev_va->base, ctx->gpuvm_bo); +drm_gpuva_link (&ctx->prev_va->base, vm_bo); ctx->prev_va =NULL ; }if (op->remap.next) { -pvr_gem_object_get (gem_to_pvr_gem (ctx->next_va->base.gem.obj)); -drm_gpuva_link (&ctx->next_va->base, ctx->gpuvm_bo); +drm_gpuva_link (&ctx->next_va->base, vm_bo); ctx->next_va =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 594/621 veth: fix peer NETDEV_XDP_ACT_NDO_XMIT after GRO is toggled while down
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianyi Gao <[email protected]>
[ Upstream commit 3f090039995f609a8e236f37980dee5712dded61 ]
A veth device advertises NETDEV_XDP_ACT_NDO_XMIT only if its peer has an XDP program attached or GRO enabled, that is, only if the peer will have NAPI to receive the frames.
veth_set_features() updates the peer's flag when GRO is toggled, but returns early if the device is down, and veth_open() only refreshes the flags of the device being opened. Toggling GRO while the device is down therefore leaves the peer's flag stale after the device comes up.
If GRO was enabled while down, the device comes up with NAPI but the peer does not advertise NDO_XMIT, and devmap rejects redirects to the peer with -EOPNOTSUPP. If GRO was disabled while down, the device comes up without NAPI but the peer still advertises NDO_XMIT, so redirects are accepted and then dropped in veth_xdp_xmit() with -ENXIO.
Commit 7a6102aa6df0 ("veth: Update XDP feature set when bringing up device") made veth_open() refresh the device's own flags. Refresh the peer's flags there too. The peer's flag depends on this device's XDP program and GRO setting, not on whether the peer is up, so it is correct to set it even if the peer is down.
--- drivers/net/veth.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/veth.c +1 -0
@@ -1414,6 +1414,7 @@ static int veth_open(struct net_device *dev) }veth_set_xdp_features (dev); +veth_set_xdp_features (peer);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 595/621 net/mlx5e: Order ICOSQ cc update after CQ doorbell
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit b056ca4d3742d0769f91137bb1ce3215428398f7 ]
mlx5e_poll_ico_cq() requires sq->cc to be updated only after mlx5_cqwq_update_db_record(), otherwise a CQ overrun may occur.
The current implementation updates sq->cc before the CQ doorbell record, violating this ordering requirement.
Update the CQ doorbell record first and use dma_wmb() before updating sq->cc. This ensures that the CQ space is released to the device before the corresponding ICOSQ consumer index is updated by software.
--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +4 -2
@@ -1079,10 +1079,12 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq) }while (!last_wqe); }while ((++i <MLX5E_TX_CQ_POLL_BUDGET ) && (cqe =mlx5_cqwq_get_cqe (&cq->wq))); - sq->cc = sqcc; -mlx5_cqwq_update_db_record (&cq->wq); +/* ensure cq space is freed before enabling more cqes */ +dma_wmb (); + + sq->cc = sqcc;return i; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 578/621 spi: sg2044-nor: Honor SPI clock limits
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Han Gao <[email protected]>
[ Upstream commit 61d44a2c07b2ad3f7db167f17ff2461ffe78441c ]
The fixed divider ignores device and operation clock limits. Calculate the divider before each transfer so SCK does not exceed either limit.
Advertise the controller maximum speed so the SPI core supplies a default when the device omits its maximum speed. Use the fastest divider when no speed limit is supplied.
--- drivers/spi/spi-sg2044-nor.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/spi/spi-sg2044-nor.c +39 -0
@@ -385,6 +385,29 @@ static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc,return 0 ; } +static int sg2044_spifmc_set_speed (struct sg2044_spifmc *spifmc, +unsigned int speed_hz) +{ +unsigned long rate =clk_get_rate (spifmc->clk); +u64 div; +u32 reg; + +if (!rate) +return -EINVAL ; + +/* SCK = HCLK / (2 * (SckDiv + 1)); round down the resulting SCK. */ + div = speed_hz ?DIV_ROUND_UP_ULL (rate,2ULL * speed_hz) :1 ; +if (div >SPIFMC_CTRL_SCK_DIV_MASK +1 ) +return -EINVAL ; + + reg =readl (spifmc->io_base +SPIFMC_CTRL ); + reg &= ~SPIFMC_CTRL_SCK_DIV_MASK ; + reg |= div -1 ; +writel (reg, spifmc->io_base +SPIFMC_CTRL ); + +return 0 ; +} +static int sg2044_spifmc_exec_op (struct spi_mem *mem,const struct spi_mem_op *op) {
@@ -395,11 +418,18 @@ static int sg2044_spifmc_exec_op(struct spi_mem *mem,mutex_lock (&spifmc->lock); + ret =sg2044_spifmc_set_speed (spifmc, op->max_freq ? +min (op->max_freq, mem->spi->max_speed_hz) : + mem->spi->max_speed_hz); +if (ret) + goto out_unlock; +if (op->addr.nbytes ==0 ) ret =sg2044_spifmc_trans_reg (spifmc, op);else ret =sg2044_spifmc_trans (spifmc, op); +out_unlock:mutex_unlock (&spifmc->lock);return ret;
@@ -409,6 +439,10 @@ static const struct spi_controller_mem_ops sg2044_spifmc_mem_ops = { .exec_op = sg2044_spifmc_exec_op, }; +static const struct spi_controller_mem_caps sg2044_spifmc_mem_caps = { + .per_op_freq = true, +}; +static void sg2044_spifmc_init (struct sg2044_spifmc *spifmc) {u32 tran_csr;
@@ -448,6 +482,10 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)if (IS_ERR (spifmc->clk))return dev_err_probe (dev,PTR_ERR (spifmc->clk),"Cannot get and enable AHB clock\n" ); + ctrl->max_speed_hz =clk_get_rate (spifmc->clk) /2 ; +if (!ctrl->max_speed_hz) +return dev_err_probe (dev, -EINVAL ,"Invalid AHB clock rate\n" ); + spifmc->dev = &pdev->dev; spifmc->ctrl = ctrl;
@@ -460,6 +498,7 @@ static int sg2044_spifmc_probe(struct platform_device *pdev) ctrl->bits_per_word_mask =SPI_BPW_MASK (8 ); ctrl->auto_runtime_pm = false; ctrl->mem_ops = &sg2044_spifmc_mem_ops; + ctrl->mem_caps = &sg2044_spifmc_mem_caps; ctrl->mode_bits =SPI_RX_DUAL |SPI_TX_DUAL |SPI_RX_QUAD |SPI_TX_QUAD ; ret =devm_mutex_init (dev, &spifmc->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 596/621 mlxsw: spectrum_flower: Fix port range register leak in tmplt_create()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Machata <[email protected]>
[ Upstream commit 7ea07afb230f1342ab0f9365edd0aae137f425d3 ]
mlxsw_sp_flower_tmplt_create() parses a flow_cls_offload template into a stack-local struct mlxsw_sp_acl_rule_info purely to compute rulei.values.elusage. Parsing can acquire port range registers via mlxsw_sp_flower_parse_ports_range(), but since this rulei never goes through mlxsw_sp_acl_rulei_destroy(), those registers were never released, including through chain template deletion.
Factor out of mlxsw_sp_acl_rulei_destroy() the code to actually release the necessary resources and call from mlxsw_sp_flower_tmplt_create() to plug the leak.
The issue was found during a review of Wentao Liang's patch referenced below.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 2 ++ drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 10 ++++++++-- drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c | 9 +++++++-- 3 files changed, 17 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -0
@@ -989,6 +989,8 @@ void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,struct mlxsw_sp_acl_rule_info *mlxsw_sp_acl_rulei_create (struct mlxsw_sp_acl *acl,struct mlxsw_afa_block *afa_block); +void mlxsw_sp_acl_rulei_free (struct mlxsw_sp *mlxsw_sp, +const struct mlxsw_sp_acl_rule_info *rulei);void mlxsw_sp_acl_rulei_destroy (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_rule_info *rulei);int mlxsw_sp_acl_rulei_commit (struct mlxsw_sp_acl_rule_info *rulei);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +8 -2
@@ -340,8 +340,8 @@ mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,return ERR_PTR (err); } -void mlxsw_sp_acl_rulei_destroy (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_rule_info *rulei) +void mlxsw_sp_acl_rulei_free (struct mlxsw_sp *mlxsw_sp, +const struct mlxsw_sp_acl_rule_info *rulei) {if (rulei->action_created)mlxsw_afa_block_destroy (rulei->act_block);
@@ -351,6 +351,12 @@ void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp,if (rulei->dst_port_range_reg_valid)mlxsw_sp_port_range_reg_put (mlxsw_sp, rulei->dst_port_range_reg_index); +} + +void mlxsw_sp_acl_rulei_destroy (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_rule_info *rulei) +{ +mlxsw_sp_acl_rulei_free (mlxsw_sp, rulei);kfree (rulei); }
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +7 -2
@@ -862,14 +862,19 @@ int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,memset (&rulei,0 ,sizeof (rulei)); err =mlxsw_sp_flower_parse (mlxsw_sp, block, &rulei, f);if (err) -return err; + goto out; + ruleset =mlxsw_sp_acl_ruleset_get (mlxsw_sp, block, f->common.chain_index,MLXSW_SP_ACL_PROFILE_FLOWER , &rulei.values.elusage); + err =PTR_ERR_OR_ZERO (ruleset); + +out: +mlxsw_sp_acl_rulei_free (mlxsw_sp, &rulei);/* keep the reference to the ruleset */ -return PTR_ERR_OR_ZERO (ruleset); +return err; } void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 597/621 net/packet: call packet_parse_headers after virtio_net_hdr_to_skb
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 513e23857a3a64fa73a1deb36a385eecd4ad7690 ]
SOCK_RAW packet sockets incorrectly drop VLAN-tagged GSO packets without VIRTIO_NET_HDR_F_NEEDS_CSUM.
packet_parse_headers() sets skb->protocol to VLAN but advances skb->network_header past the VLAN tags. virtio_net_hdr_to_skb() then flow dissects these packets, which parses the network header as a VLAN tag, and fails.
Call packet_parse_headers() after virtio_net_hdr_to_skb() instead.
This matches tun_get_user() and tap_get_user() and thus simplifies overall complexity.
Commit 01fdecc0480d ("net: packet: fix wrong transport_header when sending VLAN-tagged frame") fixed the same issue for the transport header probe in packet_parse_headers(). That probe is now skipped if virtio_net_hdr_to_skb() already set the transport header, avoiding a redundant dissection.
Implementation details:
- Do not set skb->protocol to the RX wildcard ETH_P_ALL. SOCK_RAW then derives it from the link layer header, as before. SOCK_DGRAM now leaves it 0, or derives it from gso_type for GSO with NEEDS_CSUM.
- Keep virtio_net_hdr_set_proto() last, so that the link layer protocol takes priority over gso_type.
--- net/packet/af_packet.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
net/packet/af_packet.c +15 -10
@@ -1942,8 +1942,7 @@ static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)/* On TX skb->data is the L2 header; anchor it for all socket types. */ skb_reset_mac_header (skb); -if ((!skb->protocol || skb->protocol ==htons (ETH_P_ALL )) && - sock->type ==SOCK_RAW ) +if (!skb->protocol && sock->type ==SOCK_RAW ) skb->protocol =dev_parse_header_protocol (skb);skb_probe_transport_header (skb);
@@ -2613,7 +2612,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,struct page *page;int err; - skb->protocol = proto; +if (proto !=htons (ETH_P_ALL )) + skb->protocol = proto; skb->dev = dev; skb->priority = sockc->priority; skb->mark = sockc->mark;
@@ -2677,8 +2677,6 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,if (unlikely (!skb->len))return -EINVAL ; -packet_parse_headers (skb, sock); -return tp_len; }
@@ -2918,9 +2916,13 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) tp_len = -EINVAL ; goto tpacket_error; } -virtio_net_hdr_set_proto (skb, &vnet_hdr); } +packet_parse_headers (skb, po->sk.sk_socket); + +if (has_vnet_hdr) +virtio_net_hdr_set_proto (skb, &vnet_hdr); + uarg =kmalloc (sizeof (*uarg),GFP_KERNEL );if (unlikely (!uarg)) {if (likely (len_sum >0 ))
@@ -3121,7 +3123,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) goto out_free; } - skb->protocol = proto; +if (proto !=htons (ETH_P_ALL )) + skb->protocol = proto; skb->dev = dev; skb->priority = sockc.priority; skb->mark = sockc.mark;
@@ -3130,16 +3133,18 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)if (unlikely (extra_len ==4 )) skb->no_fcs =1 ; -packet_parse_headers (skb, sock); -if (vnet_hdr_sz) { err =virtio_net_hdr_to_skb (skb, &vnet_hdr,vio_le ());if (err) goto out_free; len += vnet_hdr_sz; -virtio_net_hdr_set_proto (skb, &vnet_hdr); } +packet_parse_headers (skb, sock); + +if (vnet_hdr_sz) +virtio_net_hdr_set_proto (skb, &vnet_hdr); + err =packet_xmit (po, skb);if (unlikely (err !=0 )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 598/621 ptp: ocp: fix PCIe delay estimation calculation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vadim Fedorenko <[email protected]>
[ Upstream commit f8c8bd159a9bf626dd4921b7746ff481fce8c758 ]
The commit in fixes introduced a high cap for delayas U64_MAX value while ktime_t is actually s64. This is wrong cap as it becomes negative value and any comparison to a real delay will fail to update delay value. Use KTIME_MAX constant as correct max cap for PCIe delay.
The issue was hit in production (a negative value is observed):
# cat /sys/class/timecard/ocp0/ts_window_adjust -3
--- drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -1564,7 +1564,7 @@ ptp_ocp_watchdog(struct timer_list *t)static void ptp_ocp_estimate_pci_timing (struct ptp_ocp *bp) { -ktime_t start, end, delay =U64_MAX ; +ktime_t start, end, delay =KTIME_MAX ;u32 ctrl;int i;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 599/621 net: openvswitch: validate transport header presence in set_ipv6_addr
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 3c6a4b11330fe424557538a98fca9f0a4c5bf313 ]
When executing IPv6 address rewrite actions on IPv6 fragments, set_ipv6_addr() calls update_ipv6_checksum(). If parse_ipv6hdr() processes a non-first IPv6 fragment, it sets key->ip.proto to NEXTHDR_FRAGMENT and returns early without calling skb_set_transport_header().
update_ipv6_checksum() unconditionally evaluates skb_transport_offset() on entry before checking l4_proto. Because skb->transport_header is uninitialized, this triggers a warning under CONFIG_DEBUG_NET=y although it is completely harmless.
Fix this by returning early in update_ipv6_checksum() if l4_proto is NEXTHDR_FRAGMENT. This avoids reading the uninitialized transport offset for fragments while preserving the debug warning for any other protocol where the transport header is unexpectedly missing.
See the syzbot trace:
!skb_transport_header_was_set(skb)
WARNING: ./include/linux/skbuff.h:3075 at skb_transport_header include/linux/skbuff.h:3075 [inline], CPU#1: syz-executor463/5635 WARNING: ./include/linux/skbuff.h:3075 at skb_transport_offset include/linux/skbuff.h:3250 [inline], CPU#1: syz-executor463/5635 WARNING: ./include/linux/skbuff.h:3075 at update_ipv6_checksum net/openvswitch/actions.c:361 [inline], CPU#1: syz-executor463/5635 WARNING: ./include/linux/skbuff.h:3075 at set_ipv6_addr+0x462/0x660 net/openvswitch/actions.c:399, CPU#1: syz-executor463/5635 [...] RIP: 0010:skb_transport_header include/linux/skbuff.h:3075 [inline] RIP: 0010:skb_transport_offset include/linux/skbuff.h:3250 [inline] RIP: 0010:update_ipv6_checksum net/openvswitch/actions.c:361 [inline] RIP: 0010:set_ipv6_addr+0x462/0x660 net/openvswitch/actions.c:399 [...] Call Trace: <TASK> set_ipv6 net/openvswitch/actions.c:531 [inline] do_execute_actions+0x557e/0x8600 net/openvswitch/actions.c:1366 ovs_execute_actions+0xde/0x520 net/openvswitch/actions.c:1592 ovs_packet_cmd_execute+0xb4f/0xf10 net/openvswitch/datapath.c:705 genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114 genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209 netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2572 genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218 netlink_unicast+0x7bd/0x940 net/netlink/af_netlink.c:1361 netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1916 sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
--- net/openvswitch/actions.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/openvswitch/actions.c +6 -1
@@ -357,7 +357,12 @@ static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,static void update_ipv6_checksum (struct sk_buff *skb,u8 l4_proto,__be32 addr[4 ],const __be32 new_addr[4 ]) { -int transport_len = skb->len -skb_transport_offset (skb); +int transport_len; + +if (l4_proto ==NEXTHDR_FRAGMENT ) +return ; + + transport_len = skb->len -skb_transport_offset (skb);if (l4_proto ==NEXTHDR_TCP ) {if (likely (transport_len >=sizeof (struct tcphdr )))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 600/621 vsock: Fix memory leak in vmci_transport_recv_dgram_cb()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilia Gavrilov <[email protected]>
[ Upstream commit 7c24a4e87e219072e5e106f6791146cbf3b056b3 ]
During the closure of a datagram socket, the vmci_transport_recv_dgram_cb() function may be called, which will add the packets
to the socket's backlog; then, after the receive queue is cleared, the __release_sock() function will move the packet back from the socket's backlog to the receive queue, which will lead to a memory leak.
sock_close
__sock_release
__vsock_release
// take ownership by user-space
lock_sock_nested
sock_set_flag(sk, SOCK_DEAD)
vmci_transport_release
vmci_dispatch_dgs
vmci_datagram_invoke_guest_handler
vmci_transport_recv_dgram_cb
sk_receive_skb
if (!sock_owned_by_user(sk))
[...]
(!) else if sk_add_backlog()
[...] (!) skb_queue_purge(&sk->sk_receive_queue)
release_sock
__release_sock
// move all packets from the backlog
// to the receive queue
(!) sk_backlog_rcv
vsock_queue_rcv_skb
[...]
__sock_queue_rcv_skb
if (!sock_flag(sk, SOCK_DEAD))
// Since the socket is "dead", the function will not
// be called
sk->sk_data_ready(sk)
sock_release_ownership(sk);
sock_putAdd a receive queue cleanup in the socket destructor to fix this.
syzkaller report:
unreferenced object 0xffff8880117bfb80 (size 240):
comm "irq/56-vmw_vmci", pid 205, jiffies 4295064448 (age 73.992s) hex dump (first 32 bytes):
78 dc 26 1e 80 88 ff ff 78 dc 26 1e 80 88 ff ff x.&.....x.&.....
00 00 00 00 00 00 00 00 c0 da 26 1e 80 88 ff ff ..........&.....
backtrace:
[<ffffffff82be8d97>] __alloc_skb+0x287/0x330 net/core/skbuff.c:505
[<ffffffffa114bcbd>] vmci_transport_recv_dgram_cb+0xbd/0x210 [vmw_vsock_vmci_transport]
[<ffffffffa05072c6>] vmci_datagram_invoke_guest_handler+0x366/0x450 [vmw_vmci]
[<ffffffffa050ad75>] vmci_dispatch_dgs+0x235/0x490 [vmw_vmci]
[<ffffffffa050b025>] vmci_interrupt+0x55/0x290 [vmw_vmci]
[<ffffffff8137ad2b>] irq_thread_fn+0x8b/0x1a0 kernel/irq/manage.c:1205
[<ffffffff8137c7ae>] irq_thread+0x28e/0x530 kernel/irq/manage.c:1314
[<ffffffff81253dd6>] kthread+0x2e6/0x3a0 kernel/kthread.c:376
[<ffffffff81004392>] ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:295Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/vmw_vsock/af_vsock.c | 2 ++ 1 file changed, 2 insertions(+)
net/vmw_vsock/af_vsock.c +2 -0
@@ -890,6 +890,8 @@ static void vsock_sk_destruct(struct sock *sk) {struct vsock_sock *vsk =vsock_sk (sk); +/* Socket buffers may remain in the queue in VMCI datagram mode */ +__skb_queue_purge (&sk->sk_receive_queue);/* Flush MSG_ZEROCOPY leftovers. */ __skb_queue_purge (&sk->sk_error_queue);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 601/621 drm/vc4: Fix binner slot allocation failing on an idle GPU
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit cca01232d94adcb10f7c8c5bb8ce072b045fcb58 ]
A job's binner slots are returned to bin_alloc_used by vc4_complete_exec(), which runs from the job_done workqueue, but the seqno vc4_v3d_get_bin_slot() waits on is incremented earlier, in the function vc4_irq_finish_render_job(). Therefore, a waiter can wake, retry, and still find the pool full because the worker has not run. By then, the job might have left the render_job_list, so no seqno remains to wait on and the allocation fails returning -ENOMEM.
This scenario can be reproduced on a Raspberry Pi 3 by using a burst of small jobs (e.g. Piglit's quick_gl suite), with userspace seeing a rejected submit for a pool about to become free.
Note that the slots are held from validation until the render completes, so the pool can also be exhausted by jobs still queued on bin_job_list, leaving render_job_list empty and nothing to wait on.
Release the slots from the FRDONE handler and wait on the pool instead of on one job's seqno. This bounds the wait to the actual resource. Also, by claiming the slot inside the wait condition, another submit is unable to take the slot between the wakeup and the retry. vc4_complete_exec() keeps clearing the slots for jobs that never completed, and now wakes the waiters too.
Note that the wait takes a deadline, since the two callers need different ones. The submit path is a user task and can be interrupted, so it waits without one. On the other hand, vc4_overflow_mem_work() runs on a worker and never sees a signal, so it needs a deadline. During a reset, vc4_irq_disable() masks V3D_DRIVER_IRQS before draining the worker, and with those masked nothing can release a slot. This deadlocks: the worker would wait for slots that only the reset can free, while the reset waits in cancel_work_sync() for the worker.
--- drivers/gpu/drm/vc4/vc4_drv.h | 2 +- drivers/gpu/drm/vc4/vc4_gem.c | 8 +++++- drivers/gpu/drm/vc4/vc4_irq.c | 6 +++- drivers/gpu/drm/vc4/vc4_v3d.c | 44 ++++++++++++++---------------- drivers/gpu/drm/vc4/vc4_validate.c | 2 +- 5 files changed, 34 insertions(+), 28 deletions(-)
drivers/gpu/drm/vc4/vc4_drv.h +1 -1
@@ -1054,7 +1054,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,/* vc4_v3d.c */ extern struct platform_driver vc4_v3d_driver;extern const struct of_device_id vc4_v3d_dt_match[]; -int vc4_v3d_get_bin_slot (struct vc4_dev *vc4); +int vc4_v3d_get_bin_slot (struct vc4_dev *vc4,long timeout);int vc4_v3d_bin_bo_get (struct vc4_dev *vc4,bool *used);void vc4_v3d_bin_bo_put (struct vc4_dev *vc4);int vc4_v3d_pm_get (struct vc4_dev *vc4);
drivers/gpu/drm/vc4/vc4_gem.c +7 -1
@@ -877,11 +877,17 @@ vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)drm_gem_object_put (&bo->base.base); } -/* Free up the allocation of any bin slots we used. */ +/* Free up the allocation of any bin slots we used. Jobs that ran to +* completion had their slots released in vc4_irq_finish_render_job(). +* Only jobs that never completed still have slots to be released here. +*/ spin_lock_irqsave (&vc4->job_lock, irqflags); vc4->bin_alloc_used &= ~exec->bin_slots;spin_unlock_irqrestore (&vc4->job_lock, irqflags); +/* Let anyone waiting on the binner pool retry. */ +wake_up_all (&vc4->job_wait_queue); +/* Release the reference on the binner BO if needed. */ if (exec->bin_bo_used)vc4_v3d_bin_bo_put (vc4);
drivers/gpu/drm/vc4/vc4_irq.c +5 -1
@@ -74,7 +74,7 @@ vc4_overflow_mem_work(struct work_struct *work) bo = vc4->bin_bo; - bin_bo_slot =vc4_v3d_get_bin_slot (vc4); + bin_bo_slot =vc4_v3d_get_bin_slot (vc4,msecs_to_jiffies (500 ));if (bin_bo_slot <0 ) {drm_err (&vc4->base,"Couldn't allocate binner overflow mem\n" ); goto complete;
@@ -165,6 +165,10 @@ vc4_irq_finish_render_job(struct drm_device *dev)trace_vc4_rcl_end_irq (dev, exec->seqno); vc4->finished_seqno++; + + vc4->bin_alloc_used &= ~exec->bin_slots; + exec->bin_slots =0 ; +list_move_tail (&exec->head, &vc4->job_done_list); nextbin =vc4_first_bin_job (vc4);
drivers/gpu/drm/vc4/vc4_v3d.c +20 -24
66 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_validate.c +1 -1
@@ -401,7 +401,7 @@ validate_tile_binning_config(VALIDATE_ARGS)return -EINVAL ; } - bin_slot =vc4_v3d_get_bin_slot (vc4); + bin_slot =vc4_v3d_get_bin_slot (vc4,MAX_SCHEDULE_TIMEOUT );if (bin_slot <0 ) {if (bin_slot != -EINTR && bin_slot != -ERESTARTSYS ) { drm_err(dev, "Failed to allocate binner memory: %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 602/621 x86/CPU/AMD: Fix AMD TLBI Erratum #1718
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Borislav Petkov (AMD) <[email protected]>
commit 87db7795cbaaf636ae22ae031f4906db7bb77803 upstream.
The processor may fail to invalidate a TLB entry while executing an INVLPGB/TLBSYNC instruction pair.
Detect the erratum and apply a software workaround when a microcode fix is not present.
--- arch/x86/include/asm/cpufeatures.h | 4 ++++ arch/x86/include/asm/tlb.h | 6 ++++++ arch/x86/kernel/cpu/amd.c | 4 ++++ 3 files changed, 14 insertions(+)
arch/x86/include/asm/cpufeatures.h +4 -0
@@ -458,6 +458,8 @@#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* No Nested Data Breakpoints */ #define X86_FEATURE_WRMSR_XX_BASE_NS (20*32+ 1)/* WRMSR to {FS,GS,KERNEL_GS}_BASE is non-serializing */ #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* LFENCE always serializing / synchronizes RDTSC */ + +#define X86_FEATURE_TLBSYNC_SFW_NO (20*32+ 4)/* TLBI Erratum #1718 fixed in microcode */ #define X86_FEATURE_VERW_CLEAR (20*32+ 5)/* The memory form of VERW mitigates TSA */ #define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6)/* Null Selector Clears Base */
@@ -556,4 +558,6 @@#define X86_BUG_ITS_NATIVE_ONLY X86_BUG( 1*32+ 8)/* "its_native_only" CPU is affected by ITS, VMX is not affected */ #define X86_BUG_TSA X86_BUG( 1*32+ 9)/* "tsa" CPU is affected by Transient Scheduler Attacks */ #define X86_BUG_VMSCAPE X86_BUG( 1*32+10)/* "vmscape" CPU is affected by VMSCAPE attacks from guests */ + +#define X86_BUG_TLBI X86_BUG( 1*32+12)/* "tlbi" AMD TLBI Erratum #1718 */ #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/include/asm/tlb.h +6 -0
@@ -110,6 +110,12 @@ static inline void __tlbsync(void)/* TLBSYNC: supported in binutils >= 0.36. */ asmvolatile (".byte 0x0f, 0x01, 0xff" :::"memory" ); + +if (!static_cpu_has_bug (X86_BUG_TLBI )) +return ; + +/* TLBSYNC: supported in binutils >= 0.36. */ + asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory"); }#else /* Some compilers (I'm looking at you clang!) simply can't do DCE */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -1050,6 +1050,10 @@ static void init_amd_zen5(struct cpuinfomsr_clear_bit (MSR_AMD64_CPUID_FN_7 ,18 );pr_emerg_once ("RDSEED32 is broken. Disabling the corresponding CPUID bit.\n" ); } + +if (cpu_has (c,X86_FEATURE_INVLPGB ) && + !cpu_has (c,X86_FEATURE_TLBSYNC_SFW_NO )) +set_cpu_bug (c,X86_BUG_TLBI ); }static void init_amd (struct cpuinfo_x86 *c)
Greg Kroah-Hartman
maintainerPATCH 603/621 drm/panthor: validate userspace queue count against initialized firmware slot count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Osama Abdelkader <[email protected]>
commit ec86c43dcfff68eab4db9bdafcd3e2b16e342e18 upstream.
In panthor_drv.c:panthor_ioctl_group_create(),
the queue count is validated against the hardcoded maximum:
if (!args->queues.count || args->queues.count > MAX_CS_PER_CSG) return -EINVAL;
However, if the firmware reports fewer slots than MAX_CS_PER_CSG, panthor_fw_init_ifaces() will only initialize that smaller number of stream interfaces.
If unprivileged userspace requests more queues than the firmware reported (but no more than MAX_CS_PER_CSG), cs_slot_prog_locked() fetches an uninitialized stream interface and may crash when dereferencing cs_iface->input->ringbuf_base.
--- drivers/gpu/drm/panthor/panthor_sched.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_sched.c +3 -0
@@ -3547,6 +3547,9 @@ int panthor_group_create(struct panthor_ hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)return -EINVAL ; +if (group_args->queues.count > sched->cs_slot_count) +return -EINVAL ; + group =kzalloc (sizeof (*group),GFP_KERNEL );if (!group)return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 604/621 btrfs: make sure EXTENT_BUFFER_READING is cleared under refs_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 690c2accacb1aca91ab8186d15dee56da8723f31 upstream.
[FALSE ALERTS]
There is a bug report that the warning inside invalidate_and_check_btree_folios() got triggered during btrfs/298:
BTRFS info (device sdd): first mount of filesystem f9bf732a-a19b-44b9-99a7-614ddff168e2
BTRFS info (device sdd): using crc32c checksum algorithm
BTRFS error (device sdd): failed to find fsid cb2fdb42-b638-4f2f-badd-4127467ba674 when attempting to open seed devices BTRFS error (device sdd): failed to read chunk tree: -2
------------[ cut here ]------------ WARNING: disk-io.c:3342 at invalidate_and_check_btree_folios+0x260/0x3c0 [btrfs], CPU#4: mount/125993 CPU: 4 UID: 0 PID: 125993 Comm: mount Tainted: G W OE 7.1.0-rc7-custom+ #1 PREEMPT(full) Hardware name: QEMU KVM Virtual Machine, BIOS edk2-20250812-19.fc42 08/12/2025 Call trace: invalidate_and_check_btree_folios+0x260/0x3c0 [btrfs] (P) open_ctree+0x1f50/0x23b0 [btrfs] btrfs_get_tree+0x89c/0xc48 [btrfs] vfs_get_tree+0x30/0x110 vfs_cmd_create+0x58/0xe8 __arm64_sys_fsconfig+0x39c/0x518 invoke_syscall.constprop.0+0x48/0x120 el0_svc_common.constprop.0+0x40/0xe8 do_el0_svc+0x24/0x38 el0_svc+0x50/0x310 el0t_64_sync_handler+0xa0/0xe8 el0t_64_sync+0x198/0x1a0 ---[ end trace 0000000000000000 ]--- BTRFS warning (device sdd): unable to release extent buffer 365985792 owner 3 gen 17 refs 3 flags 0x5
[CAUSE]
In that invalidate_and_check_btree_folios() we wait for the eb to finish its read, then check if it's only held by us and the btree inode.
If not, then do a warning as it may be still held, and could cause problems.
But there is a small window where the check can lead to false alerts:
Thread A (Read endio) | Thread B (Unmount)
----------------------------------+-------------------------------------
end_bbio_meta_read() | | The eb has one extra ref held | | by the reader, and has | | EXTENT_BUFFER_READING flag set | invalidate_and_check_btree_folios() | | | |- clear_extent_buffer_reading() | | | | |- wait_on_bit_io(); | | | The EXTENT_BUFFER_READING flag is | | | cleared | | |- if (refcount_read(eb->refs) > 2) | | The eb is held by the read, us | | and btree inode, thus it | | will trigger the warning |- free_extent_buffer() |
[FIX]
Introduce a helper, free_extent_buffer_clear_reading().
If the new parameter, @clear_reading, is set, we will hold the spinlock at the beginning of free_extent_buffer_clear_reading() to make sure the EXTENT_BUFFER_READING flag is cleared inside the same critical section of decreasing refs.
Now free_extent_buffer() will just call free_extent_buffer_clear_reading() with @clear_reading set to false, so no behavior change.
But for end_bbio_meta_read(), it will not clear_extent_buffer_reading() directly, but pass @clear_reading as true.
Then inside invalidate_and_check_btree_folios(), hold the refs_lock before reading refs.
So that we eliminate the race window completely.
--- fs/btrfs/disk-io.c | 16 ++++++++++++++-- fs/btrfs/extent_io.c | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 12 deletions(-)
fs/btrfs/disk-io.c +14 -2
@@ -3279,6 +3279,8 @@ static void invalidate_and_check_btree_f*/ rcu_read_lock ();xa_for_each (&fs_info->buffer_tree, index, eb) { +unsigned int refs; +/* Increase the ref so that the eb won't disappear. */ if (!refcount_inc_not_zero (&eb->refs))continue ;
@@ -3289,16 +3291,26 @@ static void invalidate_and_check_btree_fwait_on_bit_io (&eb->bflags,EXTENT_BUFFER_READING ,TASK_UNINTERRUPTIBLE );/* +* We hold the spinlock to make sure above +* EXTENT_BUFFER_READING flag is cleared with the held +* ref dropped. +* Or we can hit a race window and lead to false alerts. +*/ +spin_lock (&eb->refs_lock); + refs =refcount_read (&eb->refs); +spin_unlock (&eb->refs_lock); + +/* * The refs threshold is 2, one held by us at the beginning * of the loop, one for the ownership in the buffer tree. */ -if (unlikely (refcount_read (&eb->refs) >2 ||extent_buffer_under_io (eb))) { +if (unlikely (refs >2 ||extent_buffer_under_io (eb))) {WARN_ON_ONCE (IS_ENABLED (CONFIG_BTRFS_DEBUG ));btrfs_warn (fs_info,"unable to release extent buffer %llu owner %llu gen %llu refs %u flags 0x%lx" , eb->start,btrfs_header_owner (eb),btrfs_header_generation (eb), -refcount_read (&eb->refs), eb->bflags); + refs, eb->bflags); }free_extent_buffer (eb);rcu_read_lock ();
fs/btrfs/extent_io.c +33 -10
81 lines not on this page · raw message
Quoted 7 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.18.57 release. There are 621 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 Thu, 15 Oct 2026 11:28:22 +0000. Anything received after that time might be too late.
Build failing on amd64:
/usr/x86_64-pc-linux-gnu/binutils-bin/2.47/ld: vmlinux.o: in function `gss_krb5_get_mic_v2':
(.text+0xfc2762): undefined reference to crypto_krb5_get_mic' /usr/x86_64-pc-linux-gnu/binutils-bin/2.47/ld: vmlinux.o: in function gss_krb5_verify_mic_v2':
(.text+0xfc293a): undefined reference to crypto_krb5_verify_mic' /usr/x86_64-pc-linux-gnu/binutils-bin/2.47/ld: vmlinux.o: in function gss_krb5_aead_encrypt':
(.text+0xfc47a1): undefined reference to crypto_krb5_encrypt' /usr/x86_64-pc-linux-gnu/binutils-bin/2.47/ld: vmlinux.o: in function gss_krb5_aead_decrypt':
(.text+0xfc48f8): undefined reference to `crypto_krb5_decrypt'
make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1
make[1]: *** [/usr/src/linux-stable-rc/Makefile:1272: vmlinux] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Greg Kroah-Hartman
maintainerPATCH 605/621 cifs: consolidate time_last_write stamp into _cifsFileInfo_put()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 0e3ea5445c228048f937ad5a944c27859a78f971 upstream.
The time_last_write stamp was scattered across cifs_close(), smb2_deferred_work_close(), and the three drain functions in misc.c. This missed the case where background I/O holds the final reference after userspace close() returns, and required explicit maintenance at each close-path site.
Move the smp_store_release() into _cifsFileInfo_put(), immediately before releasing open_file_lock. This single location covers all close paths unconditionally: normal close, background I/O dropping the final reference, deferred close via timer or external drain. The spinlock's store-release/load-acquire pairing with is_inode_writable() already provides the ordering guarantee documented in is_size_safe_to_change().
Remove the now-redundant stamps from cifs_close(), smb2_deferred_work_close(), and all six stamp sites in the misc.c deferred-close drain functions.
--- fs/smb/client/file.c | 37 ++++++++++++++++--------------------- fs/smb/client/misc.c | 51 ++++++--------------------------------------------- 2 files changed, 22 insertions(+), 66 deletions(-)
fs/smb/client/file.c +16 -21
@@ -906,6 +906,14 @@ void _cifsFileInfo_put(struct cifsFileIncifs_set_oplock_level (cifsi,0 ); } +if (OPEN_FMODE (cifs_file->f_flags) &FMODE_WRITE ) { +/* Stamp while open_file_lock is held; covers all close paths +* including background I/O. Pairs with smp_load_acquire() in +* is_size_safe_to_change(). +*/ +smp_store_release (&cifsi->time_last_write, jiffies); + } +spin_unlock (&cifsi->open_file_lock);spin_unlock (&tcon->open_file_lock);
@@ -1420,15 +1428,6 @@ void smb2_deferred_work_close(struct worcifs_del_deferred_close (cfile); cfile->deferred_close_scheduled = false;spin_unlock (&cinode->deferred_lock); -/* -* Refresh time_last_write immediately before the actual server close -* so the protection window is anchored to the real close time, not -* the earlier userspace close time stored by cifs_close(). -*/ -if (OPEN_FMODE (cfile->f_flags) &FMODE_WRITE ) { -/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ -smp_store_release (&cinode->time_last_write, jiffies); - }_cifsFileInfo_put (cfile, true, false); }
@@ -1457,10 +1456,6 @@ int cifs_close(struct inode *inode, struif (file->private_data !=NULL ) { cfile = file->private_data; file->private_data =NULL ; -if (file->f_mode &FMODE_WRITE ) { -/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ -smp_store_release (&cinode->time_last_write, jiffies); - } dclose =kmalloc (sizeof (struct cifs_deferred_close ),GFP_KERNEL );if ((cfile->status_file_deleted == false) && (smb2_can_defer_close (inode, dclose))) {
@@ -3171,13 +3166,13 @@ bool is_size_safe_to_change(struct cifsI* No writable handles open. Check whether we are within the attribute * cache validity window of a recent local modification. * -* For the close() path: cifs_close() calls smp_store_release() on -* time_last_write before _cifsFileInfo_put() removes the handle under -* open_file_lock. That spin_unlock() is a store-release that pairs -* with the spin_lock() (load-acquire) in is_inode_writable() above, -* so if is_inode_writable() returned false the smp_load_acquire() -* below is guaranteed to observe any time_last_write update from a -* concurrent close(). +* For the close() path: _cifsFileInfo_put() stamps time_last_write +* (via smp_store_release()) before releasing open_file_lock. That +* spin_unlock() is a store-release that pairs with the spin_lock() +* (load-acquire) in is_inode_writable() above, so if +* is_inode_writable() returned false the smp_load_acquire() below is +* guaranteed to observe any time_last_write update from a concurrent +* close(), covering all close paths including background I/O. * * For the setattr/truncate paths: those callers use smp_store_release() * directly; the smp_load_acquire() below pairs with that store. There
@@ -3192,7 +3187,7 @@ bool is_size_safe_to_change(struct cifsI* jiffies is still close to INITIAL_JIFFIES on 32-bit systems. */ if (from_readdir) { -/* Pairs with smp_store_release() at close and truncate sites. */ +/* Pairs with smp_store_release() in _cifsFileInfo_put() and setattr. */ tlw =smp_load_acquire (&cifsInode->time_last_write);if (tlw &&time_before (jiffies, tlw + cifs_sb->ctx->acregmax))return false;
fs/smb/client/misc.c +6 -45
78 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 579/621 cgroup/cpuset: Call is_in_v2_mode() after acquiring cpuset_mutex in cpuset_handle_hotplug()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Waiman Long <[email protected]>
[ Upstream commit b8eb5fd5bdb4c03758b056c70e5e1d962ca89757 ]
It is reported by sashiko that calling is_in_v2_mode() outside of cpuset_mutex critical section in cpuset_handle_hotplug() can introduce a TOCTOU race where cgroup hierarchy may have changed from v1 to v2 or vice versa after is_in_v2_mode() is called leading to erroneously skip the allocation of tmpmasks or incorrectly modify cpus_allowed masks, resulting in cpuset state corruption. Fix that by calling is_in_v2_mode() after acquiring the cpuset_mutex.
--- kernel/cgroup/cpuset.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/cgroup/cpuset.c +5 -4
@@ -4113,15 +4113,16 @@ static void cpuset_handle_hotplug(void)static cpumask_t new_cpus;static nodemask_t new_mems;bool cpus_updated, mems_updated; -bool on_dfl =is_in_v2_mode (); +bool on_dfl;struct tmpmasks tmp, *ptmp =NULL ; -if (on_dfl && !alloc_tmpmasks (&tmp)) - ptmp = &tmp; -lockdep_assert_cpus_held ();mutex_lock (&cpuset_mutex); + on_dfl =is_in_v2_mode (); +if (on_dfl && !alloc_tmpmasks (&tmp)) + ptmp = &tmp; +/* fetch the available cpus/mems and find out which changed how */ cpumask_copy (&new_cpus, cpu_active_mask); new_mems = node_states[N_MEMORY ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 606/621 netfs, afs: Fix symlink reading
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
commit c51e89c5b5db3e1927738fad7cd18b66dde68aed upstream.
Fix the reading of symlinks from the cache in afs by making netfslib trim the amount read down to i_size. The problem is that afs sets the size of the iterator to the size of the buffer (PAGE_SIZE) so that the cache can round the read size up to the cache's DIO size.
Note that this also impacts the reading of AFS mountpoints as they're just stored as symlinks with an odd file mode.
--- fs/netfs/read_collect.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/netfs/read_collect.c +5 -0
@@ -409,6 +409,11 @@ static void netfs_rreq_assess_single(strnetfs_single_mark_inode_dirty (rreq->inode); } +/* To do DIO, the cache has to round the size up, so we need to undo +* the rounding. +*/ + rreq->transferred =min (rreq->transferred, rreq->i_size); +if (rreq->iocb) { rreq->iocb->ki_pos += rreq->transferred;if (rreq->iocb->ki_complete) {
Greg Kroah-Hartman
maintainerPATCH 607/621 media: verisilicon: Fix kernel panic due to __initconst misuse
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Qian <[email protected]>
commit e8d97c270cb46a2a88739019d0f8547adc7d97da upstream.
Fix a kernel panic when probing the driver as a module:
Unable to handle kernel paging request at virtual address ffffd9c18eb05000 of_find_matching_node_and_match+0x5c/0x1a0 hantro_probe+0x2f4/0x7d0 [hantro_vpu]
The imx8mq_vpu_shared_resources array is referenced by variant structures through their shared_devices field. When built as a module, __initconst causes this data to be freed after module init, but it's later accessed during probe, causing a page fault.
The imx8mq_vpu_shared_resources is referenced from non-init code, so keeping __initconst or __initconst_or_module here is wrong.
Drop the __initconst annotation and let it live in the normal .rodata section.
A bug of __initconst called from regular non-init probe code leading to bugs during probe deferrals or during unbind-bind cycles.
--- drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +1 -1
@@ -343,7 +343,7 @@ const struct hantro_variant imx8mq_vpu_v .num_regs = ARRAY_SIZE(imx8mq_reg_names) }; -static const struct of_device_id imx8mq_vpu_shared_resources[]__initconst = { +static const struct of_device_id imx8mq_vpu_shared_resources[] = { { .compatible ="nxp,imx8mq-vpu-g1" , }, { .compatible ="nxp,imx8mq-vpu-g2" , }, {/* sentinel */ }
Greg Kroah-Hartman
maintainerPATCH 608/621 net: fix backlog_unlock_irq_restore() vs CONFIG_PREEMPT_RT
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 26f29b14916964043bc25b55ad1b9f5e9a12ca53 upstream.
CONFIG_PREEMPT_RT is special, make this clear in backlog_lock_irq_save() and backlog_unlock_irq_restore().
The issue shows up with CONFIG_DEBUG_IRQFLAGS=y
raw_local_irq_restore() called with IRQs enabled
WARNING: kernel/locking/irqflag-debug.c:10 at warn_bogus_irq_restore+0xc/0x20 kernel/locking/irqflag-debug.c:10, CPU#1: aoe_tx0/1321
Modules linked in:
CPU: 1 UID: 0 PID: 1321 Comm: aoe_tx0 Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/24/2026
RIP: 0010:warn_bogus_irq_restore+0xc/0x20 kernel/locking/irqflag-debug.c:10
Call Trace:
<TASK>
backlog_unlock_irq_restore net/core/dev.c:253 [inline]
enqueue_to_backlog+0x525/0xcf0 net/core/dev.c:5347
netif_rx_internal+0x120/0x550 net/core/dev.c:5659
__netif_rx+0xa9/0x110 net/core/dev.c:5679
loopback_xmit+0x43a/0x660 drivers/net/loopback.c:90
__netdev_start_xmit include/linux/netdevice.h:5275 [inline]
netdev_start_xmit include/linux/netdevice.h:5284 [inline]
xmit_one net/core/dev.c:3864 [inline]
dev_hard_start_xmit+0x2df/0x830 net/core/dev.c:3880
__dev_queue_xmit+0x16f4/0x3990 net/core/dev.c:4829
dev_queue_xmit include/linux/netdevice.h:3384 [inline]--- net/core/dev.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
net/core/dev.c +12 -5
@@ -231,10 +231,13 @@ static bool use_backlog_threads(void)static inline void backlog_lock_irq_save (struct softnet_data *sd,unsigned long *flags) { -if (IS_ENABLED (CONFIG_RPS ) ||use_backlog_threads ()) +if (IS_ENABLED (CONFIG_PREEMPT_RT )) {spin_lock_irqsave (&sd->input_pkt_queue.lock, *flags); -else + }else {local_irq_save (*flags); +if (IS_ENABLED (CONFIG_RPS ) ||use_backlog_threads ()) +spin_lock (&sd->input_pkt_queue.lock); + } }static inline void backlog_lock_irq_disable (struct softnet_data *sd)
@@ -248,9 +251,13 @@ static inline void backlog_lock_irq_disastatic inline void backlog_unlock_irq_restore (struct softnet_data *sd,unsigned long flags) { -if (IS_ENABLED (CONFIG_RPS ) ||use_backlog_threads ()) -spin_unlock (&sd->input_pkt_queue.lock); -local_irq_restore (flags); +if (IS_ENABLED (CONFIG_PREEMPT_RT )) { +spin_unlock_irqrestore (&sd->input_pkt_queue.lock, flags); + }else { +if (IS_ENABLED (CONFIG_RPS ) ||use_backlog_threads ()) +spin_unlock (&sd->input_pkt_queue.lock); +local_irq_restore (flags); + } }static inline void backlog_unlock_irq_enable (struct softnet_data *sd)
Greg Kroah-Hartman
maintainerPATCH 609/621 netfs: Fix missing alloc tagging of direct mempool allocations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Ge <[email protected]>
commit b78b728e21c32ec4c330b299f657fb1eb02dffc2 upstream.
Commit 1d78d56c43ef ("netfs: Fix folio_queue ENOMEM in writeback by adding a mempool") added a mempool for the folio_queues and made the request, subrequest and folio_queue allocations distinguish between writeback and everything else. Writeback is part of memory reclaim and must not fail due to ENOMEM, so it allocates under GFP_NOFS through mempool_alloc(), which may dip into the pool's reserve and, if that runs empty, wait for elements to be returned. The GFP_KERNEL paths, which can return -ENOMEM to their callers, invoke the pool's ->alloc() callback directly instead.
The direct call, however, skips the alloc_hooks() wrapper that the mempool_alloc() macro provides. The pool callbacks, mempool_alloc_slab() and mempool_kmalloc(), call kmem_cache_alloc_noprof() and kmalloc_noprof() and rely on current->alloc_tag having been set by the caller. With CONFIG_MEM_ALLOC_PROFILING_DEBUG=y this leads to
current->alloc_tag not set
WARNING: ./include/linux/alloc_tag.h:161 at __alloc_tagging_slab_alloc_hook alloc_tag was not set
WARNING: ./include/linux/alloc_tag.h:166 at __alloc_tagging_slab_free_hook
at allocation and free time respectively, as reported when reading files on a CIFS mount. The allocations are also missing from /proc/allocinfo.
Wrap the direct ->alloc() invocations in alloc_hooks() with a new mempool_alloc_noreserve() helper in include/linux/mempool.h, next to the other alloc_hooks()-wrapped macros such as mempool_alloc(). The GFP_KERNEL paths keep their failable allocation semantics, they just get tagged now.
--- fs/netfs/objects.c | 4 ++-- fs/netfs/rolling_buffer.c | 2 +- include/linux/mempool.h | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-)
fs/netfs/objects.c +2 -2
@@ -34,7 +34,7 @@ struct netfs_io_request *netfs_alloc_req rreq =mempool_alloc (mempool, gfp); }else { - rreq = mempool->alloc (gfp, mempool->pool_data); + rreq =mempool_alloc_noreserve (mempool, gfp);if (!rreq)return ERR_PTR (-ENOMEM ); }
@@ -206,7 +206,7 @@ struct netfs_io_subrequest *netfs_alloc_struct kmem_cache *cache = mempool->pool_data;if (rreq->gfp ==GFP_KERNEL ) - subreq = mempool->alloc (rreq->gfp, mempool->pool_data); + subreq =mempool_alloc_noreserve (mempool, rreq->gfp);else subreq =mempool_alloc (mempool, rreq->gfp);if (!subreq)
fs/netfs/rolling_buffer.c +1 -1
@@ -29,7 +29,7 @@ struct folio_queue *netfs_folioq_alloc(ustruct folio_queue *fq;if (gfp ==GFP_KERNEL ) - fq = netfs_folioq_pool.alloc (gfp, netfs_folioq_pool.pool_data); + fq =mempool_alloc_noreserve (&netfs_folioq_pool, gfp);else fq =mempool_alloc (&netfs_folioq_pool, gfp);if (fq) {
include/linux/mempool.h +7 -0
@@ -67,6 +67,13 @@ extern void *mempool_alloc_noprof(mempoo#define mempool_alloc (...) \ alloc_hooks(mempool_alloc_noprof(__VA_ARGS__)) +/* +* Allocate a new element without dipping into the pool's reserves or +* waiting. Returns NULL on failure. +*/ +#define mempool_alloc_noreserve (_pool, _gfp) \ + alloc_hooks((_pool)->alloc(_gfp, (_pool)->pool_data)) +extern void *mempool_alloc_preallocated (mempool_t *pool) __malloc;extern void mempool_free (void *element,mempool_t *pool);
Greg Kroah-Hartman
maintainerPATCH 610/621 workqueue: fix devm_alloc_workqueue() va_list misuse
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
commit 0de4cb473aed57ee4ba7e0551ad27bddc19fc519 upstream.
devm_alloc_workqueue() built a va_list and passed it as a single positional argument to the variadic alloc_workqueue() macro:
va_start(args, max_active); wq = alloc_workqueue(fmt, flags, max_active, args); va_end(args);
C does not allow forwarding a va_list through a ... parameter. alloc_workqueue() expands to alloc_workqueue_noprof(), which runs its own va_start() over its ... params, so the inner vsnprintf(wq->name, sizeof(wq->name), fmt, args) in __alloc_workqueue() received the outer va_list object as the first variadic slot rather than the caller's actual format arguments.
Add a new static helper alloc_workqueue_va() that wraps __alloc_workqueue() and runs wq_init_lockdep() on success, and fold both alloc_workqueue_noprof() and devm_alloc_workqueue_noprof() onto it as suggested by Tejun.
The wq_init_lockdep() step is required on the devm path too, otherwise __flush_workqueue()'s on-stack COMPLETION_INITIALIZER_ONSTACK_MAP would NULL-deref wq->lockdep_map.
No caller changes are required. devm_alloc_ordered_workqueue() is a macro forwarding to devm_alloc_workqueue() and inherits the fix. Two in-tree callers actively trigger the broken path on every probe:
drivers/power/supply/mt6370-charger.c:889
drivers/power/supply/max77705_charger.c:649
both of which use devm_alloc_ordered_workqueue(dev, "%s", 0, dev_name(dev)).
A standalone reproducer module is available at[1].
--- include/linux/workqueue.h | 6 ++++-- kernel/workqueue.c | 28 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-)
include/linux/workqueue.h +4 -2
@@ -529,8 +529,10 @@ alloc_workqueue_noprof(const char *fmt,* Pointer to the allocated workqueue on success, %NULL on failure. */ __printf(2, 5) struct workqueue_struct * -devm_alloc_workqueue (struct device *dev,const char *fmt,unsigned int flags, -int max_active, ...); +devm_alloc_workqueue_noprof (struct device *dev,const char *fmt, +unsigned int flags,int max_active, ...); +#define devm_alloc_workqueue (...) \ + alloc_hooks(devm_alloc_workqueue_noprof(__VA_ARGS__))#ifdef CONFIG_LOCKDEP /**
kernel/workqueue.c +19 -9
@@ -5875,6 +5875,20 @@ err_destroy:return NULL ; } +static struct workqueue_struct *alloc_workqueue_va (const char *fmt, +unsigned int flags, +int max_active, +va_list args) +{ +struct workqueue_struct *wq; + + wq =__alloc_workqueue (fmt, flags, max_active, args); +if (wq) +wq_init_lockdep (wq); + +return wq; +} + __printf(1, 4) struct workqueue_struct *alloc_workqueue_noprof(const char *fmt, unsigned int flags,
@@ -5884,12 +5898,8 @@ struct workqueue_struct *alloc_workqueueva_list args;va_start (args, max_active); - wq =__alloc_workqueue (fmt, flags, max_active, args); + wq =alloc_workqueue_va (fmt, flags, max_active, args);va_end (args); -if (!wq) -return NULL ; - -wq_init_lockdep (wq);return wq; }
@@ -5901,15 +5911,15 @@ static void devm_workqueue_release(void } __printf(2, 5) struct workqueue_struct * -devm_alloc_workqueue (struct device *dev,const char *fmt,unsigned int flags, -int max_active, ...) +devm_alloc_workqueue_noprof (struct device *dev,const char *fmt, +unsigned int flags,int max_active, ...) {struct workqueue_struct *wq;va_list args;int ret;va_start (args, max_active); - wq =alloc_workqueue (fmt, flags, max_active, args); + wq =alloc_workqueue_va (fmt, flags, max_active, args);va_end (args);if (!wq)return NULL ;
@@ -5920,7 +5930,7 @@ devm_alloc_workqueue(struct device *dev,return wq; } -EXPORT_SYMBOL_GPL (devm_alloc_workqueue); +EXPORT_SYMBOL_GPL (devm_alloc_workqueue_noprof);#ifdef CONFIG_LOCKDEP __printf (1 ,5 )
Greg Kroah-Hartman
maintainerPATCH 611/621 ice: fix broken Rx on VFs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Lobakin <[email protected]>
commit 436fa8e7d1a119ec90f39e7c2ce0f3a146652899 upstream.
Since the tagged commit, ice stopped respecting Rx buffer length passed from VFs.
At that point, the buffer length was hardcoded in ice, so VFs still worked up to some point (until, for example, a VF wanted an MTU larger than its PF).
The next commit 93f53db9f9dc ("ice: switch to Page Pool"), broke Rx on VFs completely since ice started accounting per-queue buffer lengths again, but now VF queues always had their length zeroed, as ice was already ignoring what iavf was passing to it.
Restore the line that initializes the buffer length on VF queues basing on the virtchnl messages.
--- drivers/net/ethernet/intel/ice/virt/queues.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/intel/ice/virt/queues.c +3 -0
@@ -863,6 +863,9 @@ int ice_vc_cfg_qs_msg(struct ice_vf *vf, (qpi->rxq.databuffer_size > ((16 * 1024) - 128) || qpi->rxq.databuffer_size < 128)) goto error_param; + + ring->rx_buf_len = qpi->rxq.databuffer_size; +if (qpi->rxq.max_pkt_size > max_frame_size || qpi->rxq.max_pkt_size <64 ) goto error_param;
Greg Kroah-Hartman
maintainerPATCH 612/621 s390/zcrypt: Improve CCA CPRB length and overflow checks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit 35ac6754ba6da45fd193f5ce3f665f7490b830d5 upstream.
The xcrb_msg_to_type6cprb_msgx() function lacks proper input validation, creating security vulnerabilities:
1. Integer overflow after CEIL4 alignment: Signed int variables could overflow during 4-byte boundary alignment, causing undersized buffer allocations or incorrect bounds checking.
2. Missing minimum size validation: The CPRBX structure is copied from userspace without verifying sufficient buffer length. Undersized buffers cause uninitialized memory access when reading structure fields like cprbx.cprb_len and cprbx.domain.
3. Arithmetic overflow in sum calculations: Adding control block and data block sizes could overflow, bypassing size checks and enabling buffer overflows.
Fix by using size_t for length calculations, adding U32_MAX boundary checks after alignment, validating minimum control block size before copying from userspace, and detecting sum calculation overflows.
--- drivers/s390/crypto/zcrypt_msgtype6.c | 81 +++++++++++++++------------------- 1 file changed, 37 insertions(+), 44 deletions(-)
drivers/s390/crypto/zcrypt_msgtype6.c +37 -44
@@ -343,49 +343,39 @@ static int xcrb_msg_to_type6cprb_msgx(bo }; }__packed * msg = ap_msg->msg; -int rcblen =CEIL4 (xcrb->request_control_blk_length); -int req_sumlen, resp_sumlen; -char *req_data = ap_msg->msg +sizeof (struct type6_hdr ) + rcblen; -char *function_code; - -if (CEIL4 (xcrb->request_control_blk_length) < - xcrb->request_control_blk_length) -return -EINVAL ;/* overflow after alignment*/ - -/* length checks */ - ap_msg->len =sizeof (struct type6_hdr ) + -CEIL4 (xcrb->request_control_blk_length) + - xcrb->request_data_length; +size_t req_cblen, rep_cblen, req_sumlen, rep_sumlen; +char *function_code, *req_data; + +/* request length and overflow checks */ +if (xcrb->request_control_blk_length <sizeof (struct CPRBX )) +return -EINVAL ; + req_cblen =CEIL4 ((size_t )xcrb->request_control_blk_length); +if (req_cblen >U32_MAX ) +return -EINVAL ; + req_sumlen = req_cblen + xcrb->request_data_length; +if (req_sumlen >U32_MAX ) +return -EINVAL ; + ap_msg->len =sizeof (struct type6_hdr ) + req_sumlen;if (ap_msg->len > ap_msg->bufsize)return -EINVAL ; - -/* -* Overflow check -* sum must be greater (or equal) than the largest operand -*/ - req_sumlen =CEIL4 (xcrb->request_control_blk_length) + - xcrb->request_data_length; -if ((CEIL4 (xcrb->request_control_blk_length) <= - xcrb->request_data_length) ? +if (req_cblen <= xcrb->request_data_length ? req_sumlen < xcrb->request_data_length : - req_sumlen <CEIL4 (xcrb->request_control_blk_length)) { + req_sumlen < req_cblen) {return -EINVAL ; } -if (CEIL4 (xcrb->reply_control_blk_length) < - xcrb->reply_control_blk_length) -return -EINVAL ;/* overflow after alignment*/ - -/* -* Overflow check -* sum must be greater (or equal) than the largest operand -*/ - resp_sumlen =CEIL4 (xcrb->reply_control_blk_length) + - xcrb->reply_data_length; -if ((CEIL4 (xcrb->reply_control_blk_length) <= - xcrb->reply_data_length) ? - resp_sumlen < xcrb->reply_data_length : - resp_sumlen <CEIL4 (xcrb->reply_control_blk_length)) { +/* reply length and overflow checks */ +if (xcrb->reply_control_blk_length <sizeof (struct CPRBX )) +return -EINVAL ; + rep_cblen =CEIL4 ((size_t )xcrb->reply_control_blk_length); +if (rep_cblen >U32_MAX ) +return -EINVAL ; + rep_sumlen = rep_cblen + xcrb->reply_data_length; +if (rep_sumlen >U32_MAX ) +return -EINVAL ; +if (rep_cblen <= xcrb->reply_data_length ? + rep_sumlen < xcrb->reply_data_length : + rep_sumlen < rep_cblen) {return -EINVAL ; }
@@ -394,7 +384,7 @@ static int xcrb_msg_to_type6cprb_msgx(bomemcpy (msg->hdr.agent_id, &xcrb->agent_ID,sizeof (xcrb->agent_ID)); msg->hdr.tocardlen1 = xcrb->request_control_blk_length;if (xcrb->request_data_length) { - msg->hdr.offset2 = msg->hdr.offset1 + rcblen; + msg->hdr.offset2 = msg->hdr.offset1 + req_cblen; msg->hdr.tocardlen2 = xcrb->request_data_length; } msg->hdr.fromcardlen1 = xcrb->reply_control_blk_length;
@@ -405,8 +395,8 @@ static int xcrb_msg_to_type6cprb_msgx(bo xcrb->request_control_blk_addr, xcrb->request_control_blk_length))return -EFAULT ; -if (msg->cprbx.cprb_len +sizeof (msg->hdr.function_code) > - xcrb->request_control_blk_length) +/* copy subfunction code into AP msg type 6 function code field */ +if (msg->cprbx.cprb_len > req_cblen -sizeof (msg->hdr.function_code))return -EINVAL ; function_code = ((unsigned char *)&msg->cprbx) + msg->cprbx.cprb_len; memcpy(msg->hdr.function_code, function_code,
@@ -438,10 +428,13 @@ static int xcrb_msg_to_type6cprb_msgx(bo }/* copy data block */ -if (xcrb->request_data_length && -z_copy_from_user (userspace, req_data, xcrb->request_data_address, - xcrb->request_data_length)) -return -EFAULT ; +if (xcrb->request_data_length) { + req_data = ap_msg->msg +sizeof (struct type6_hdr ) + req_cblen; +if (z_copy_from_user (userspace, req_data, + xcrb->request_data_address, + xcrb->request_data_length)) +return -EFAULT ; + }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 613/621 s390/zcrypt: Improve EP11 CPRB length and overflow checks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit 17ac0bc866fc624cd05f022dcd8b730c0af11bb1 upstream.
The xcrb_msg_to_type6_ep11cprb_msgx() function lacks proper input validation, creating security vulnerabilities:
1. Missing minimum size validation: The ep11_cprb structure and subsequent payload fields (pld_tag, pld_lenfmt) are copied from userspace without verifying sufficient buffer length.
2. Arithmetic overflow in length calculations: CEIL4 alignment could overflow, bypassing size checks and enabling buffer overflows.
3. The payload is asn1 encoded but the function just uses a simple c struct overlay to access some fields of the payload.
Fix by using size_t for length calculations, adding U32_MAX boundary checks after alignment, and validating minimum request size and minimum reply size before copying from userspace. Do a very simple asn1 parsing of the payload up to the function value field.
--- drivers/s390/crypto/zcrypt_msgtype6.c | 152 +++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 39 deletions(-)
drivers/s390/crypto/zcrypt_msgtype6.c +113 -39
@@ -20,6 +20,7 @@#include <linux/slab.h> #include <linux/atomic.h> #include <linux/uaccess.h> +#include <linux/unaligned.h> #include "ap_bus.h" #include "zcrypt_api.h"
@@ -35,6 +36,9 @@#define CEXXC_RESPONSE_TYPE_XCRB 1#define CEXXC_RESPONSE_TYPE_EP11 2 +/* smallest possible EP11 payload size */ +#define MIN_EP11_PAYLOAD_SIZE 5 +MODULE_AUTHOR ("IBM Corporation" );MODULE_DESCRIPTION ("Cryptographic Coprocessor (message type 6), " \"Copyright IBM Corp. 2001, 2023" );
@@ -439,12 +443,59 @@ static int xcrb_msg_to_type6cprb_msgx(boreturn 0 ; } +/* +* Simple asn1 int reader/decoder helper function +* Returns number of bytes processed or < 0 on failure +* Only accepts int length values of 1, 2 or 4. +*/ +static inline int asn1_int_decode (const u8 *buf,size_t intlen,u32 *u) +{ +switch (intlen) { +case 1 : + *u = (u32)(*buf); +return 1 ; +case 2 : + *u = (u32 )get_unaligned_be16 (buf); +return 2 ; +case 4 : + *u = (u32 )get_unaligned_be32 (buf); +return 4 ; +default : +return -EINVAL ; + } +} + +/* +* Simple asn1 length parse helper function +* Returns number of bytes processed or < 0 on failure +* Only accepts length encoded within the length octet +* or for long form 1, 2 or 4 octet length bytes. +*/ +static inline int asn1_length_decode (const u8 *buf,size_t buflen,u32 *u) +{ +int i; + +if (buflen <1 ) +return -EINVAL ; + +if (*buf <128 ) { + *u = (u32)(*buf &0x7F ); +return 1 ; + } + + i = *buf &0x7F ; +if (--buflen < i) +return -EINVAL ; + i =asn1_int_decode (++buf, i, u); + +return i <0 ? i : i +1 ; +} +static int xcrb_msg_to_type6_ep11cprb_msgx (bool userspace,struct ap_message *ap_msg,struct ep11_urb *xcrb,unsigned int *fcode,unsigned int *domain) { -unsigned int lfmt;static struct type6_hdr static_type6_ep11_hdr = { .type =0x06 , .rqid = {0x00 ,0x01 },
@@ -457,34 +508,32 @@ static int xcrb_msg_to_type6_ep11cprb_msstruct {struct type6_hdr hdr;union { -struct { -struct ep11_cprb cprbx; -unsigned char pld_tag;/* fixed value 0x30 */ -unsigned char pld_lenfmt;/* length format */ - } __packed; +struct ep11_cprb cprbx; DECLARE_FLEX_ARRAY(u8, userdata); }; } __packed * msg = ap_msg->msg; -struct pld_hdr { -unsigned char func_tag;/* fixed value 0x4 */ -unsigned char func_len;/* fixed value 0x4 */ -unsigned int func_val;/* function ID */ -unsigned char dom_tag;/* fixed value 0x4 */ -unsigned char dom_len;/* fixed value 0x4 */ -unsigned int dom_val;/* domain id */ - } __packed * payload_hdr = NULL; +size_t req_len, rep_len, pld_len; +unsigned char *pld; +int offs =0 , i; +unsigned int u; -if (CEIL4 (xcrb->req_len) < xcrb->req_len) -return -EINVAL ;/* overflow after alignment*/ - -/* length checks */ - ap_msg->len =sizeof (struct type6_hdr ) +CEIL4 (xcrb->req_len); +/* request length and overflow checks */ +if (xcrb->req_len <sizeof (struct ep11_cprb ) +MIN_EP11_PAYLOAD_SIZE ) +return -EINVAL ; + req_len =CEIL4 (xcrb->req_len); +if (req_len < xcrb->req_len || req_len >U32_MAX ) +return -EINVAL ; + ap_msg->len =sizeof (struct type6_hdr ) + req_len;if (ap_msg->len > ap_msg->bufsize)return -EINVAL ; -if (CEIL4 (xcrb->resp_len) < xcrb->resp_len) -return -EINVAL ;/* overflow after alignment*/ +/* reply length and overflow checks */ +if (xcrb->resp_len <sizeof (struct ep11_cprb )) +return -EINVAL ; + rep_len =CEIL4 (xcrb->resp_len); +if (rep_len < xcrb->resp_len || rep_len >U32_MAX ) +return -EINVAL ;/* prepare type6 header */ msg->hdr = static_type6_ep11_hdr;
@@ -493,26 +542,51 @@ static int xcrb_msg_to_type6_ep11cprb_ms/* Import CPRB data from the ioctl input parameter */ if (z_copy_from_user (userspace, msg->userdata, - (char __force __user *)xcrb->req, xcrb->req_len)) { + (char __force __user *)xcrb->req, xcrb->req_len))return -EFAULT ; - } -if ((msg->pld_lenfmt &0x80 ) ==0x80 ) {/*ext.len.fmt 2 or 3*/ -switch (msg->pld_lenfmt &0x03 ) { -case 1 : - lfmt =2 ; -break ; -case 2 : - lfmt =3 ; -break ; -default : -return -EINVAL ; - } - }else { - lfmt =1 ;/* length format #1 */ - } - payload_hdr = (struct pld_hdr *)((&msg->pld_lenfmt) + lfmt); - *fcode = payload_hdr->func_val &0xFFFF ; + pld = msg->userdata +sizeof (struct ep11_cprb ); + pld_len = msg->cprbx.payload_len; +if (pld_len != xcrb->req_len -sizeof (struct ep11_cprb )) +return -EINVAL ; +/* +* At this point pld_len is always >= MIN_EP11_PAYLOAD_SIZE +* and the smallest supported asn1 payload is: +* payload tag (1 octet) +* payload length (1-5 octets) +* function tag (1 octet) +* function length (1-5 octets) +* function value (1-4 octets) +*/ + +/* payload tag */ +if (pld[offs++] !=0x30 ) +return -EINVAL ; +/* payload length field */ + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (offs >= pld_len || u > pld_len - offs) +return -EINVAL ; +/* function tag */ +if (pld[offs++] !=0x04 ) +return -EINVAL ; +/* function length */ +if (offs >= pld_len) +return -EINVAL ; + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (offs >= pld_len || u > pld_len - offs) +return -EINVAL ; +/* function value */ + i =asn1_int_decode (pld + offs, u, &u); +if (i <0 ) +return -EINVAL ; + offs += i; + *fcode =0xFFFF & u;/* enable special processing based on the cprbs flags special bit */ if (msg->cprbx.flags &0x20 )