5.10.275-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 1062/1848 aio: fix NULL deref when a fault races ring truncation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit d53b5aa5cfae27e4d236fc0ab9581085d27f7d33 ]
The aio ring lives in a file on the aio pseudo filesystem and the ring VMA uses filemap_fault(). aio_ctx_aops doesn't have a ->read_folio because aio_setup_ring() puts all folios of the ring into the page cache. So a fault on the ring only works as long as it finds its folio in the page cache. If it doesn't, filemap_fault() calls ->read_folio without checking and we jump to NULL.
We already fixed this twice this year. A forked child could inherit the ring mapping, fixed by commit c03ce4173c7b ("fs: aio: set VMA_DONTCOPY_BIT in mmap to fix NULL-pointer-dereference error"). And a partial mremap() could leave part of the ring mapped, fixed by commit 3adf7ae18bf4 ("fs: aio: reject partial mremap to avoid Null-pointer-dereference error"). Both times a VMA outlived the ring and the ring file was truncated under it.
There's a third way to get there. kill_ioctx() and the error path of ioctx_alloc() unmap the ring with vm_munmap() and ignore the return value. If vm_munmap() has to wait for mmap_lock and a fatal signal is pending it returns -EINTR and the VMA stays. free_ioctx() then calls put_aio_ring_file() which truncates the ring file to zero. A fault that passed the i_size check in filemap_fault() before that doesn't find its folio anymore, allocates a new one and calls ->read_folio:
fault on the ring io_destroy() with SIGKILL pending
================= =================================
vm_munmap() returns -EINTR
filemap_fault()
i_size check passes
free_ioctx()
put_aio_ring_file()
truncate_setsize(inode, 0)
no folio, allocate a new one
filemap_read_folio()
->read_folio == NULL
All that's needed is a second process that shares the mm. If a CLONE_VM child calls io_destroy() and gets SIGKILLed while it waits for mmap_lock the ring stays mapped for the threads of the parent. Any user can do that.
Instead of plugging the routes one by one give the ring a ->read_folio that unlocks the folio and returns -EIO. All folios of a live ring are in the page cache so a fault can only end up there if the ring was truncated. The fault now gets SIGBUS. Nothing else reads the ring file and the aio filesystem uses noop_backing_dev_info so there's no readahead either.
Making vm_munmap() unkillable in those two places would only close this one route and bring back what commit ae7987835643 ("mm: make vm_munmap killable") fixed.
--- fs/aio.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/aio.c +11 -0
@@ -455,7 +455,18 @@ static int aio_migratepage(struct address_space *mapping, struct page *new, }#endif +/* +* filemap_fault() reads a page that it did not find in the page cache. All +* pages of a live ring are there, so the ring was truncated under the fault. +*/ +static int aio_readpage (struct file *file,struct page *page) +{ +unlock_page (page); +return -EIO ; +} +static const struct address_space_operations aio_ctx_aops = { + .readpage = aio_readpage, .set_page_dirty = __set_page_dirty_no_writeback, #if IS_ENABLED(CONFIG_MIGRATION) .migratepage = aio_migratepage,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1063/1848 mm/huge_memory: fix truncate racing with PMD zapping
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit e6a07d29b0a60f3a4cfe77fe34eeb4b3fb38d6c4 ]
zap_huge_pmd_folio() removes the rmap before calling folio_mark_dirty(). If this was the last mapping, truncation can skip unmapping the folio and proceed without waiting for the PMD lock, racing with dirtying.
ifs_set_range_dirty() can oops if MADV_DONTNEED races with ftruncate() on XFS, when we get the folio set dirty after it was found to not be mapped anymore.
Move folio_mark_dirty() and folio_mark_accessed() before rmap removal, matching the PTE zap path. This keeps the folio mapped while updating its state, so truncation must wait for the page table lock.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/huge_memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/huge_memory.c +6 -2
@@ -1699,8 +1699,6 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,if (pmd_present (orig_pmd)) { page =pmd_page (orig_pmd); -page_remove_rmap (page, true); -VM_BUG_ON_PAGE (page_mapcount (page) <0 , page);VM_BUG_ON_PAGE (!PageHead (page), page); }else if (thp_migration_supported ()) {swp_entry_t entry;
@@ -1724,6 +1722,12 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,set_page_dirty (page); } +/* Remove the rmap after transferring the dirty bit to the page. */ +if (pmd_present (orig_pmd)) { +page_remove_rmap (page, true); +VM_BUG_ON_PAGE (page_mapcount (page) <0 , page); + } +spin_unlock (ptl);if (flush_needed)tlb_remove_page_size (tlb, page,HPAGE_PMD_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1064/1848 udf: fix preallocation discarding before an empty allocation extent
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 0c52750caaaccee8b0e929450fe6538ec4985722 ]
udf_discard_prealloc() finds the last extent of a file by peeking at the next one with udf_next_aext() and stopping when that returns 0. The peek reads into eloc and elen, and the code then uses them as the last extent. But when udf_next_aext() returns 0 they hold no defined
value: if the extent list ends in a continuation descriptor that leads to an empty allocation extent, they describe that continuation, i.e. the block of the empty allocation extent, one block long.
The kernel creates such lists itself: when udf_delete_aext() removes the only descriptor of the last allocation extent in a list, it leaves that allocation extent empty and the continuation to it in place.
If the last extent is a preallocation, udf_discard_prealloc() deletes it with udf_delete_aext(), which finds the following allocation extent empty, so it also removes the continuation and frees that allocation extent's block. udf_discard_prealloc() then frees eloc and elen: that block a second time, instead of the preallocated blocks. On a space bitmap the preallocated blocks leak and the free block count drifts. On an unallocated space table the second free adds a second free extent for the same block, which is later handed out twice: fsx as run by generic/091 and generic/263 ends up with two parts of its test file in one block and reads back bad data.
Peek into separate variables, so that eloc and elen keep the last extent that udf_next_aext() returned with 1.
--- fs/udf/truncate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/udf/truncate.c +4 -3
@@ -122,8 +122,8 @@ void udf_discard_prealloc(struct inode *inode) {struct extent_position epos = {};struct extent_position prev_epos = {}; -struct kernel_lb_addr eloc; -uint32_t elen; +struct kernel_lb_addr eloc, tmpeloc; +uint32_t elen, tmpelen;uint64_t lbcount =0 ;int8_t etype =-1 , netype;struct udf_inode_info *iinfo =UDF_I (inode);
@@ -136,7 +136,8 @@ void udf_discard_prealloc(struct inode *inode) epos.block = iinfo->i_location;/* Find the last extent in the file */ -while ((netype =udf_next_aext (inode, &epos, &eloc, &elen,0 )) !=-1 ) { +while ((netype =udf_next_aext (inode, &epos, &tmpeloc, &tmpelen, +0 )) !=-1 ) {brelse (prev_epos.bh); prev_epos = epos;if (prev_epos.bh)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1065/1848 fbdev: kyro: Use devm_ioremap() for mmio registers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Di Santi <[email protected]>
[ Upstream commit e0bf12a43243e6afc5a03fc55c58ec48aba48088 ]
Replace the manual ioremap() call for the MMIO registers with the device-managed devm_ioremap() variant.
This simplifies the driver's resource management by ensuring the memory is automatically unmapped when the driver detaches from the device.
Stable-dep-of: d3bc005a6294 ("fbdev: kyro: Release WC setup on registration failure")
--- drivers/video/fbdev/kyro/fbdev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/video/fbdev/kyro/fbdev.c +3 -5
@@ -713,13 +713,14 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) kyro_fix.mmio_len =pci_resource_len (pdev,1 ); currentpar->regbase = deviceInfo.pSTGReg = -ioremap (kyro_fix.mmio_start, kyro_fix.mmio_len); +devm_ioremap (&pdev->dev, kyro_fix.mmio_start, + kyro_fix.mmio_len);if (!currentpar->regbase) goto out_free_fb; info->screen_base =pci_ioremap_wc_bar (pdev,0 );if (!info->screen_base) - goto out_unmap_regs; + goto out_free_fb;if (!nomtrr) currentpar->wc_cookie = arch_phys_wc_add(kyro_fix.smem_start,
@@ -768,8 +769,6 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) out_unmap:iounmap (info->screen_base); -out_unmap_regs: -iounmap (currentpar->regbase); out_free_fb:framebuffer_release (info);
@@ -792,7 +791,6 @@ static void kyrofb_remove(struct pci_dev *pdev) deviceInfo.ulOverlayOffset =0 ;iounmap (info->screen_base); -iounmap (par->regbase);arch_phys_wc_del (par->wc_cookie);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1066/1848 fbdev: kyro: Use devm_ioremap_wc() for screen mem
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Di Santi <[email protected]>
[ Upstream commit 32dfb6112ea3ca143636832cd34234f2be4830bb ]
Replace the manual pci_ioremap_wc() call for mapping screen memory with the device-managed devm_ioremap_wc() variant.
This simplifies the driver's resource management by ensuring the memory is automatically unmapped when the driver detaches from the device.
Stable-dep-of: d3bc005a6294 ("fbdev: kyro: Release WC setup on registration failure")
--- drivers/video/fbdev/kyro/fbdev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/fbdev/kyro/fbdev.c +3 -6
@@ -718,7 +718,8 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (!currentpar->regbase) goto out_free_fb; - info->screen_base =pci_ioremap_wc_bar (pdev,0 ); + info->screen_base =devm_ioremap_wc (&pdev->dev, kyro_fix.smem_start, + kyro_fix.smem_len);if (!info->screen_base) goto out_free_fb;
@@ -756,7 +757,7 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)fb_memset (info->screen_base,0 , size);if (register_framebuffer (info) <0 ) - goto out_unmap; + goto out_free_fb; fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", info->fix.id,
@@ -767,8 +768,6 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; -out_unmap: -iounmap (info->screen_base); out_free_fb:framebuffer_release (info);
@@ -790,8 +789,6 @@ static void kyrofb_remove(struct pci_dev *pdev) deviceInfo.ulNextFreeVidMem =0 ; deviceInfo.ulOverlayOffset =0 ; -iounmap (info->screen_base); -arch_phys_wc_del (par->wc_cookie);unregister_framebuffer (info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1067/1848 fbdev: kyro: Release WC setup on registration failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit d3bc005a62945aec57059201092b12b7c955e5a7 ]
If register_framebuffer() fails, kyrofb_probe() frees the framebuffer without releasing its write-combining range. Release the range before freeing the framebuffer. Earlier failures still skip this cleanup.
The missing cleanup already exists in the initial Git import, before the conversion from mtrr_add() to arch_phys_wc_add().
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/video/fbdev/kyro/fbdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/kyro/fbdev.c +3 -1
@@ -757,7 +757,7 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)fb_memset (info->screen_base,0 , size);if (register_framebuffer (info) <0 ) - goto out_free_fb; + goto out_free_wc; fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", info->fix.id,
@@ -768,6 +768,8 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; +out_free_wc: +arch_phys_wc_del (currentpar->wc_cookie); out_free_fb:framebuffer_release (info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1068/1848 hwmon: (coretemp) Fix 32-bit jiffies wraparound in show_temp()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 9a6aa085c94c7f2817c4d50a7264e6fb51286f40 ]
show_temp() rate-limits MSR reads by storing tdata->last_updated as an unsigned long and comparing it against jiffies using time_after(jiffies, tdata->last_updated + HZ).
time_after() relies on signed long subtraction, which only produces the expected result while the two timestamps are within LONG_MAX jiffies of each other. On 32-bit kernels, if tempX_input is not read for more than LONG_MAX jiffies (~24.85 days at HZ=1000), the signed difference flips sign and time_after() evaluates to false. Because tdata->last_updated is only refreshed when time_after() succeeds, subsequent reads remain blocked from refreshing for another ~24.85 days until jiffies wraps past tdata->last_updated + HZ again, returning either a stale cached temperature or -ENODATA if the sensor had never been read since initialization.
Store tdata->last_updated as a u64 and use get_jiffies_64() with time_after64(), which does not wrap in any practical uptime.
--- drivers/hwmon/coretemp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/hwmon/coretemp.c +4 -3
@@ -70,7 +70,7 @@ struct temp_data {int temp;int ttarget;int tjmax; -unsigned long last_updated; +u64 last_updated;unsigned int cpu;u32 cpu_core_id;u32 status_reg;
@@ -157,7 +157,8 @@ static ssize_t show_temp(struct device *dev,mutex_lock (&tdata->update_lock);/* Check whether the time interval has elapsed */ -if (!tdata->valid ||time_after (jiffies, tdata->last_updated +HZ )) { +if (!tdata->valid || +time_after64 (get_jiffies_64 (), tdata->last_updated +HZ )) {rdmsr_on_cpu (tdata->cpu, tdata->status_reg, &eax, &edx);/* * Ignore the valid bit. In all observed cases the register
@@ -167,7 +168,7 @@ static ssize_t show_temp(struct device *dev,*/ tdata->temp = tdata->tjmax - ((eax >>16 ) &0x7f ) *1000 ; tdata->valid =1 ; - tdata->last_updated = jiffies; + tdata->last_updated =get_jiffies_64 (); }mutex_unlock (&tdata->update_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1069/1848 hwmon: (tmp108) Fix initial conversion delay and wait until ready
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 7cd60538073e465310c94b2a2f0ea8d2f03768ef ]
In tmp108_common_probe(), the driver only adds the 30 ms conversion delay (TMP108_CONVERSION_TIME_MS) to ready_time if the sensor was previously in TMP108_MODE_SHUTDOWN. However, the TMP108 hardware defaults to continuous conversion mode (TMP108_MODE_CONTINUOUS) upon power-on reset, including immediately after enabling the vcc supply regulator during probe, while the temperature register retains its power-on reset value of 0x0000 (0°C) until the first conversion completes. Because the initial mode is not shutdown, the delay is bypassed and early reads via thermal zone registration or sysfs before the first conversion finishes return an uninitialized 0°C reading.
In addition, returning -EAGAIN from tmp108_read() while waiting for a conversion to complete after probe or resume can trigger an unnecessary tight retry loop in callers or fail initial reads.
Unconditionally set ready_time to TMP108_CONVERSION_TIME_MS ahead in tmp108_common_probe(), track ready_time as ktime_t, and wait for the remaining conversion time in tmp108_read() using usleep_range() instead of returning -EAGAIN.
--- drivers/hwmon/tmp108.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/hwmon/tmp108.c +11 -15
@@ -14,7 +14,7 @@#include <linux/of.h> #include <linux/i2c.h> #include <linux/init.h> -#include <linux/jiffies.h> +#include <linux/ktime.h> #include <linux/regmap.h> #include <linux/slab.h>
@@ -73,7 +73,7 @@struct tmp108 {struct regmap *regmap;u16 orig_config; -u64 ready_time; +ktime_t ready_time; };/* convert 12-bit TMP108 register value to milliCelsius */
@@ -94,6 +94,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,struct tmp108 *tmp108 =dev_get_drvdata (dev);unsigned int regval;int err, hyst; +s64 delay;if (type == hwmon_chip) {if (attr == hwmon_chip_update_interval) {
@@ -123,12 +124,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input: -/* Is it too early to return a conversion ? */ -if (time_before64 (get_jiffies_64 (), tmp108->ready_time)) { -dev_dbg (dev,"%s: Conversion not ready yet..\n" , - __func__); -return -EAGAIN ; - } +/* Wait if it is too early to return a conversion */ + delay =ktime_us_delta (tmp108->ready_time,ktime_get ()); +if (delay >0 ) +usleep_range (delay, delay +1000 ); err =regmap_read (tmp108->regmap,TMP108_REG_TEMP , ®val);if (err <0 )return err;
@@ -371,11 +370,8 @@ static int tmp108_probe(struct i2c_client *client)return err; } - tmp108->ready_time =get_jiffies_64 (); -if ((tmp108->orig_config &TMP108_CONF_MODE_MASK ) == -TMP108_MODE_SHUTDOWN ) - tmp108->ready_time += -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS ); err =devm_add_action_or_reset (dev, tmp108_restore_config, tmp108);if (err) {
@@ -405,8 +401,8 @@ static int __maybe_unused tmp108_resume(struct device *dev) err =regmap_update_bits (tmp108->regmap,TMP108_REG_CONF ,TMP108_CONF_MODE_MASK ,TMP108_MODE_CONTINUOUS ); - tmp108->ready_time =get_jiffies_64 () + -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1070/1848 drm/amdgpu: dont walk the CS chunks when allocating them failed
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit ade92d50aad6799a5a9d7e73cd1604fd0576e656 ]
amdgpu_cs_pass1() sets p->nchunks before allocating p->chunks, and the allocation failure path skips resetting it. amdgpu_cs_parser_fini() then frees the kdata of nchunks chunks from a NULL array. On navi48 with the chunk array allocation failed through failslab:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:amdgpu_cs_parser_fini+0x35d/0x710 [amdgpu] amdgpu_cs_ioctl+0xcae/0x7a20 [amdgpu] drm_ioctl_kernel+0x180/0x320 [drm]
Set nchunks once the array exists.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -2
@@ -140,13 +140,14 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs goto free_chunk; } - p->nchunks = cs->in.num_chunks; - p->chunks =kmalloc_array (p->nchunks,sizeof (struct amdgpu_cs_chunk ), +/* parser_fini() walks nchunks chunks, set it once they exist */ + p->chunks =kmalloc_array (cs->in.num_chunks,sizeof (struct amdgpu_cs_chunk ),GFP_KERNEL );if (!p->chunks) { ret = -ENOMEM ; goto free_chunk; } + p->nchunks = cs->in.num_chunks;for (i =0 ; i < p->nchunks; i++) {struct drm_amdgpu_cs_chunk __user *chunk_ptr =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1071/1848 nvme: unregister when pr_register() is given a zero new key
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit a9d431124fb2e58215daf0299d6fcf47bbc2d6b1 ]
The block layer PR API defines a zero new_key in pr_register() as unregistering old_key. nvme_pr_register() sends Replace Reservation Key with a zero NRKEY instead. The host stays registered with key 0, and its next registration with another key fails with Reservation Conflict.
The pNFS SCSI layout client unregisters this way at umount. A later mount cannot register and sends all I/O through the metadata server.
Send Unregister Reservation Key when new_key is zero.
--- drivers/nvme/host/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +6 -1
@@ -2286,7 +2286,12 @@ static int nvme_pr_register(struct block_device *bdev, u64 old,if (flags & ~PR_FL_IGNORE_KEY )return -EOPNOTSUPP ; - cdw10 = old ?2 :0 ; +if (!new) + cdw10 =1 ; +else if (old) + cdw10 =2 ; +else + cdw10 =0 ; cdw10 |= (flags &PR_FL_IGNORE_KEY ) ?1 <<3 :0 ; cdw10 |= (1 <<30 ) | (1 <<31 );/* PTPL=1 */ return nvme_pr_command (bdev, cdw10, old, new, nvme_cmd_resv_register);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1072/1848 mm/vma: dont leak the charge for stack growth
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit b1ee87802111156e27557e82acc31fa7dfc76e2a ]
acct_stack_growth() charges stack expansion even without VM_ACCOUNT. This can happen for read-only or MAP_NORESERVE mappings created with MAP_GROWSDOWN. Unmapping these VMAs does not release the charge, leaking Committed_AS.
Only check and charge growth for VM_ACCOUNT VMAs, matching mremap(). Unaccounted growth skips the overcommit check while remaining subject to the other stack-growth limits.
--- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/mmap.c +2 -1
@@ -2399,7 +2399,8 @@ static int acct_stack_growth(struct vm_area_struct *vma,* Overcommit.. This must be the final test, as it will * update security statistics. */ -if (security_vm_enough_memory_mm (mm, grow)) +if ((vma->vm_flags &VM_ACCOUNT ) && +security_vm_enough_memory_mm (mm, grow))return -ENOMEM ;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1073/1848 ocfs2/heartbeat: serialize concurrent writes to a regions dev attribute
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eklavya Singh <[email protected]>
[ Upstream commit 0a8f258c0f012314c36b9e4818cdc0178c68f891 ]
o2hb_region_dev_store() checks reg->hr_bdev_file to see if the region is already started, but nothing stops two writers from doing that at the same time. configfs only serializes writes through the same open file, so two processes that each open the dev attribute can both get past the check:
A: hr_bdev_file is NULL, opens file A, sets hr_bdev_file = A
B: hr_bdev_file is NULL, opens file B, sets hr_bdev_file = B
A: start fails, fput(hr_bdev_file) drops B, sets it to NULL
B: start fails, fput(NULL)
Both calls also use the same hr_slots, hr_slot_data and hr_tmp_block, so the error paths can free the slot data twice.
syzbot hit the fput(NULL) with an unbound loop device, where every start fails with -EIO. With four threads doing the same thing on a KASAN kernel I get both crashes within a second:
BUG: KASAN: double-free in o2hb_unmap_slot_data+0x14d/0x2f0 BUG: kernel NULL pointer dereference, address: 0000000000000158
Add a mutex to the region and hold it in dev_store(), in the block_bytes, start_block and blocks stores, and in dev_show(), since they all look at hr_bdev_file. dev_store() cleans up with goto, so it takes the mutex in a small wrapper rather than with guard(). The mutex is dropped while dev_store() waits for the heartbeat to become steady, which takes seconds, so a read of dev doesn't stall behind a start. hr_bdev_file is already set at that point, so other writers still get -EINVAL, and the cleanup after the wait retakes the mutex.
With the patch the same test ran for 10 minutes with lockdep on and nothing was reported. So did a second one, with a working loop device, that interrupts starts during the wait while other threads read and write the attributes.
--- fs/ocfs2/cluster/heartbeat.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +18 -2
@@ -268,6 +268,8 @@ struct o2hb_region {/* Message key for negotiate timeout message. */ unsigned int hr_key;struct list_head hr_handler_list; +/* Serializes the dev, block_bytes, start_block and blocks attributes. */ +struct mutex hr_dev_mutex;/* last hb status, 0 for success, other value for error. */ int hr_last_hb_status;
@@ -1607,6 +1609,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item,unsigned long block_bytes;unsigned int block_bits; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1635,6 +1638,7 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item,unsigned long long tmp;char *p = (char *)page; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1660,6 +1664,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,unsigned long tmp;char *p = (char *)page; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1677,10 +1682,12 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,static ssize_t o2hb_region_dev_show (struct config_item *item,char *page) { +struct o2hb_region *reg =to_o2hb_region (item);unsigned int ret =0 ; -if (to_o2hb_region (item)->hr_bdev) - ret =sprintf (page,"%s\n" ,to_o2hb_region (item)->hr_dev_name); +guard (mutex)(®->hr_dev_mutex); +if (reg->hr_bdev) + ret =sprintf (page,"%s\n" , reg->hr_dev_name);return ret; }
@@ -1803,6 +1810,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,ssize_t ret = -EINVAL ;int live_threshold; +mutex_lock (®->hr_dev_mutex);if (reg->hr_bdev) goto out;
@@ -1903,9 +1911,15 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, reg->hr_task = hb_task;spin_unlock (&o2hb_live_lock); +/* +* Don't hold hr_dev_mutex across the wait, which can take seconds. +* hr_bdev is already set, so other writers still get -EINVAL. +*/ +mutex_unlock (®->hr_dev_mutex); ret =wait_event_interruptible (o2hb_steady_queue,atomic_read (®->hr_steady_iterations) ==0 || reg->hr_node_deleted); +mutex_lock (®->hr_dev_mutex);if (ret) {atomic_set (®->hr_steady_iterations,0 ); reg->hr_aborted_start =1 ;
@@ -1945,6 +1959,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out2:fdput (f); out: +mutex_unlock (®->hr_dev_mutex);return ret; }
@@ -2048,6 +2063,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g }INIT_LIST_HEAD (®->hr_all_item); +mutex_init (®->hr_dev_mutex);INIT_LIST_HEAD (®->hr_handler_list);config_item_init_type_name (®->hr_item, name, &o2hb_region_type);if (!config_item_name (®->hr_item)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1074/1848 mm: make swapoff interruptible when unusing mms/shmem
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Down <[email protected]>
[ Upstream commit 740128dd1a3f2bd81a80314d079b6b03c39ba3af ]
try_to_unuse() only checks for a pending signal between mms, and shmem_unuse() doesn't check at all. That means that once swapoff gets to a process or a shmem file with a lot swapped out, nothing can interrupt it until every last page of it has been read back in.
Just as one example of where this can concretely show up, freezing tasks for suspend or hibernation has to wait for swapoff to notice the freezer's fake signal, and gives up after freeze_timeout_msecs (20 seconds by default).
Here's a facetious example where one swaps out 2GiB of one process to a swap file on ext4, starts swapoff, and half a second later tries to freeze with pm_test=freezer. Writing to /sys/power/state then fails with EBUSY and this in dmesg:
Freezing user space processes failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0):
task:swapoff state:D stack:0 pid:3175 tgid:3175 ppid:2955 task_flags:0x400100 flags:0x00000419
Call trace:
[...]
io_schedule+0x44/0x70
folio_wait_bit_common+0x1ec/0x3d0
__folio_lock+0x24/0x40
unuse_pte_range+0x2d0/0x348
unuse_vma+0x158/0x248
unuse_mm+0xfc/0x150
try_to_unuse+0x104/0x3f8
__do_sys_swapoff+0x220/0x5d8
[...]The same goes for anything else that wants swapoff to stop, like an admin hitting ^C in a panic, of course.
Prior to commit b56a2d8af914 ("mm: rid swapoff of quadratic complexity") try_to_unuse() was driven by find_next_to_unuse() which checks for a signal before every entry, so let's restore that behaviour.
Just as an example of the improvements, here's how long freezing takes in the same test while swapoff is happening on my computer:
before after
400MiB anon 8.925s 0.028s
400MiB shmem 1.639s 0.003s
2GiB anon failed after 20.003s 0.011s--- mm/shmem.c | 4 ++++ mm/swapfile.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
mm/shmem.c +4 -0
@@ -1305,6 +1305,10 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type, } } +if (signal_pending (current)) { + ret = -ERESTARTSYS ; +break ; + } start = indices[pvec.nr -1 ]; }while (true);
mm/swapfile.c +3 -1
@@ -2048,6 +2048,8 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, pmd =pmd_offset (pud, addr); do { cond_resched(); + if (signal_pending(current)) + return -ERESTARTSYS; next = pmd_addr_end(addr, end); if (pmd_none_or_trans_huge_or_clear_bad(pmd)) continue;
@@ -2284,7 +2286,7 @@ int try_to_unuse(unsigned int type, bool frontswap,if (READ_ONCE (si->inuse_pages)) {if (!signal_pending (current)) goto retry; - retval = -EINTR ; + retval = -ERESTARTSYS ; } out:return (retval ==FRONTSWAP_PAGES_UNUSED ) ?0 : retval;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1075/1848 mm/memory: reject remote COW faults on PFN mappings
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 8db6921cc07b74197a3866d62ed262b68aeadcf3 ]
When handling a COW fault without a normal source page (PFN mappings), __wp_page_copy_user() copies from the faulting user address. For remote faults, this accesses the wrong address space, resulting in wrong data getting copied.
For example, user_events updates an enable bit in the registering process's memory. If that memory needs to be faulted in, user_event_enabler_fault_fixup() calls fixup_user_fault() from a work item. Placing the enable bit in a private PFN mapping can trigger this remote COW path.
Reject these faults with VM_FAULT_SIGBUS when the target mm differs from current->mm: remote faults. Ordinary (non-PFN) mappings are not affected.
The user-address copy dates back to commit 6aab341e0a28 ("mm: re-architect the VM_UNPAGED logic"); likely, actual ways to get remote faults in there on COW PFN mappings appeared afterwards. But the fix is simple and straight forward.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/memory.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
mm/memory.c +19 -7
@@ -2648,10 +2648,10 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,return same; } -static inline bool cow_user_page (struct page *dst,struct page *src, +static inline int cow_user_page (struct page *dst,struct page *src,struct vm_fault *vmf) { -bool ret; +int ret;void *kaddr;void __user *uaddr;bool locked = false;
@@ -2661,9 +2661,16 @@ static inline bool cow_user_page(struct page *dst, struct page *src,if (likely (src)) {copy_user_highpage (dst, src, addr, vma); -return true; +return 0 ; } +/* +* __copy_from_user_inatomic() only works as expected for local faults. +* Reject remote faults. +*/ +if (unlikely (mm != current->mm)) +return -EFAULT ; +/* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by
@@ -2688,7 +2695,7 @@ static inline bool cow_user_page(struct page *dst, struct page *src,* and update local tlb only */ update_mmu_tlb (vma, addr, vmf->pte); - ret = false; + ret = -EAGAIN ; goto pte_unlock; }
@@ -2713,7 +2720,7 @@ static inline bool cow_user_page(struct page *dst, struct page *src,if (!likely (pte_same (*vmf->pte, vmf->orig_pte))) {/* The PTE changed under us, update local tlb */ update_mmu_tlb (vma, addr, vmf->pte); - ret = false; + ret = -EAGAIN ; goto pte_unlock; }
@@ -2732,7 +2739,7 @@ static inline bool cow_user_page(struct page *dst, struct page *src, } } - ret = true; + ret =0 ; pte_unlock:if (locked)
@@ -2908,12 +2915,15 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)if (!new_page) goto oom; }else { +int err; + new_page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address);if (!new_page) goto oom; -if (!cow_user_page (new_page, old_page, vmf)) { + err =cow_user_page (new_page, old_page, vmf); +if (err) {/* * COW failed, if the fault was solved by other, * it's fine. If not, userspace would re-fault on
@@ -2923,6 +2933,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)put_page (new_page);if (old_page)put_page (old_page); +if (err == -EFAULT ) +return VM_FAULT_SIGBUS ;return 0 ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1076/1848 mm/userfaultfd: compare exact registration modes before skipping
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 05f64f211a25f7d9771d4fde109aad97174a1cf3 ]
Changing registration from MISSING|WP to WP returns success but leaves MISSING enabled. The no-op check sees that WP is already set and skips the update, so later accesses to missing pages still wait for userspace.
Skip the update only when the current and requested UFFD modes match exactly.
--- fs/userfaultfd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/userfaultfd.c +2 -1
@@ -1409,7 +1409,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,* userfaultfd and with the right tracking mode too. */ if (vma->vm_userfaultfd_ctx.ctx == ctx && - (vma->vm_flags & vm_flags) == vm_flags) + (vma->vm_flags & (VM_UFFD_MISSING |VM_UFFD_WP )) == + vm_flags) goto skip;if (vma->vm_start > start)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1077/1848 apparmor: fix query_data() output overlapping the lookup key
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit d30844001360a403a511cf24fc75ecaa6a7a7544 ]
In query_data(), buf and query point into the same multi_transaction
buffer: buf at the start, query a few bytes in, and the lookup key right after the label string that query points to. Reusing the buffer is by design and is safe as long as the query is fully parsed before buf is written to, but the key is not: it is dereferenced on every iteration of label_for_each_confined(), after output has already been written. So when the label has more than one profile with a data table, the data of the first matching profile is written to buf while the key is still needed, and overwrites it if the data is large enough. The later lookups then run on a corrupted key. Besides, if the data has no NUL byte from the key's position to the end of the allocation, strhash() -> strlen() -> jhash() reads past the 4096-byte slab object, triggering an out-of-bound read:
BUG: KASAN: slab-out-of-bounds in jhash+0x595/0x5e0 Read of size 1 at addr ff1100001159d000 by task exploit/155 CPU: 0 UID: 1000 PID: 155 Comm: exploit Not tainted 7.3.0-rc7 #1 Call Trace: jhash+0x595/0x5e0 aa_write_access+0x880/0x1400 vfs_write+0x26f/0xd20 ksys_write+0x115/0x210
Writing to the .access file is unprivileged (0666), but triggering this requires loaded profiles that carry a data table, which needs CAP_MAC_ADMIN and is not the case on default distribution policies.
Fix by copying the key with kstrdup() before writing any output to buf, so the key stays valid across all loop iterations regardless of what gets written to the overlapping buffer.
--- security/apparmor/apparmorfs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
security/apparmor/apparmorfs.c +12 -3
@@ -739,7 +739,7 @@ static void profile_query_cb(struct aa_profile *profile, struct aa_perms *perms,static ssize_t query_data (char *buf,size_t buf_len,char *query,size_t query_len) { -char *out; +char *out, *keydup;const char *key;struct label_it i;struct aa_label *label, *curr;
@@ -760,11 +760,18 @@ static ssize_t query_data(char *buf, size_t buf_len,if (buf_len <sizeof (bytes) +sizeof (blocks))return -EINVAL ;/* not enough space */ +/* buf overlaps query, keep a copy of the key for the later lookups */ + keydup =kstrdup (key,GFP_KERNEL ); +if (!keydup) +return -ENOMEM ; + curr =begin_current_label_crit_section (); label =aa_label_parse (curr, query,GFP_KERNEL , false, false);end_current_label_crit_section (curr); -if (IS_ERR (label)) +if (IS_ERR (label)) { +kfree (keydup);return PTR_ERR (label); + }/* We are going to leave space for two numbers. The first is the total * number of bytes we are writing after the first number. This is so
@@ -782,13 +789,14 @@ static ssize_t query_data(char *buf, size_t buf_len,if (!profile->data)continue ; - data =rhashtable_lookup_fast (profile->data, &key, + data =rhashtable_lookup_fast (profile->data, &keydup, profile->data->p);if (data) {if (out +sizeof (outle32) + data->size > buf + buf_len) {aa_put_label (label); +kfree (keydup);return -EINVAL ;/* not enough space */ } outle32 =__cpu_to_le32 (data->size);
@@ -800,6 +808,7 @@ static ssize_t query_data(char *buf, size_t buf_len, } }aa_put_label (label); +kfree (keydup); outle32 =__cpu_to_le32 (out - buf -sizeof (bytes));memcpy (buf, &outle32,sizeof (outle32));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1078/1848 virtio_blk: use synchronous quiesce in virtblk_freeze_priv()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Zhang <[email protected]>
[ Upstream commit 6c6dec7883f8eb10b326bc9d109a4990c885d949 ]
blk_mq_run_work_fn() can call blk_mq_sched_dispatch_requests() through blk_mq_run_dispatch_ops(). The dispatcher checks QUEUE_FLAG_QUIESCED while the flag is clear. It can then be preempted before it gets a request. At that time, it has no queue usage reference, so blk_mq_freeze_queue() does not wait for it.
virtblk_freeze_priv() then calls blk_mq_quiesce_queue_nowait() and blk_mq_unfreeze_queue(). A new request can enter the queue. The old dispatcher can run again, use its old flag check, get the new request, and call virtio_queue_rq(). At the same time, virtblk_freeze_priv() can reset the device, delete the virtqueues, and free vblk->vqs. The old dispatcher can then use a deleted virtqueue or a NULL vblk->vqs, and the kernel can crash.
Fix this by using blk_mq_quiesce_queue(), which waits for dispatch code that was already running. Keep the existing freeze and unfreeze order. The queue remains quiesced until virtblk_restore_priv() calls blk_mq_unquiesce_queue().
--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +1 -1
@@ -955,7 +955,7 @@ static int virtblk_freeze(struct virtio_device *vdev)/* Ensure no requests in virtqueues before deleting vqs. */ blk_mq_freeze_queue (q); -blk_mq_quiesce_queue_nowait (q); +blk_mq_quiesce_queue (q);blk_mq_unfreeze_queue (q);/* Ensure we don't receive any more interrupts */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1079/1848 mm/filemap: read mapping->a_ops->free_folio under i_lock
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit dc24e273244e9d712257d5a6c20a32c7f5ca84e6 ]
memory_failure() -> ... -> filemap_remove_folio() can read mapping->a_ops after the inode has been freed. Once the folio is deleted from the pagecache it no longer pins the mapping, so after i_lock is dropped e.g., a concurrent final iput() can evict and free the inode before filemap_free_folio() looks up mapping->a_ops->free_folio.
Most callers hold a reference on the inode, but not all.
Documentation/filesystems/vfs.rst explicitly states that ->free_folio() must not assume the original address_space mapping still exists.
Fix it by loading ->free_folio while i_lock is still held, similar to what folio_unmap_invalidate() does.
Inline filemap_free_folio() into its remaining caller such that delete_from_page_cache_batch() also just loads the callback before dropping the i_lock.
The bug was found by code inspection and has not been reproduced.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-)
mm/filemap.c +24 -20
@@ -239,23 +239,6 @@ void __delete_from_page_cache(struct page *page, void *shadow)page_cache_delete (mapping, page, shadow); } -static void page_cache_free_page (struct address_space *mapping, -struct page *page) -{ -void (*freepage)(struct page *); - - freepage = mapping->a_ops->freepage; -if (freepage) -freepage (page); - -if (PageTransHuge (page) && !PageHuge (page)) { -page_ref_sub (page,thp_nr_pages (page)); -VM_BUG_ON_PAGE (page_count (page) <=0 , page); - }else { -put_page (page); - } -} -/** * delete_from_page_cache - delete page from page cache * @page: the page which the kernel is trying to remove from page cache
@@ -267,14 +250,23 @@ static void page_cache_free_page(struct address_space *mapping,void delete_from_page_cache (struct page *page) {struct address_space *mapping =page_mapping (page); +void (*freepage)(struct page *page);unsigned long flags;BUG_ON (!PageLocked (page));xa_lock_irqsave (&mapping->i_pages, flags);__delete_from_page_cache (page,NULL ); + freepage = mapping->a_ops->freepage;xa_unlock_irqrestore (&mapping->i_pages, flags); -page_cache_free_page (mapping, page); +if (freepage) +freepage (page); +if (PageTransHuge (page) && !PageHuge (page)) { +page_ref_sub (page,thp_nr_pages (page)); +VM_BUG_ON_PAGE (page_count (page) <=0 , page); + }else { +put_page (page); + } }EXPORT_SYMBOL (delete_from_page_cache);
@@ -343,6 +335,7 @@ static void page_cache_delete_batch(struct address_space *mapping,void delete_from_page_cache_batch (struct address_space *mapping,struct pagevec *pvec) { +void (*freepage)(struct page *page);int i;unsigned long flags;
@@ -356,10 +349,21 @@ void delete_from_page_cache_batch(struct address_space *mapping,unaccount_page_cache_page (mapping, pvec->pages[i]); }page_cache_delete_batch (mapping, pvec); + freepage = mapping->a_ops->freepage;xa_unlock_irqrestore (&mapping->i_pages, flags); -for (i =0 ; i <pagevec_count (pvec); i++) -page_cache_free_page (mapping, pvec->pages[i]); +for (i =0 ; i <pagevec_count (pvec); i++) { +struct page *page = pvec->pages[i]; + +if (freepage) +freepage (page); +if (PageTransHuge (page) && !PageHuge (page)) { +page_ref_sub (page,thp_nr_pages (page)); +VM_BUG_ON_PAGE (page_count (page) <=0 , page); + }else { +put_page (page); + } + } }int filemap_check_errors (struct address_space *mapping)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1080/1848 hwrng: virtio - prevent use-after-free after a failed restore
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 0f7bf47f5a0cc26320aa4b14f4504d03a07f4b74 ]
remove_common() frees the driver data during freeze, but does not clear vdev->priv, which points to freed memory. If probe_common() then fails during restore, a later remove or freeze can dereference the dangling pointer.
Clear vdev->priv on the probe_common() error cleanup path and before freeing the driver data in remove_common(). Also reset the device and return early from remove_common() if vdev->priv is already NULL for a safe teardown after a failed restore.
Message-ID: <[email protected]>
--- drivers/char/hw_random/virtio-rng.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/char/hw_random/virtio-rng.c +7 -0
@@ -186,6 +186,7 @@ static int probe_common(struct virtio_device *vdev) err_find:ida_simple_remove (&rng_index_ida, index); err_ida: + vdev->priv =NULL ;kfree (vi);return err; }
@@ -194,6 +195,11 @@ static void remove_common(struct virtio_device *vdev) {struct virtrng_info *vi = vdev->priv; +if (!vi) { + vdev->config->reset (vdev); +return ; + } + vi->hwrng_removed = true; vi->data_avail =0 ; vi->data_idx =0 ;
@@ -203,6 +209,7 @@ static void remove_common(struct virtio_device *vdev)hwrng_unregister (&vi->hwrng); vdev->config->del_vqs (vdev);ida_simple_remove (&rng_index_ida, vi->index); + vdev->priv =NULL ;kfree (vi); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1081/1848 fork: take mmap_lock before copying mm_struct
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit ef694e2d210111cc08c52fd25da9ab130170bfa3 ]
dup_mm() copies the parent's mm_struct before dup_mmap() takes the mmap_lock. A concurrent brk() can leave the child with a stale mm->brk and newer heap mappings, causing later brk() requests to fail.
Other operations (e.g., PR_SET_MM) on the parent's mm_struct can similarly cause inconsistencies.
As a simple and robust fix, grab the parent's mmap_lock earlier. This way we don't need to update individual mm fields in dup_mmap() and keep missing ones. Stop updating the 4 existing members (total_vm, data_vm, exec_vm, stack_vm), as that is now no longer required.
Keep releasing the parent's mmap_lock in dup_mmap(), before userfaultfd completion, to avoid moving the userfaultfd handling into the caller. This should get cleaned up later.
Move uprobe_start_dup_mmap() to preserve the lock ordering.
--- kernel/fork.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
kernel/fork.c +15 -14
@@ -478,11 +478,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,unsigned long charge;LIST_HEAD (uf); -uprobe_start_dup_mmap (); -if (mmap_write_lock_killable (oldmm)) { - retval = -EINTR ; - goto fail_uprobe_end; - } +mmap_assert_write_locked (oldmm);flush_cache_dup_mm (oldmm);uprobe_dup_mmap (oldmm, mm);/*
@@ -493,11 +489,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,/* No ordering required: file already has been exposed. */ RCU_INIT_POINTER (mm->exe_file,get_mm_exe_file (oldmm)); - mm->total_vm = oldmm->total_vm; - mm->data_vm = oldmm->data_vm; - mm->exec_vm = oldmm->exec_vm; - mm->stack_vm = oldmm->stack_vm; - rb_link = &mm->mm_rb.rb_node; rb_parent =NULL ; pprev = &mm->mmap;
@@ -608,7 +599,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,flush_tlb_mm (oldmm);mmap_write_unlock (oldmm);dup_userfaultfd_complete (&uf); -fail_uprobe_end:uprobe_end_dup_mmap ();return retval; fail_nomem_anon_vma_fork:
@@ -636,7 +626,7 @@ static inline void mm_free_pgd(struct mm_struct *mm)#else static int dup_mmap (struct mm_struct *mm,struct mm_struct *oldmm) { -mmap_write_lock (oldmm); +mmap_assert_write_locked (oldmm);RCU_INIT_POINTER (mm->exe_file,get_mm_exe_file (oldmm));mmap_write_unlock (oldmm);return 0 ;
@@ -1375,10 +1365,18 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,if (!mm) goto fail_nomem; +uprobe_start_dup_mmap (); +if (mmap_write_lock_killable (oldmm)) { +free_mm (mm); + goto fail_uprobe; + } +memcpy (mm, oldmm,sizeof (*mm)); -if (!mm_init (mm, tsk, mm->user_ns)) - goto fail_nomem; +if (!mm_init (mm, tsk, mm->user_ns)) { +mmap_write_unlock (oldmm); + goto fail_uprobe; + } err =dup_mmap (mm, oldmm);if (err)
@@ -1397,7 +1395,10 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, mm->binfmt =NULL ;mm_init_owner (mm,NULL );mmput (mm); +return NULL ; +fail_uprobe: +uprobe_end_dup_mmap (); fail_nomem:return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1082/1848 hwmon: (coretemp) Check for NULL platform device in hotplug callbacks
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 0f9c7ed3b5009a037e5533eac03a0d4d45ecf1f0 ]
coretemp_get_pdev() returns NULL when topology_logical_die_id(cpu) is negative (such as -ENODEV or -ERANGE from topology_get_logical_id() on a firmware/hardware APIC ID mismatch) or exceeds max_zones (for example, under asymmetric or anomalous ACPI die topologies where topology_max_packages() * topology_max_dies_per_package() is smaller than the logical die count).
Commit 6d03bbff456b ("hwmon: (coretemp) Simplify platform device handling") pre-allocated zone_devices[0 .. max_zones - 1] during module init and dropped the NULL checks on pdev in coretemp_cpu_online() and coretemp_cpu_offline(), passing pdev unconditionally to platform_get_drvdata(). When coretemp_get_pdev() returns NULL, platform_get_drvdata(pdev) dereferences &pdev->dev and triggers a kernel NULL pointer dereference.
Check for a NULL pdev and return 0 in both coretemp_cpu_online() and coretemp_cpu_offline() before calling platform_get_drvdata(). Returning 0 in coretemp_cpu_online() ignores the unmapped CPU without blocking CPU bringup or tearing down valid thermal zones on other dies.
--- drivers/hwmon/coretemp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hwmon/coretemp.c +6 -0
@@ -619,6 +619,9 @@ static int coretemp_cpu_online(unsigned int cpu)if (!cpu_has (c,X86_FEATURE_DTHERM ))return -ENODEV ; +if (!pdev) +return 0 ; + pdata =platform_get_drvdata (pdev);if (!pdata->hwmon_dev) {struct device *hwmon;
@@ -670,6 +673,9 @@ static int coretemp_cpu_offline(unsigned int cpu)return 0 ;/* If the physical CPU device does not exist, just return */ +if (!pdev) +return 0 ; + pd =platform_get_drvdata (pdev);if (!pd->hwmon_dev)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1083/1848 drm/amdgpu: Only enable HDMI audio if display supports it
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: renpanpan <[email protected]>
[ Upstream commit 0de95c96655c8a12df62e47871016f49e5cd8618 ]
The amdgpu legacy DCE audio path (dce_v6/v8/v10) unconditionally calls audio_enable(pin, true) at the end of afmt_setmode(), regardless of whether the connected display advertises audio support in its EDID.
This causes a phantom HDMI audio output to appear for displays that have no audio capability (no basic audio bit, no Audio Data Block in EDID), because the GPU sets the AUDIO_ENABLED register bit, which drives the HDA codec's ELDV pin sense, making the codec report the jack as audio-available.
The radeon, nouveau, and dw-hdmi drivers all gate audio enablement on display_info.has_audio. Apply the same check to amdgpu's DCE afmt_setmode functions.
--- drivers/gpu/drm/amd/amdgpu/dce_v10_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +3 -2
@@ -1737,8 +1737,9 @@ static void dce_v10_0_afmt_setmode(struct drm_encoder *encoder,WREG32 (mmAFMT_RAMP_CONTROL2 + dig->afmt->offset,0x00000001 );WREG32 (mmAFMT_RAMP_CONTROL3 + dig->afmt->offset,0x00000001 ); -/* enable audio after to setting up hw */ -dce_v10_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (drm_detect_monitor_audio (amdgpu_connector_edid (connector))) +dce_v10_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v10_0_afmt_enable (struct drm_encoder *encoder,bool enable)
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +3 -2
@@ -1702,8 +1702,9 @@ static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,dce_v6_0_audio_dp_enable (encoder,1 ); } -/* enable audio after setting up hw */ -dce_v6_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (drm_detect_monitor_audio (amdgpu_connector_edid (connector))) +dce_v6_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v6_0_afmt_enable (struct drm_encoder *encoder,bool enable)
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +3 -2
@@ -1666,8 +1666,9 @@ static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,WREG32 (mmAFMT_RAMP_CONTROL2 + offset,0x00000001 );WREG32 (mmAFMT_RAMP_CONTROL3 + offset,0x00000001 ); -/* enable audio after setting up hw */ -dce_v8_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (drm_detect_monitor_audio (amdgpu_connector_edid (connector))) +dce_v8_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v8_0_afmt_enable (struct drm_encoder *encoder,bool enable)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1084/1848 scsi: bsg: Report synchronous data copyback failures
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit a52f2ad45726d788755b525adcf51f65a6b836ff ]
scsi_bsg_sg_io_fn() ignores the result of blk_rq_unmap_user(). For a data-in command that uses a bounce buffer, unmapping copies the completed data to userspace. If that copy fails, SG_IO can report success despite the copyback failure.
Capture the unmap status. Preserve an earlier sense-buffer copy error and otherwise return the data copyback error. This matches the error precedence used by scsi_complete_sghdr_rq().
On x86_64, a virtio-scsi INQUIRY with an unaligned PROT_NONE destination made ioctl() return 0 in 20/20 runs before this change and return -1 with errno EFAULT in 20/20 runs afterward. Writable controls succeeded in 20/20 runs on both kernels.
--- block/bsg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
block/bsg.c +4 -2
@@ -137,7 +137,7 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)struct request *rq;struct bio *bio;struct sg_io_v4 hdr; -int ret; +int ret, unmap_ret;if (copy_from_user (&hdr, uarg,sizeof (hdr)))return -EFAULT ;
@@ -185,7 +185,9 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)blk_execute_rq (q,NULL , rq, !(hdr.flags &BSG_FLAG_Q_AT_TAIL )); ret = rq->q->bsg_dev.ops->complete_rq (rq, &hdr); -blk_rq_unmap_user (bio); + unmap_ret =blk_rq_unmap_user (bio); +if (!ret) + ret = unmap_ret; out_free_rq: rq->q->bsg_dev.ops->free_rq (rq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1085/1848 ocfs2: use the stored hash when checking xattr bucket collision
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e39baff18b85cf8956aee138d7944b6581e8ba36 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a full bucket can make room for the entry being set by recomputing the hash of the name:
u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0;
For a new entry that is the hash it will be stored under, so comparing it is correct. An existing entry keeps the hash it already has: an update never rewrites xe_name_hash, since ocfs2_xa_add_entry() is the only writer of that field for a real entry and ocfs2_xa_prepare_entry() calls it only when loc->xl_entry is NULL.
An entry stored by a kernel that sign-extended the name bytes when hashing can still be updated, because ocfs2_xattr_find_entry() searches a non-indexed xattr block by memcmp on the name and never looks at xe_name_hash. Growing it past the space left in the block converts the block into a tree, ocfs2_cp_xattr_block_to_bucket() fills the bucket in stored hash order, and the update runs out of room in the bucket too. The collision check then compares the unsigned hash against the legacy hashes in the bucket and reports no collision.
ocfs2_xattr_set_entry_index_block() goes on to allocate a bucket that ocfs2_divide_xattr_bucket() cannot fill: a bucket whose entries all share one hash has no divide position, so all it does is append an empty bucket with a sentinel hash one above the last entry's.
The re-search that follows depends on where the unsigned hash sorts. Below the legacy ones, it comes back to the full bucket and the set fails with -ENOSPC, having grown the tree for nothing. Above them, it lands on the new empty bucket, which ocfs2_xattr_bucket_find() handles explicitly and ocfs2_find_xe_in_bucket() scans zero times, so the set stores a second copy of the entry under the unsigned hash and returns success. The original stays in the full bucket, listxattr reports the name twice and getxattr returns the new copy.
Pass the hash the entry is stored under instead: the stored one for an existing entry, the unsigned one for a new entry. A tree whose entries are all stored under the unsigned hash sees no change, since there the two are the same value.
Stable-dep-of: e8de099f2958 ("ocfs2: do not read the entry array of an empty xattr bucket")
--- fs/ocfs2/xattr.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +17 -10
@@ -5603,16 +5603,14 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,/* * check whether the xattr bucket is filled up with the same hash value. -* If we want to insert the xattr with the same hash, return -ENOSPC. -* If we want to insert a xattr with different hash value, go ahead -* and ocfs2_divide_xattr_bucket will handle this. +* If the entry being set carries that same hash, return -ENOSPC, since +* ocfs2_divide_xattr_bucket() has no divide position to work with. +* Otherwise go ahead and ocfs2_divide_xattr_bucket() will handle this. */ -static int ocfs2_check_xattr_bucket_collision (struct inode *inode, -struct ocfs2_xattr_bucket *bucket, -const char *name) +static int ocfs2_check_xattr_bucket_collision (struct ocfs2_xattr_bucket *bucket, +u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); -u32 name_hash =ocfs2_xattr_name_hash (inode, name,strlen (name));if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ;
@@ -5709,6 +5707,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { + u32 name_hash;int ret;trace_ocfs2_xattr_set_entry_index_block (xi->xi_name);
@@ -5728,10 +5727,18 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. +* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. */ - ret =ocfs2_check_xattr_bucket_collision (inode, - xs->bucket, - xi->xi_name); +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + + ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1086/1848 ocfs2: do not read the entry array of an empty xattr bucket
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e8de099f2958c84aa23186c5481e69f7ffd39355 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a bucket can make room by comparing the hash being inserted against the first and the last entry. xh_count comes off disk and is never checked, and a bucket is allowed to hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so that an empty bucket still carries the hash it is keyed by. xh_count then reads back as 0 while xh_entries[0] is still meaningful, and the second comparison indexes xh_entries[-1].
That is outside the __counted_by_le(xh_count) bounds of xh_entries[] and lands on the header. An entry is 16 bytes and xe_name_hash is its first field, so the value read is xh_count | xh_free_start << 16. It stays inside the block, but the answer is arbitrary, and for an empty bucket it says there is no collision, so a new bucket gets added on the strength of it.
An empty bucket holds no entries to collide with. Return before reading the array.
One way to reach the test with an empty bucket is a set that removes the bucket's only entry during cleanup and then fails for space again, since it is that second -ENOSPC which calls this. Growing a value past OCFS2_XATTR_INLINE_SIZE is the easy route: the cluster allocation fails, the "!orig_clusters" arm of ocfs2_xa_cleanup_value_truncate() removes the entry, and although the "growing" caller does set ctxt->set_abort, only ocfs2_xattr_block_set() and __ocfs2_xattr_set_handle() look at it, so ocfs2_xattr_set_entry_index_block() goes straight on to the collision check.
This sits on commit a9ea8b397864 ("ocfs2: use the stored hash when checking xattr bucket collision"), which gave the collision check its two argument form and is marked for 6.2 and later. The read fixed here is present in the three argument version too, but a tree without that commit needs the hunk adapted by hand.
--- fs/ocfs2/xattr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +10 -1
@@ -5611,11 +5611,20 @@ static int ocfs2_check_xattr_bucket_collision(struct ocfs2_xattr_bucket *bucket, u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); +u16 count =le16_to_cpu (xh->xh_count); + +/* +* An empty bucket keeps the hash of the entry that was removed in +* xh_entries[0] so that it can still be found, but it holds no +* entries to collide with. +*/ +if (!count) +return 0 ;if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ; -if (xh->xh_entries[le16_to_cpu (xh->xh_count) -1 ].xe_name_hash == +if (xh->xh_entries[count -1 ].xe_name_hash == xh->xh_entries[0 ].xe_name_hash) { mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " "hash = %u\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1087/1848 ocfs2: read the xattr entry hash before defragmenting the bucket
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit f48151da595e74efdc23d83d8d6d142207b8c731 ]
Patch series "ocfs2: fix stale xattr entry pointers and empty header reads", v1.
Five defects in the ocfs2 extended attribute code, plus one robustness measure that belongs with them, all on the paths that move entries between a block, a bucket and an index tree. They fall into two groups.
Stale entry pointers (patches 1 to 3)
ocfs2_xa_set() writes through a pointer into xh_entries[] that two of its callers invalidate first. Defragmenting a bucket ends in a sort() on xe_name_hash, and lib/sort.c is an unstable heapsort, so entries that share a hash can trade slots. Copying a block into a bucket changes the order outright, since a block holds its entries in insertion order while a bucket holds them by hash, yet ocfs2_xattr_update_xattr_search() relocates the search by the index the entry had in the block. Neither path compares the entry's name with the one being set, so setxattr() can replace a neighbouring attribute's value and still report success, or trip ocfs2_xa_reuse_entry()'s BUG_ON. Patch 1 takes the hash before the sort; patches 2 and 3 look the entry up again afterwards.
Reads of an empty entry array (patches 4 to 6)
A block and a bucket may both hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so an empty bucket still carries the hash it is keyed by. Three sites index xh_entries[] without checking xh_count and so read xh_entries[-1], which lands on the header and comes back as xh_count | xh_free_start << 16. Nothing faults, but the value is acted on: the collision check reports no collision for an empty bucket, the divide commits a sentinel hash that hides part of the key space from ocfs2_xattr_bucket_find(), and the block to bucket copy claims storage the bucket does not hold. Patches 4 to 6 guard each site and keep the one read of xh_entries[0] that ocfs2_xa_remove_entry() documents as intentional.
This patch (of 6):
ocfs2_xattr_set_entry_index_block() takes the hash a bucket split has to work with out of xs->here, but only after ocfs2_xattr_set_entry_bucket() has tried and failed to fit the entry. That call defragments the bucket when it runs out of room, and ocfs2_defrag_xattr_bucket() finishes by sorting the entry array by name hash. lib/sort.c is not stable, so two entries sharing a hash may trade slots and xs->here is left naming an entry other than the one the search found.
The hash value itself survives the permutation -- the array is already sorted, so a slot can only exchange with an equal-hash neighbour -- but there is no reason to depend on that. Pick the hash up before the set, where xs->here is unambiguously the entry the search landed on.
No functional change intended.
--- fs/ocfs2/xattr.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +16 -10
@@ -5721,6 +5721,22 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,trace_ocfs2_xattr_set_entry_index_block (xi->xi_name); +/* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. +* +* Read it before the set below. Filling the bucket may defragment it, +* and ocfs2_defrag_xattr_bucket() re-sorts the entry array, so +* afterwards xs->here only denotes whichever entry the sort left in +* that slot. +*/ +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + ret =ocfs2_xattr_set_entry_bucket (inode, xi, xs, ctxt);if (!ret) goto out;
@@ -5736,17 +5752,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. -* -* An existing entry keeps the hash it was stored under, and that is -* the hash a split has to work with. A new entry is stored under the -* unsigned one, which is what ocfs2_xa_add_entry() will write. */ -if (xs->not_found) - name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, - xi->xi_name_len); -else - name_hash =le32_to_cpu (xs->here->xe_name_hash); - ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1088/1848 KVM: x86: Exit to userspace if emulation prepared a completion callback
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hou Wenlong <[email protected]>
[ Upstream commit adbfb12d4c4517a8adde23a7fc46538953d56eea ]
em_rdmsr() and em_wrmsr() return X86EMUL_IO_NEEDED if MSR accesses required an exit to userspace. However, x86_emulate_insn() doesn't return X86EMUL_*, so x86_emulate_instruction() doesn't directly act on X86EMUL_IO_NEEDED; instead, it looks for other signals to differentiate between PIO, MMIO, etc. causing RDMSR/WRMSR emulation not to exit to userspace now.
Nevertheless, if the userspace_msr_exit_test testcase in selftests is changed to test RDMSR/WRMSR with a forced emulation prefix, the test passes. What happens is that first userspace exit information is filled but the userspace exit does not happen. Because x86_emulate_instruction() returns 1, the guest retries the instruction---but this time RIP has already been adjusted past the forced emulation prefix, so the guest executes RDMSR/WRMSR and the userspace exit finally happens.
Since the X86EMUL_IO_NEEDED path has provided a complete_userspace_io callback, x86_emulate_instruction() can just return 0 if the callback is not NULL. Then RDMSR/WRMSR instruction emulation will exit to userspace directly, without the RDMSR/WRMSR vmexit.
Message-Id: <56f9df2ee5c05a81155e2be366c9dc1f7adc8817.1635842679.git.houwenlong93@linux.alibaba.com>
Stable-dep-of: ae85ac25eb67 ("KVM: x86: Conditionally resched when restarting REP string emulation")
--- arch/x86/kvm/x86.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kvm/x86.c +3 -0
@@ -7717,6 +7717,9 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, writeback = false; r =0 ; vcpu->arch.complete_userspace_io = complete_emulated_mmio; + }else if (vcpu->arch.complete_userspace_io) { + writeback = false; + r =0 ; }else if (r ==EMULATION_RESTART ) goto restart;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1089/1848 KVM: x86: Conditionally resched when restarting REP string emulation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit ae85ac25eb671d174811cc3101549448671fd505 ]
When restarting emulation, e.g. of a REP-prefixed string instruction, conditionally reschedule as emulating guest writes can be deceptively slow and expensive, e.g. when shadow paging is in use and each write can trigger write tracking.
In a perfect world, restarting emulation (or not) would be less arbitrary, e.g. would honor not only host events (NEED_RESCHED, signals, etc.) but also guest events (e.g. by checking kvm_vcpu_has_events()). Unfortunately, as pointed out by Sashiko, pio_in_emulated()'s read-ahead logic is baked into the restart logic, as KVM relies on restarting emulation to drain the cache and avoid duplicate reads from the I/O port. I.e. re-entering the guest on kvm_vcpu_has_events() or __xfer_to_guest_mode_work_pending() would introduce architecturally-incorrect, guest-visible changes.
Message-ID: <[email protected]>
--- arch/x86/kvm/x86.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +4 -2
@@ -7720,10 +7720,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, }else if (vcpu->arch.complete_userspace_io) { writeback = false; r =0 ; - }else if (r ==EMULATION_RESTART ) + }else if (r ==EMULATION_RESTART ) { +cond_resched (); goto restart; -else + }else { r =1 ; + }if (writeback) {unsigned long rflags = kvm_x86_ops.get_rflags (vcpu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1090/1848 drm/amd/display: Avoid closing unowned DDC pins
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Hung <[email protected]>
[ Upstream commit e7ba638b8116cb5f1a5690f543052371215f1626 ]
[WHY]dal_ddc_open() cleans up pins it acquires on later failures. If the data-pin open fails, this attempt acquired nothing. If opening the clock pin or configuring fails, dal_ddc_open() closes the pins it opened. An extra dal_ddc_close() is unnecessary and unsafe:GPIO_RESULT_ALREADY_OPENED can mean AUX owns the existing handles, and closing them here would disrupt AUX.
[HOW]
Remove the extra dal_ddc_close() from the failed-open path.
--- drivers/gpu/drm/amd/display/dc/core/dc_link.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -5
@@ -373,12 +373,8 @@ bool dc_link_is_dp_sink_present(struct dc_link *link)* which indicates we need additional delay */ -if (dal_ddc_open (ddc,GPIO_MODE_INPUT , -GPIO_DDC_CONFIG_TYPE_MODE_I2C ) !=GPIO_RESULT_OK ) { -dal_ddc_close (ddc); - +if (dal_ddc_open (ddc,GPIO_MODE_INPUT ,GPIO_DDC_CONFIG_TYPE_MODE_I2C ) !=GPIO_RESULT_OK )return present; - }/* * Read GPIO: DP sink is present if both clock and data pins are zero
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1091/1848 arm64: kexec_file: Fix elf_headers memory leak in retry loop
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
[ Upstream commit ac302aea3d824ccc99f29b8e499c365cb9a684a9 ]
A retry allocates new elf headers and overwrites image->elf_headers, leaking the previous buffer.
Free it before assigning.
--- arch/arm64/kernel/machine_kexec_file.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kernel/machine_kexec_file.c +2 -0
@@ -284,6 +284,8 @@ int load_other_segments(struct kimage *image,vfree (headers); goto out_err; } + +vfree (image->arch.elf_headers); image->arch.elf_headers = headers; image->arch.elf_headers_mem = kbuf.mem; image->arch.elf_headers_sz = headers_sz;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1092/1848 ALSA: hda/realtek: Fix internal speakers on Acer Aspire AL16-31P
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luis Gerardo Lopez Hernandez <[email protected]>
[ Upstream commit d933955c456e0573b40eae4f72a3af37ab1c15c3 ]
The Acer Aspire AL16-31P (Intel Alder Lake-N, Realtek ALC269VC, PCI/codec SSID 2782:1718) has its internal speakers wired to pin 0x1b, but the BIOS marks that pin as not connected (0x411111f0) and only exposes pin 0x14 as the speaker. As a result the internal speakers are silent while headphones, HDMI and Bluetooth work.
This is the same layout as the Infinix Y4 Max and MEDION E15433, which share the 0x2782 subsystem vendor. Reuse their fixup, which configures pin 0x1b as an internal speaker and limits the internal mic boost.
Tested by booting with snd-hda-intel model=2782:1705: the fixup is picked, pin 0x1b is used as a speaker output, the internal speakers work, and they are muted when headphones are plugged in.
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -9635,6 +9635,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x2782 ,0x1701 ,"Infinix Y4 Max" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1705 ,"MEDION E15433" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1707 ,"Vaio VJFE-ADL" ,ALC298_FIXUP_SPK_VOLUME ), +SND_PCI_QUIRK (0x2782 ,0x1718 ,"Acer Aspire AL16-31P" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x8086 ,0x2074 ,"Intel NUC 8" ,ALC233_FIXUP_INTEL_NUC8_DMIC ),SND_PCI_QUIRK (0x8086 ,0x2080 ,"Intel NUC 8 Rugged" ,ALC256_FIXUP_INTEL_NUC8_RUGGED ), SND_PCI_QUIRK(0x8086, 0x2081, "Intel NUC 10", ALC256_FIXUP_INTEL_NUC10),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1093/1848 ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhou Qiuyue <[email protected]>
[ Upstream commit 66dfb2cacda7faae614d688943d85e75abf7f586 ]
rawv6_send_hdrinc() caches the route before handing the skb to l3mdev_ip6_out(). The VRF output path may replace skb->dst and release the original route, leaving the cached pointer stale.
The function later dereferences that pointer for statistics accounting and as the output device passed to NF_HOOK(). Its RCU read-side critical section starts after l3mdev_ip6_out(), so it cannot prevent the old route from being reclaimed in between.
Reload the route from the current skb destination after l3mdev_ip6_out() returns.
KASAN reports a slab-use-after-free in rawv6_sendmsg(), with the route allocated by ip6_dst_alloc(), freed by dst_destroy() from rcu_core(), and the related RCU callback queued from vrf_l3_out().
--- net/ipv6/raw.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/raw.c +3 -0
@@ -650,6 +650,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,if (unlikely (!skb))return 0 ; +/* l3mdev_ip6_out() may have replaced the skb dst. */ + rt = (struct rt6_info *)skb_dst (skb); +/* Acquire rcu_read_lock() in case we need to use rt->rt6i_idev * in the error path. Since skb has been freed, the dst could * have been queued for deletion.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1094/1848 mm/shmem: make shmem_file() check the files inode
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit d3710111839d11339e414b1bb3fea3d05ab83f6e ]
shmem_file() only checks if file->f_mapping is a shmem mapping. This mapping can belong to another file, however, as with a Coda file backed by a tmpfs container after mmap().
So it does not guarantee that the file inode is an actual shmem inode.
Seal handling and memfd preservation use this check before accessing shmem inode state, so they can access an inode of the wrong type.
Let's make shmem_file() check the inode's file operations instead, to identify shmem inodes reliably. This will identify regular shmem inodes, including memfds and ordinary tmpfs files, independently of wrapper file operations.
Use shmem_mapping() in collapse_file() instead to not change the behavior of collapse_file(): it operates on the page cache and uses mapping->host for shmem inode operations. Focusing on the file does not seem relevant.
--- include/linux/shmem_fs.h | 15 ++++++--------- mm/khugepaged.c | 2 +- mm/shmem.c | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-)
include/linux/shmem_fs.h +6 -9
@@ -67,8 +67,14 @@ extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags);extern int shmem_lock (struct file *file,int lock,struct user_struct *user);#ifdef CONFIG_SHMEM +bool shmem_file (struct file *file);extern bool shmem_mapping (struct address_space *mapping);#else +static inline bool shmem_file (struct file *file) +{ +return false; +} +static inline bool shmem_mapping (struct address_space *mapping) {return false;
@@ -106,15 +112,6 @@ static inline struct page *shmem_read_mapping_page( mapping_gfp_mask(mapping)); } -static inline bool shmem_file (struct file *file) -{ -if (!IS_ENABLED (CONFIG_SHMEM )) -return false; -if (!file || !file->f_mapping) -return false; -return shmem_mapping (file->f_mapping); -} -extern bool shmem_charge (struct inode *inode,long pages);extern void shmem_uncharge (struct inode *inode,long pages);
mm/khugepaged.c +1 -1
@@ -1690,13 +1690,13 @@ static void collapse_file(struct mm_struct *mm, struct page **hpage, int node) {struct address_space *mapping = file->f_mapping; +const bool is_shmem =shmem_mapping (mapping);gfp_t gfp;struct page *new_page;pgoff_t index, end = start +HPAGE_PMD_NR ;LIST_HEAD (pagelist);XA_STATE_ORDER (xas, &mapping->i_pages, start,HPAGE_PMD_ORDER );int nr_none =0 , result =SCAN_SUCCEED ; -bool is_shmem =shmem_file (file);VM_BUG_ON (!IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !is_shmem);VM_BUG_ON (start & (HPAGE_PMD_NR -1 ));
mm/shmem.c +5 -0
@@ -254,6 +254,11 @@ static const struct inode_operations shmem_special_inode_operations;static const struct vm_operations_struct shmem_vm_ops;static struct file_system_type shmem_fs_type; +bool shmem_file (struct file *file) +{ +return file &&file_inode (file)->i_fop == &shmem_file_operations; +} +bool vma_is_shmem (struct vm_area_struct *vma) {return vma->vm_ops == &shmem_vm_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1095/1848 nvmet: reject keep-alive timeouts that would overflow
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit 96ae13f40ce5930cd58c43128e385131476f2a66 ]
nvmet_set_feat_kato() and nvmet_alloc_ctrl() convert the 32-bit millisecond KATO from the host to seconds with DIV_ROUND_UP(kato, 1000). The addition in DIV_ROUND_UP() is done in 32 bits, so any KATO above 4294966296 ms wraps around and rounds to 0 seconds. A Set Features command with KATO 0xffffffff then succeeds but disables the keep-alive
timer: Get Features returns 0 and Keep Alive fails with Keep Alive Timeout Invalid. A Connect command with such a KATO creates a controller without a keep-alive timer.
The converted value has more consumers that can overflow. Get Features multiplies it by 1000, and the timer paths multiply it by HZ in 32 bits and arm a delay that must not exceed MAX_JIFFY_OFFSET.
Reject a KATO whose rounded value does not fit all of these. Return Keep Alive Timeout Invalid from both Set Features and Connect. Validate Set Features before stopping the current timer so a failed update leaves its timeout unchanged. Round in 64 bits. A KATO of 0 keeps its current meaning.
--- drivers/nvme/target/admin-cmd.c | 7 ++++++- drivers/nvme/target/core.c | 7 ++++++- drivers/nvme/target/nvmet.h | 8 ++++++++ include/linux/nvme.h | 1 + 4 files changed, 21 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +6 -1
@@ -739,8 +739,13 @@ u16 nvmet_set_feat_kato(struct nvmet_req *req) {u32 val32 =le32_to_cpu (req->cmd->common.cdw11); +if (val32 >NVMET_MAX_KATO *MSEC_PER_SEC ) { + req->error_loc = offsetof(struct nvme_common_command , cdw11); +return NVME_SC_KA_TIMEOUT_INVALID |NVME_SC_DNR ; + } +nvmet_stop_keep_alive_timer (req->sq->ctrl); - req->sq->ctrl->kato =DIV_ROUND_UP (val32,1000 ); + req->sq->ctrl->kato =DIV_ROUND_UP_ULL (val32,MSEC_PER_SEC );nvmet_start_keep_alive_timer (req->sq->ctrl);nvmet_set_result (req, req->sq->ctrl->kato);
drivers/nvme/target/core.c +6 -1
@@ -1325,6 +1325,11 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,int ret;u16 status; +if (kato >NVMET_MAX_KATO *MSEC_PER_SEC ) { + req->error_loc = offsetof(struct nvmf_connect_command , kato); +return NVME_SC_KA_TIMEOUT_INVALID |NVME_SC_DNR ; + } + status =NVME_SC_CONNECT_INVALID_PARAM |NVME_SC_DNR ; subsys =nvmet_find_get_subsys (req->port, subsysnqn);if (!subsys) {
@@ -1401,7 +1406,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, kato =NVMET_DISC_KATO_MS ;/* keep-alive timeout in seconds */ - ctrl->kato =DIV_ROUND_UP (kato,1000 ); + ctrl->kato =DIV_ROUND_UP_ULL (kato,MSEC_PER_SEC ); ctrl->err_counter =0 ;spin_lock_init (&ctrl->error_lock);
drivers/nvme/target/nvmet.h +8 -0
@@ -7,6 +7,7 @@#define _NVMET_H#include <linux/dma-mapping.h> +#include <linux/jiffies.h> #include <linux/types.h> #include <linux/device.h> #include <linux/kref.h>
@@ -503,6 +504,13 @@ void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,#define NVMET_KAS 10#define NVMET_DISC_KATO_MS 120000 +/* +* Largest keep-alive timeout in seconds that can be reported back in +* milliseconds and converted to jiffies without overflowing. +*/ +#define NVMET_MAX_KATO \ + min3(U32_MAX / MSEC_PER_SEC, U32_MAX / HZ, MAX_JIFFY_OFFSET / HZ) +int __init nvmet_init_configfs (void ); void __exit nvmet_exit_configfs(void);
include/linux/nvme.h +1 -0
@@ -1485,6 +1485,7 @@ enum {NVME_SC_SGL_INVALID_OFFSET =0x16 ,NVME_SC_SGL_INVALID_SUBTYPE =0x17 , +NVME_SC_KA_TIMEOUT_INVALID =0x1A ,NVME_SC_SANITIZE_FAILED =0x1C , NVME_SC_SANITIZE_IN_PROGRESS = 0x1D,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1096/1848 KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit e4558c3d7198ed9a0adc3304681f561f4e4d80e1 ]
When potentially reusing a shadow page, zap the shadow page if its number of parent PTEs exceeds KVM's (mostly) arbitrary rmap recycling threshold. Letting the guest create a (mostly) unbounded number of parent PTEs allows the guest to coerce KVM into creating lists containing millions of PTEs, effectively bounded only by the maximum number of shadow pages.
Because PTE lists are simple singly linked lists, removal is O(n). Even worse, if a list is constructed just so, teardown can be O(n^2), e.g. if SPTEs are built such that zapping child SPTEs always zaps the last entry in the list. To cap things off, all paths that walk PTE lists do so while holding mmu_lock, without conditionally rescheduling.
Using a doubly linked list would not address the issue, as removal would remain O(n) since KVM still wouldn't know where in the list to remove from. Removal could be made O(1) by storing a per-SPTE pointer, but that would largely defeat the purpose of reusing SPs, and would penalize well-behaved guests, especially for nested TDP where aliasing page tables is uncommon.
So, cap the maximum number of parent PTEs at the rmap limit. In practice, well-behaved guests will likely never run afoul of the limit. E.g. when running Linux as L1 with TDP, the number of parent PTEs for a single SP tops out at under 200 (though undoubtedly obscure workloads can push it higher). Deliberately use a "greater than or equal" as opposed to rmap's strictly "greater than", as the rmap code checks the threshold immediately *after* inserting into the list, i.e. the limit is 1000 for rmaps, KVM just very briefly blows past it.
Apply the check to both indirect and direct SPs, because while a fully direct MMU naturally limits the number of parent PTEs to '1', direct SPs in indirect MMUs have no such constraint. E.g. if the guest maps a huge PTE into many locations in its page tables, and KVM is backing the hugepage with a direct SP, i.e. with a series of smaller pages, then KVM could end up with a direct SP with many parents.
Note, shadow_mmu_try_split_huge_pages() always restarts the rmap walk or bails entirely if it gets to the point where it tries to grab a SP, i.e. there is *no* pre-existing bug that would be tripped by zapping a SP and thus rmaps when getting a SP.
Message-ID: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/x86/kvm/mmu/mmu.c +18 -0
@@ -2029,6 +2029,9 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,struct hlist_head *sp_list;unsigned quadrant;struct kvm_mmu_page *sp; +struct rmap_iterator iter; +u64 *sptep; +unsigned int parent_count;bool need_sync = false;bool flush = false;int collisions =0 ;
@@ -2059,6 +2062,21 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,if (sp->role.word != role.word)continue ; +/* +* Note! Unlike fully direct MMUs, direct SPs in indirect MMUs +* can have an arbitrary number of parents, e.g if the guest is +* mapping a huge PTE at many points in its page tables. +*/ + parent_count =0 ; +for_each_rmap_spte (&sp->parent_ptes, &iter, sptep) { +if (++parent_count >=RMAP_RECYCLE_THRESHOLD ) +break ; + } +if (parent_count >=RMAP_RECYCLE_THRESHOLD ) { +kvm_mmu_prepare_zap_page (vcpu->kvm, sp, &invalid_list); +break ; + } +if (direct_mmu) goto trace_get_page;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1097/1848 mm: document mmu_notifier_invalidate_range_start_nonblock()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
[ Upstream commit 7ced098fcfe596feab3cea4f40128b0119c7bf1a ]
Document what mmu_notifier_invalidate_range_start_nonblock() is for. Also add a __must_check annotation to signal that callers must bail out if a notifier vetoes the operation.
Stable-dep-of: 6d65925777ec ("mm/mmu_notifier: finish non-blocking interval invalidation on error")
--- include/linux/mmu_notifier.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
include/linux/mmu_notifier.h +8 -1
@@ -455,7 +455,14 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)lock_map_release (&__mmu_notifier_invalidate_range_start_map); } -static inline int +/* +* This version of mmu_notifier_invalidate_range_start() avoids blocking, but it +* can return an error if a notifier can't proceed without blocking, in which +* case you're not allowed to modify PTEs in the specified range. +* +* This is mainly intended for OOM handling. +*/ +static inline int __must_check mmu_notifier_invalidate_range_start_nonblock (struct mmu_notifier_range *range) {int ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1098/1848 mm/mmu_notifier: finish non-blocking interval invalidation on error
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6d65925777ecae9d7a571a327e41c63f3940a0c7 ]
When an ordinary MMU notifier rejects a non-blocking invalidation, the interval invalidation started beforehand is left unfinished: the caller skips mmu_notifier_invalidate_range_end(). Subsequent interval notifier operations can then wait forever.
The only in-tree trigger is nouveau SVM, which uses both notifier types and rejects non-blocking invalidations. Reaping via the OOM reaper or process_mrelease() can therefore leave the GPU fault worker stuck, holding a reference that prevents the dying process's address space and memory from being freed.
End the interval invalidation when an ordinary notifier fails a non-blocking invalidation, like mn_itree_invalidate() already does when an interval notifier fails. Make that handling clearer in the documentation of mmu_notifier_invalidate_range_start_nonblock().
Fix generated by an LLM and sent by Josef Bacik in private.
--- include/linux/mmu_notifier.h | 3 ++- mm/mmu_notifier.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-)
include/linux/mmu_notifier.h +2 -1
@@ -458,7 +458,8 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)/* * This version of mmu_notifier_invalidate_range_start() avoids blocking, but it * can return an error if a notifier can't proceed without blocking, in which -* case you're not allowed to modify PTEs in the specified range. +* case you're not allowed to modify PTEs in the specified range or call +* mmu_notifier_invalidate_range_end(). * * This is mainly intended for OOM handling. */
mm/mmu_notifier.c +13 -4
@@ -537,16 +537,25 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) {struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; -int ret; +const bool has_itree = subscriptions->has_itree; +int ret =0 ; -if (subscriptions->has_itree) { +if (has_itree) { ret =mn_itree_invalidate (subscriptions, range);if (ret)return ret; }if (!hlist_empty (&subscriptions->list)) -return mn_hlist_invalidate_range_start (subscriptions, range); -return 0 ; + ret =mn_hlist_invalidate_range_start (subscriptions, range); + +/* +* On error, the non-blocking caller is not allowed to call +* invalidate_range_end(), as in mn_itree_invalidate(). +*/ +if (ret && has_itree && !mmu_notifier_range_blockable (range)) +mn_itree_inv_end (subscriptions); + +return ret; } static void
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1099/1848 blk-iocost: Simplify ioc_rqos_done()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 62c159a03da92121b1b909fd8039028de97885fc ]
Leave out the superfluous "& REQ_OP_MASK" code. The definition of req_op() shows that that code is superfluous:
#define req_op(req) ((req)->cmd_flags & REQ_OP_MASK)
Compile-tested only.
Stable-dep-of: e9804489e27d ("blk-iocost: account flush sequence latency only once")
--- block/blk-iocost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-iocost.c +1 -1
@@ -2786,7 +2786,7 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq)if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns)return ; -switch (req_op (rq) &REQ_OP_MASK ) { +switch (req_op (rq)) {case REQ_OP_READ : pidx =QOS_RLAT ; rw =READ ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1100/1848 blk-iocost: account flush sequence latency only once
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhe Liu <[email protected]>
[ Upstream commit e9804489e27dd6e33aec5511fe3780ff3009f57f ]
A flush sequence with a DATA phase can complete its original request twice. Both completions invoke ioc_rqos_done(), causing the request to contribute two latency samples and adding the same queue wait time twice. This gives such requests disproportionate weight compared to ordinary writes, distorting the device-wide latency and queue wait feedback used to adjust iocost's virtual time rate.
Skip requests marked RQF_FLUSH_SEQ in ioc_rqos_done(). The flag is set when the request enters the flush machinery and is still set when the data phase completes; blk_flush_restore_request() clears it before the final completion, so accounting happens only once, after the whole sequence finishes. The remaining sample covers the request's lifetime through any postflush, and its queue wait time is accumulated only once.
--- block/blk-iocost.c | 3 +++ 1 file changed, 3 insertions(+)
block/blk-iocost.c +3 -0
@@ -2786,6 +2786,9 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq)if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns)return ; +if (unlikely (rq->rq_flags &RQF_FLUSH_SEQ )) +return ; +switch (req_op (rq)) {case REQ_OP_READ : pidx =QOS_RLAT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1101/1848 xfrm: retry inexact policy lookup after node reinsertion
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit 868f63c8bfafa9b827168c9126f85264c39c02ec ]
An inexact policy lookup first records pointers to candidate hlist heads and then traverses the lists. A concurrent policy insertion can merge inexact tree nodes between those operations:
lookup policy insertion
------ ----------------
find inexact candidates
save obsolete hlist head
write_seqcount_begin(&bin->count)
merge inexact tree nodes
hlist_del_rcu(&policy->bydst)
reinsert policy->bydst in survivor
write_seqcount_end(&bin->count) evaluate saved candidate list
miss the moved policy
The merge immediately reinserts the same hlist node into the surviving tree node. RCU keeps the policy alive, but it does not provide a consistent view while its list node is moved. A lookup that selected the obsolete list can observe it empty. A lookup already traversing a moved policy can instead follow the next pointer rewritten by the reinsertion. Either case can return an incorrect IPsec policy result.
The per-bin sequence counter already brackets calls to xfrm_policy_inexact_insert_node(), including node merges. The read side, however, currently validates the counter only while searching an individual rb-tree. A successful search returns without validation, and the later candidate-list traversal is outside that read-side section.
Snapshot the per-bin sequence before discovering candidate heads and
validate it after evaluating all candidate lists. Retry the lookup if
the inexact policy tree changes while it is being searched.
--- net/xfrm/xfrm_policy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/xfrm/xfrm_policy.c +9 -2
@@ -2104,6 +2104,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,struct xfrm_pol_inexact_bin *bin;struct xfrm_policy *pol, *ret;struct hlist_head *chain; +unsigned int inexact_sequence;unsigned int sequence;int err;
@@ -2135,12 +2136,18 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, } } bin =xfrm_policy_inexact_lookup_rcu (net, type, family, dir, if_id); -if (!bin || !xfrm_policy_find_inexact_candidates (&cand, bin, saddr, - daddr)) +if (!bin) + goto skip_inexact; + + inexact_sequence =read_seqcount_begin (&bin->count); +if (!xfrm_policy_find_inexact_candidates (&cand, bin, saddr, daddr)) goto skip_inexact; pol =xfrm_policy_eval_candidates (&cand, ret, fl, type, family, dir, if_id); +if (read_seqcount_retry (&bin->count, inexact_sequence)) + goto retry; +if (pol) { ret = pol;if (IS_ERR (pol))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1102/1848 mm/filemap: dont lose a folio lock wakeup to a signal
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 8ccb6ded6a47b59b4907ed4f8c293cf8122de889 ]
An exclusive waiter in folio_wait_bit_common() can leave the wait loop because of a fatal signal, then be woken by folio_unlock() before finish_wait(). If the waker did not hand over the lock, the waiter returns -EINTR without trying to acquire it.
folio_wake_bit() stops after waking the first exclusive waiter, so this loses the wakeup and can leave other waiters asleep indefinitely on an unlocked folio.
After finish_wait(), let a waiter woken without a lock handoff try once more to acquire the lock. If successful, return success so the caller's eventual unlock wakes the next waiter. Otherwise, the current lock owner will do so.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
mm/filemap.c +15 -3
@@ -1328,10 +1328,22 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,* return value based on that state without races. * * Also note that WQ_FLAG_WOKEN is sufficient for a non-exclusive -* waiter, but an exclusive one requires WQ_FLAG_DONE. +* waiter, but an exclusive one must also acquire the bit. */ -if (behavior ==EXCLUSIVE ) -return wait->flags &WQ_FLAG_DONE ?0 : -EINTR ; +if (behavior ==EXCLUSIVE ) { +if (wait->flags &WQ_FLAG_DONE ) +return 0 ; +/* +* We might have just been woken up and the waker will not +* wake up anybody else. If we ignore that now, the remaining +* waiters may not get woken up: take the bit now if it is +* still free. +*/ +if ((wait->flags &WQ_FLAG_WOKEN ) && + !test_and_set_bit (bit_nr, &page->flags)) +return 0 ; +return -EINTR ; + }return wait->flags &WQ_FLAG_WOKEN ?0 : -EINTR ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1103/1848 xfs: mark the inode preallocated for pNFS write layouts past EOF
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 8b8e265991556d99b6d721697f148975a7c68767 ]
xfs_fs_map_blocks() marks the inode XFS_DIFLAG_PREALLOC only when it allocates blocks for a write layout. A write layout past EOF can also hand out allocated blocks, such as speculative preallocation. blockgc then frees them under the layout, and another file may get them.
Mark the inode whenever a write mapping ends past EOF.
--- fs/xfs/xfs_pnfs.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
fs/xfs/xfs_pnfs.c +18 -3
@@ -91,6 +91,7 @@ xfs_fs_map_blocks(int nimaps =1 ;uint lock_flags;int error =0 ; +bool update_inode = false;if (XFS_FORCED_SHUTDOWN (mp))return -EIO ;
@@ -157,7 +158,24 @@ xfs_fs_map_blocks( end_fsb - offset_fsb, &imap);if (error) goto out_unlock; + update_inode = true; + }else { +xfs_iunlock (ip, lock_flags); +/* +* Blocks past EOF that were allocated for buffered writes, such +* as speculative preallocation, can be freed by +* xfs_free_eofblocks() without breaking the layout unless the +* inode is marked as preallocated. Mark it before handing them +* out for writing, as for blocks allocated above. +*/ +if (!error && write && !(ip->i_d.di_flags &XFS_DIFLAG_PREALLOC ) && + imap.br_startoff + imap.br_blockcount > +XFS_B_TO_FSB (mp,XFS_ISIZE (ip))) + update_inode = true; + } + +if (update_inode) {/* * Ensure the next transaction is committed synchronously so * that the blocks allocated and handed out to the client are
@@ -168,9 +186,6 @@ xfs_fs_map_blocks( error =xfs_log_force_inode (ip);if (error) goto out_unlock; - - }else { -xfs_iunlock (ip, lock_flags); }xfs_iunlock (ip,XFS_IOLOCK_EXCL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1104/1848 scsi: aic7xxx: Use default settings on the SGI O2 onboard controllers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit 696bdfc58975fbc70d2e2347a74e0b562e7e2494 ]
The SGI O2 firmware runs its onboard aic7880s without the Adaptec BIOS, so scratch RAM holds no settings. The left over BIOS path reads uninitialised bytes, and bad parity panics the boot.
Use the defaults there with host ID 0. ahc_init() keeps the default host ID ahc_pci_config() chose, 7 on other PCI controllers, so only the O2 changes.
--- drivers/scsi/aic7xxx/aic7xxx_core.c | 8 ++++++-- drivers/scsi/aic7xxx/aic7xxx_pci.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-)
drivers/scsi/aic7xxx/aic7xxx_core.c +6 -2
@@ -5267,9 +5267,13 @@ ahc_init(struct ahc_softc *ahc)/* * Assume we have a board at this stage and it has been reset. +* PCI controllers keep the host ID ahc_pci_config() chose. */ -if ((ahc->flags &AHC_USEDEFAULTS ) !=0 ) - ahc->our_id = ahc->our_id_b =7 ; +if ((ahc->flags &AHC_USEDEFAULTS ) !=0 ) { +if ((ahc->chip &AHC_PCI ) ==0 ) + ahc->our_id =7 ; + ahc->our_id_b =7 ; + }/* * Default to allowing initiator operations.
drivers/scsi/aic7xxx/aic7xxx_pci.c +19 -1
@@ -701,6 +701,21 @@ ahc_find_pci_device(ahc_dev_softc_t pci)return (NULL ); } +/* +* The SGI O2 firmware runs its onboard controllers, in slots 1 and 2 of the +* root bus, without the Adaptec BIOS and at host ID 0. It leaves no settings +* in scratch RAM, which may still hold power-on contents with bad parity. +*/ +static bool +ahc_pci_sgi_o2_onboard (struct ahc_softc *ahc) +{ +int slot =ahc_get_pci_slot (ahc->dev_softc); + +return IS_ENABLED (CONFIG_SGI_IP32 ) && +ahc_get_pci_bus (ahc->dev_softc) ==0 && + (slot ==1 || slot ==2 ); +} +int ahc_pci_config (struct ahc_softc *ahc,const struct ahc_pci_identity *entry) {
@@ -782,6 +797,9 @@ ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry) ahc->bus_intr = ahc_pci_intr; ahc->bus_chip_init = ahc_pci_chip_init; +if (ahc_pci_sgi_o2_onboard (ahc)) + ahc->flags |=AHC_NO_BIOS_INIT ; +/* Remember how the card was setup in case there is no SEEPROM */ if ((ahc_inb (ahc,HCNTRL ) &POWRDN ) ==0 ) {ahc_pause (ahc);
@@ -898,7 +916,7 @@ ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry)* Assume only one connector and always turn * on termination. */ - our_id =0x07 ; + our_id =ahc_pci_sgi_o2_onboard (ahc) ?0 :0x07 ; sxfrctl1 =STPWEN ; }ahc_outb (ahc,SCSICONF , our_id|ENSPCHK |RESET_SCSI );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1105/1848 xfs: cap the block count of xfs_iomap_write_direct() at one extent
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 66d1ce09ebd72709f8d739630c39f440445173fd ]
xfs_iomap_write_direct() reserves blocks for the whole count in an unsigned int. For a pNFS layout the client chooses that count, and an RW LAYOUTGET for 16 TiB wraps the reservation and shuts XFS down.
xfs_bmapi_write() maps at most XFS_MAX_BMBT_EXTLEN blocks here, so cap the count at that. nfsd asks again for the rest. The other callers get the same mapping as before.
--- fs/xfs/xfs_iomap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/xfs/xfs_iomap.c +8 -0
@@ -203,6 +203,14 @@ xfs_iomap_write_direct(ASSERT (count_fsb >0 ); +/* +* xfs_bmapi_write() maps at most MAXEXTLEN blocks in one +* mapping, so don't reserve blocks for more. A pNFS layout range +* comes from a client, and its block count may not even fit the +* 32-bit reservation. The caller maps the rest with a later call. +*/ + count_fsb =min_t (xfs_filblks_t, count_fsb,MAXEXTLEN ); + resaligned =xfs_aligned_fsb_count (offset_fsb, count_fsb,xfs_get_extsz_hint (ip));if (unlikely (XFS_IS_REALTIME_INODE (ip))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1106/1848 selinux: prevent KMSAN warning in selinux_inet_conn_request()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Kanner <[email protected]>
commit 1df83cbf23a27174aee6ea5e52462f03f7e48a10 upstream.
KMSAN reports the following issue:
[ 81.822503] ===================================================== [ 81.823222] BUG: KMSAN: uninit-value in selinux_inet_conn_request+0x2c8/0x4b0 [ 81.823891] selinux_inet_conn_request+0x2c8/0x4b0 [ 81.824385] security_inet_conn_request+0xc0/0x160 [ 81.824886] tcp_v4_route_req+0x30e/0x490 [ 81.825343] tcp_conn_request+0xdc8/0x3400 [ 81.825813] tcp_v4_conn_request+0x134/0x190 [ 81.826292] tcp_rcv_state_process+0x1f4/0x3b40 [ 81.826797] tcp_v4_do_rcv+0x9ca/0xc30 [ 81.827236] tcp_v4_rcv+0x3bf5/0x4180 [ 81.827670] ip_protocol_deliver_rcu+0x822/0x1230 [ 81.828174] ip_local_deliver_finish+0x259/0x370 [ 81.828667] ip_local_deliver+0x1c0/0x450 [ 81.829105] ip_sublist_rcv+0xdc1/0xf50 [ 81.829534] ip_list_rcv+0x72e/0x790 [ 81.829941] __netif_receive_skb_list_core+0x10d5/0x1180 [ 81.830499] netif_receive_skb_list_internal+0xc41/0x1190 [ 81.831064] napi_complete_done+0x2c4/0x8b0 [ 81.831532] e1000_clean+0x12bf/0x4d90 [ 81.831983] __napi_poll+0xa6/0x760 [ 81.832391] net_rx_action+0x84c/0x1550 [ 81.832831] __do_softirq+0x272/0xa6c [ 81.833239] __irq_exit_rcu+0xb7/0x1a0 [ 81.833654] irq_exit_rcu+0x17/0x40 [ 81.834044] common_interrupt+0x8d/0xa0 [ 81.834494] asm_common_interrupt+0x2b/0x40 [ 81.834949] default_idle+0x17/0x20 [ 81.835356] arch_cpu_idle+0xd/0x20 [ 81.835766] default_idle_call+0x43/0x70 [ 81.836210] do_idle+0x258/0x800 [ 81.836581] cpu_startup_entry+0x26/0x30 [ 81.837002] __pfx_ap_starting+0x0/0x10 [ 81.837444] secondary_startup_64_no_verify+0x17a/0x17b [ 81.837979] [ 81.838166] Local variable nlbl_type.i created at: [ 81.838596] selinux_inet_conn_request+0xe3/0x4b0 [ 81.839078] security_inet_conn_request+0xc0/0x160
KMSAN warning is reproducible with:
* netlabel_mgmt_protocount is 0 (e.g. netlbl_enabled() returns 0)
* CONFIG_SECURITY_NETWORK_XFRM may be set or not
* CONFIG_KMSAN=y
* ssh USER@HOSTNAME /bin/date
selinux_skb_peerlbl_sid() will call selinux_xfrm_skb_sid(), then fall to selinux_netlbl_skbuff_getsid() which will not initialize nlbl_type, but it will be passed to:
err = security_net_peersid_resolve(nlbl_sid,
nlbl_type, xfrm_sid, sid);
and checked by KMSAN, although it will not be used inside security_net_peersid_resolve() (at least now), since this function will check either (xfrm_sid == SECSID_NULL) or (nlbl_sid == SECSID_NULL) first and return before using uninitialized nlbl_type.
--- security/selinux/netlabel.c | 1 + 1 file changed, 1 insertion(+)
security/selinux/netlabel.c +1 -0
@@ -195,6 +195,7 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb,struct netlbl_lsm_secattr secattr;if (!netlbl_enabled ()) { + *type =NETLBL_NLTYPE_NONE ; *sid =SECSID_NULL ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1107/1848 ovl: inherit FMODE_NONOTIFY when reading directory layers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 9ff338af0e002fe217cfa16b1289b76f6b21fc72 ]
Listing a merged or impure overlay directory opens the real layer directories from ovl_dir_read(), when the readdir cache is filled. Those opens use plain ovl_path_open(), so when the directory fd is one that fanotify created for a permission event, they can still raise FS_OPEN_PERM. A listener that also marks the backing filesystem and calls getdents() on the event fd before answering then deadlocks the same way as with the directory open fixed by the previous commit.
Store the overlay user file in struct ovl_readdir_data and pass it to ovl_path_open_realfile() from ovl_dir_read(), for both the merged and the impure cache. Internal readers such as ovl_check_empty_dir() and the mount-time workdir cleanup still pass no user file.
A note about severity and real world impact: The FAN_OPEN_PERM event is traditionally used by anti-malware protection agents and security/audit agents. The scope that is often used in those use cases is FAN_MARK_MOUNT and agents typically monitor multiple mounts in a mount namespace. FAN_OPEN_PERM from directory open requires user opt-in with FAN_ONDIR. It is often not the case that anti-malware agents monitor open of directories. Security/audit engines are more likely to opt-into FAN_OPEN_PERM on directories, but are less likely to list the content of a directory within the scope of FAN_OPEN_PERM event, so the real world impact of this bug is likely not significant.
--- fs/overlayfs/readdir.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
fs/overlayfs/readdir.c +20 -11
@@ -37,6 +37,7 @@ struct ovl_dir_cache {struct ovl_readdir_data {struct dir_context ctx; +const struct file *user_file;struct dentry *dentry;bool is_lowest;struct rb_root *root;
@@ -295,9 +296,13 @@ static inline int ovl_dir_read(struct path *realpath, struct ovl_readdir_data *rdd) {struct file *realfile; +int flags =O_RDONLY |O_LARGEFILE ;int err; - realfile =ovl_path_open (realpath,O_RDONLY |O_LARGEFILE ); +if (rdd->user_file && (rdd->user_file->f_mode &FMODE_NONOTIFY )) + flags |= __FMODE_NONOTIFY; + + realfile =ovl_path_open (realpath, flags);if (IS_ERR (realfile))return PTR_ERR (realfile);
@@ -341,12 +346,13 @@ static void ovl_dir_reset(struct file *file) }static int ovl_dir_read_merged (struct dentry *dentry,struct list_head *list, -struct rb_root *root) +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_merge, + .user_file = user_file, .dentry = dentry, .list = list, .root = root,
@@ -390,9 +396,10 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos) od->cursor = p; } -static struct ovl_dir_cache *ovl_cache_get (struct dentry *dentry) +static struct ovl_dir_cache *ovl_dir_cache_get (struct file *file) {int res; +struct dentry *dentry = file->f_path.dentry;struct ovl_dir_cache *cache; cache =ovl_dir_cache (d_inode (dentry));
@@ -411,7 +418,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)INIT_LIST_HEAD (&cache->entries); cache->root =RB_ROOT ; - res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root); + res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -545,14 +552,15 @@ static int ovl_fill_plain(struct dir_context *ctx, const char *name,return 0 ; } -static int ovl_dir_read_impure (struct path *path,struct list_head *list, -struct rb_root *root) +static int ovl_dir_read_impure (struct path *path,struct list_head *list, +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_cache_entry *p, *n;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_plain, + .user_file = user_file, .list = list, .root = root, };
@@ -590,9 +598,10 @@ static int ovl_dir_read_impure(struct path *path, struct list_head *list,return 0 ; } -static struct ovl_dir_cache *ovl_cache_get_impure (struct path *path) +static struct ovl_dir_cache *ovl_cache_get_impure (struct file *file) {int res; +struct path *path = &file->f_path;struct dentry *dentry = path->dentry;struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_dir_cache *cache;
@@ -609,7 +618,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(struct path *path)if (!cache)return ERR_PTR (-ENOMEM ); - res =ovl_dir_read_impure (path, &cache->entries, &cache->root); + res =ovl_dir_read_impure (path, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -724,7 +733,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)dput (parent);if (ovl_is_impure_dir (file)) { - rdt.cache =ovl_cache_get_impure (&file->f_path); + rdt.cache =ovl_cache_get_impure (file);if (IS_ERR (rdt.cache))return PTR_ERR (rdt.cache); }
@@ -771,7 +780,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)if (!od->cache) {struct ovl_dir_cache *cache; - cache =ovl_cache_get (dentry); + cache =ovl_dir_cache_get (file); err =PTR_ERR (cache);if (IS_ERR (cache)) goto out;
@@ -986,7 +995,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)const struct cred *old_cred; old_cred =ovl_override_creds (dentry->d_sb); - err =ovl_dir_read_merged (dentry, list, &root); + err =ovl_dir_read_merged (dentry, list, &root,NULL );revert_creds (old_cred);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1108/1848 comedi: addi_apci_3xxx: fix subdevice count underallocation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Zi <[email protected]>
[ Upstream commit 3de5aa458dede472a253266d02902bd95af8e849 ]
In apci3xxx_auto_attach(), the number of subdevices is computed with
n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao + ...
The ternary is inverted: when the board has analog input channels (ai_n_chan != 0), it counts 0 instead of 1, so the AI subdevice that is actually created is not accounted for. As a result comedi_alloc_subdevices() allocates one entry too few, and the later subdevice initialization (notably the TTL Digital I/O subdevice, which is populated last) writes past the end of the allocated array, causing a slab out-of-bounds write.
Flip the ternary to count 1 when ai_n_chan is non-zero and 0 otherwise, matching the subdevice creation order in the function.
--- drivers/staging/comedi/drivers/addi_apci_3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/comedi/drivers/addi_apci_3xxx.c +1 -1
@@ -788,7 +788,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - n_subdevices = (board->ai_n_chan ?0 :1 ) + board->has_ao + + n_subdevices = (board->ai_n_chan ?1 :0 ) + board->has_ao + board->has_dig_in + board->has_dig_out + board->has_ttl_io; ret =comedi_alloc_subdevices (dev, n_subdevices);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1109/1848 comedi: dt2811: fix shift-out-of-bounds in IRQ check
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 471ce96a9c415b8a67bd5081ac2089a458cacc2f ]
The IRQ number passed via comedi_devconfig->options[1] is a signed int that comes from userspace. The check it->options[1] <= 7 does not reject negative values, so a negative IRQ number reaches BIT(it->options[1]), which is undefined behavior and triggers a UBSAN shift-out-of-bounds warning:
UBSAN: shift-out-of-bounds in drivers/comedi/drivers/dt2811.c:570:31 shift exponent -251 is negative
Add an explicit lower bound check (it->options[1] >= 0) so that only valid IRQ numbers 0..7 are accepted before the shift.
--- drivers/staging/comedi/drivers/dt2811.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/comedi/drivers/dt2811.c +1 -1
@@ -567,7 +567,7 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)dt2811_reset (dev);/* IRQ's 2,3,5,7 are valid for async command support */ -if (it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { +if (it->options[1 ] >=0 && it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { ret =request_irq (it->options[1 ], dt2811_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1110/1848 drm/amdgpu: parse CS IBs at the BO offset their VA mapping starts at
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 63a59637517682a920f86da1a189a3e639dd4fb3 ]
For rings which parse or patch the IBs on the CPU, like JPEG and VCN, the CS looks the IB up through its VA mapping and maps the BO, but ignores the offset in the BO the mapping starts at. It then parses other data than the GPU executes. On navi31, an IB of JPEG NOPs in the second page of a BO, mapped with offset_in_bo 4096, is parsed from the zeros in the first page and rejected:
amdgpu 0000:03:00.0: Invalid packet [0x00000000]!
while the same IB submitted through a mapping of the whole BO works.
Add the mapping offset when locating the IB in the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -771,7 +771,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p) } offset = m->start *AMDGPU_GPU_PAGE_SIZE ; - kptr += va_start - offset; + kptr += va_start - offset + m->offset;if (ring->funcs->parse_cs) {memcpy (ib->ptr, kptr, chunk_ib->ib_bytes);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1111/1848 ocfs2: validate move extents against a stable EOF
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 84db6619cb702c37cf848b450c21b9c9706b0775 ]
The move-extents range must be bounded by the inode size used for extent movement. ocfs2_ioctl_move_extents() checks and clamps the request before taking the local inode and cluster locks in ocfs2_move_extents(). It also uses separate i_size_read() calls for the range check and subtraction.
A concurrent truncate can invalidate the first check and make the later unsigned subtraction underflow:
Move-extents ioctl Truncate
------------------ --------
check me_start <= i_size
take inode and cluster locks shrink EOF below me_start release locks
compare me_start + me_len with EOF
set me_len = EOF - me_start
[unsigned underflow]
acquire inode and cluster locks
select extents using the bad range
A truncate after clamping can also leave the range extending beyond EOF. Conversely, the cached size may be smaller than the size refreshed when the cluster inode lock is acquired. Early validation can then reject a valid start or permanently shorten the requested length and threshold. The me_start + me_len comparison can also wrap for a large input length.
Validate and adjust the original request once, after inode_lock(), the exclusive rw lock and ocfs2_inode_lock() have stabilized and refreshed the size. Read EOF once, reject a start beyond it, and bound the length by EOF minus start. Normalize the threshold using the same EOF snapshot. This keeps zero as the default-threshold sentinel until validation uses the size that will govern extent movement.
Move goal validation after range adjustment as well. Its allocation-group capacity check uses me_len and must see the EOF-clamped length. Both validation failures use the existing inode-lock unwind path before any extent movement or transaction starts.
Range errors now reach the ioctl's normal copyout path, as goal errors already did. Unlike the old early rejection, a failed copyout can therefore override -EINVAL with -EFAULT.
--- fs/ocfs2/move_extents.c | 62 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
fs/ocfs2/move_extents.c +31 -31
@@ -908,8 +908,10 @@ static int __ocfs2_move_extents_range(struct buffer_head *di_bh,static int ocfs2_move_extents (struct ocfs2_move_extents_context *context) {int status; +u64 i_size;handle_t *handle;struct inode *inode = context->inode; +struct ocfs2_move_extents *range = context->range;struct ocfs2_dinode *di;struct buffer_head *di_bh =NULL ;struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);
@@ -934,6 +936,35 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context) goto out_rw_unlock; } + i_size =i_size_read (inode); +if (range->me_start > i_size) { + status = -EINVAL ; +mlog_errno (status); + goto out_inode_unlock; + } + +if (range->me_len > i_size - range->me_start) + range->me_len = i_size - range->me_start; + +/* +* The default threshold for defragmentation is 1 MiB, which +* matches the maximum OCFS2 cluster size. +*/ +if (!range->me_threshold) + range->me_threshold =1024 *1024 ; + +if (range->me_threshold > i_size) + range->me_threshold = i_size; + +/* The goal check depends on the adjusted range length. */ +if (!context->auto_defrag) { + status =ocfs2_validate_and_adjust_move_goal (inode, context->range); +if (status) { +mlog_errno (status); + goto out_inode_unlock; + } + } +/* * rememer ip_xattr_sem also needs to be held if necessary */
@@ -1026,49 +1057,18 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) goto out_free; } -if (range.me_start >i_size_read (inode)) { - status = -EINVAL ; - goto out_free; - } - -if (range.me_start + range.me_len >i_size_read (inode)) - range.me_len =i_size_read (inode) - range.me_start; - context->range = ⦥ -/* -* ok, the default theshold for the defragmentation -* is 1M, since our maximum clustersize was 1M also. -* any thought? -*/ -if (!range.me_threshold) - range.me_threshold =1024 *1024 ; - -if (range.me_threshold >i_size_read (inode)) - range.me_threshold =i_size_read (inode); -if (range.me_flags &OCFS2_MOVE_EXT_FL_AUTO_DEFRAG ) { context->auto_defrag =1 ;if (range.me_flags &OCFS2_MOVE_EXT_FL_PART_DEFRAG ) context->partial =1 ; - }else { -/* -* first best-effort attempt to validate and adjust the goal -* (physical address in block), while it can't guarantee later -* operation can succeed all the time since global_bitmap may -* change a bit over time. -*/ - - status =ocfs2_validate_and_adjust_move_goal (inode, &range); -if (status) - goto out_copy; } status =ocfs2_move_extents (context);if (status)mlog_errno (status); -out_copy:/* * movement/defragmentation may end up being partially completed, * that's the reason why we need to return userspace the finished
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1112/1848 xfs: add a flag to convert unwritten extents without allocating blocks
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit f3ca3498dfe624f9b604c934263538a3acd55af5 ]
xfs_bmapi_write() with XFS_BMAPI_CONVERT also allocates blocks for holes and delalloc extents in the range. Add XFS_BMAPI_CONVERT_ONLY for callers that may only convert already allocated blocks. It stops at a hole or delalloc extent, and returns -ENOSR if it stops before mapping anything.
Marked for stable because "xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks" needs it.
--- fs/xfs/libxfs/xfs_bmap.c | 12 ++++++++++++ fs/xfs/libxfs/xfs_bmap.h | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_bmap.c +12 -0
@@ -4304,6 +4304,8 @@ xfs_bmapi_finish(* extent state if necessary. Details behaviour is controlled by the flags * parameter. Only allocates blocks from a single allocation group, to avoid * locking problems. +* With XFS_BMAPI_CONVERT_ONLY, it stops at a hole or a delalloc extent instead +* of allocating blocks, and returns -ENOSR if it stops before mapping anything. */ int xfs_bmapi_write(
@@ -4363,6 +4365,8 @@ xfs_bmapi_write(*/ ASSERT ((flags & (XFS_BMAPI_PREALLOC |XFS_BMAPI_ZERO )) != (XFS_BMAPI_PREALLOC |XFS_BMAPI_ZERO )); +ASSERT (!(flags &XFS_BMAPI_CONVERT_ONLY ) || + (flags &XFS_BMAPI_CONVERT ));if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) {
@@ -4412,6 +4416,9 @@ xfs_bmapi_write(* that we found, if any. */ if (need_alloc || wasdelay) { +if (flags &XFS_BMAPI_CONVERT_ONLY ) +break ; + bma.eof = eof; bma.conv = !!(flags &XFS_BMAPI_CONVERT ); bma.wasdel = wasdelay;
@@ -4486,6 +4493,11 @@ xfs_bmapi_write(xfs_bmapi_finish (&bma, whichfork,0 );xfs_bmap_validate_ret (orig_bno, orig_len, orig_flags, orig_mval, orig_nmap, *nmap); + +if (!n && (flags &XFS_BMAPI_CONVERT_ONLY )) { +ASSERT (bma.nallocs ==0 ); +return -ENOSR ; + }return 0 ; error0:xfs_bmapi_finish (&bma, whichfork, error);
fs/xfs/libxfs/xfs_bmap.h +9 -1
@@ -101,6 +101,13 @@ struct xfs_extent_free_item/* Do not update the rmap btree. Used for reconstructing bmbt from rmapbt. */ #define XFS_BMAPI_NORMAP 0x2000 +/* +* Use with XFS_BMAPI_CONVERT to convert unwritten extents without allocating +* blocks. Stop at a hole or a delalloc extent: return the mappings found so +* far, or -ENOSR if there are none. +*/ +#define XFS_BMAPI_CONVERT_ONLY 0x4000 +#define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \
@@ -112,7 +119,8 @@ struct xfs_extent_free_item { XFS_BMAPI_REMAP, "REMAP" }, \ { XFS_BMAPI_COWFORK, "COWFORK" }, \ { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ - { XFS_BMAPI_NORMAP, "NORMAP" } + { XFS_BMAPI_NORMAP, "NORMAP" }, \ + { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" } static inline int xfs_bmapi_aflag(int w)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1113/1848 udf: dont use eloc after the end of the unallocated space table
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 94401199df90e1c2a50c6e4b73618ac5a4ba83ba ]
When udf_next_aext() returns 0, its eloc, elen and etype outputs hold no defined value. Two walks of the unallocated space table still use eloc after the walk has reached the end of the table.
udf_table_prealloc_blocks() looks for a free extent starting at first_block and decides whether it found one by comparing eloc with first_block after the walk. If the table's list ends in a continuation descriptor that leads to an empty allocation extent, eloc is then the block of that allocation extent, which is in use, and if that is first_block, the block is handed out as preallocation. Once udf_discard_prealloc() no longer frees the wrong block, this is what still makes fsx in generic/091 and generic/263 read back bad data on a table, in about one run in four. Only take the extent if the walk stopped at it.
When udf_table_free_blocks() cannot merge the freed blocks into an existing extent, it appends a new one and sets only its block number, so the partition reference comes from whatever eloc held after the walk, and with long allocation descriptors it is written to disk. For a table without extents, eloc was never set. Take the partition reference from the freed blocks instead. Short allocation descriptors do not store the partition reference, which is why this half remains a latent long-descriptor fix rather than a reproduced failure.
--- fs/udf/balloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/udf/balloc.c +2 -1
@@ -473,6 +473,7 @@ static void udf_table_free_blocks(struct super_block *sb,int adsize; + eloc.partitionReferenceNum = bloc->partitionReferenceNum; eloc.logicalBlockNum = start; elen =EXT_RECORDED_ALLOCATED | (count << sb->s_blocksize_bits);
@@ -545,7 +546,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb, ;/* empty loop body */ } -if (first_block == eloc.logicalBlockNum) { +if (etype !=-1 && first_block == eloc.logicalBlockNum) { epos.offset -= adsize; alloc_count = (elen >> sb->s_blocksize_bits);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1114/1848 sign-file,extract-cert: move common SSL helper functions to a header
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
commit 300e6d4116f956b035281ec94297dc4dc8d4e1d3 upstream.
Couple error handling helpers are repeated in both tools, so move them to a common header.
--- MAINTAINERS | 1 + scripts/extract-cert.c | 37 ++----------------------------------- scripts/sign-file.c | 37 ++----------------------------------- scripts/ssl-common.h | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 70 deletions(-)
MAINTAINERS +1 -0
@@ -4103,6 +4103,7 @@ F: Documentation/admin-guide/module-sign F: certs/ F: scripts/extract-cert.c F: scripts/sign-file.c +F: scripts/ssl-common.h CFAG12864B LCD DRIVER M: Miguel Ojeda Sandonis <[email protected]>
scripts/extract-cert.c +2 -35
@@ -23,6 +23,8 @@#include <openssl/err.h> #include <openssl/engine.h> +#include "ssl-common.h" +/* * OpenSSL 3.0 deprecates the OpenSSL's ENGINE API. *
@@ -40,41 +42,6 @@ void format(void)exit (2 ); } -static void display_openssl_errors (int l) -{ -const char *file; -char buf[120 ]; -int e, line; - -if (ERR_peek_error () ==0 ) -return ; -fprintf (stderr,"At main.c:%d:\n" , l); - -while ((e =ERR_get_error_line (&file, &line))) { -ERR_error_string (e, buf); -fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); - } -} - -static void drain_openssl_errors (void ) -{ -const char *file; -int line; - -if (ERR_peek_error () ==0 ) -return ; -while (ERR_get_error_line (&file, &line)) {} -} - -#define ERR (cond, fmt, ...) \ - do { \ - bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ - if (__cond) { \ - err(1, fmt, ## __VA_ARGS__); \ - } \ - } while(0) -static const char *key_pass;static BIO *wb;static char *cert_dst;
scripts/sign-file.c +2 -35
@@ -29,6 +29,8 @@#include <openssl/err.h> #include <openssl/engine.h> +#include "ssl-common.h" +/* * OpenSSL 3.0 deprecates the OpenSSL's ENGINE API. *
@@ -83,41 +85,6 @@ void format(void)exit (2 ); } -static void display_openssl_errors (int l) -{ -const char *file; -char buf[120 ]; -int e, line; - -if (ERR_peek_error () ==0 ) -return ; -fprintf (stderr,"At main.c:%d:\n" , l); - -while ((e =ERR_get_error_line (&file, &line))) { -ERR_error_string (e, buf); -fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); - } -} - -static void drain_openssl_errors (void ) -{ -const char *file; -int line; - -if (ERR_peek_error () ==0 ) -return ; -while (ERR_get_error_line (&file, &line)) {} -} - -#define ERR (cond, fmt, ...) \ - do { \ - bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ - if (__cond) { \ - err(1, fmt, ## __VA_ARGS__); \ - } \ - } while(0) -static const char *key_pass;static int pem_pw_cb (char *buf,int len,int w,void *v)
scripts/ssl-common.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* +* SSL helper functions shared by sign-file and extract-cert. +*/ + +static void display_openssl_errors (int l) +{ +const char *file; +char buf[120 ]; +int e, line; + +if (ERR_peek_error () ==0 ) +return ; +fprintf (stderr,"At main.c:%d:\n" , l); + +while ((e =ERR_get_error_line (&file, &line))) { +ERR_error_string (e, buf); +fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); + } +} + +static void drain_openssl_errors (void ) +{ +const char *file; +int line; + +if (ERR_peek_error () ==0 ) +return ; +while (ERR_get_error_line (&file, &line)) {} +} + +#define ERR (cond, fmt, ...) \ + do { \ + bool __cond = (cond); \ + display_openssl_errors(__LINE__); \ + if (__cond) { \ + errx(1, fmt, ## __VA_ARGS__); \ + } \ + } while (0)
Greg Kroah-Hartman
maintainerPATCH 1115/1848 sign-file,extract-cert: avoid using deprecated ERR_get_error_line()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
commit 467d60eddf55588add232feda325da7215ddaf30 upstream.
ERR_get_error_line() is deprecated since OpenSSL 3.0.
Use ERR_peek_error_line() instead, and combine display_openssl_errors() and drain_openssl_errors() to a single function where parameter decides if it should consume errors silently.
--- scripts/extract-cert.c | 4 ++-- scripts/sign-file.c | 6 +++--- scripts/ssl-common.h | 23 ++++++++--------------- 3 files changed, 13 insertions(+), 20 deletions(-)
scripts/extract-cert.c +2 -2
@@ -96,11 +96,11 @@ int main(int argc, char **argv) parms.cert =NULL ;ENGINE_load_builtin_engines (); -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 ); e =ENGINE_by_id ("pkcs11" );ERR (!e,"Load PKCS#11 ENGINE" );if (ENGINE_init (e)) -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 );else ERR (1 ,"ENGINE_init" );if (key_pass)
scripts/sign-file.c +3 -3
@@ -114,11 +114,11 @@ static EVP_PKEY *read_private_key(constENGINE *e;ENGINE_load_builtin_engines (); -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 ); e =ENGINE_by_id ("pkcs11" );ERR (!e,"Load PKCS#11 ENGINE" );if (ENGINE_init (e)) -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 );else ERR (1 ,"ENGINE_init" );if (key_pass)
@@ -273,7 +273,7 @@ int main(int argc, char **argv)/* Digest the module data. */ OpenSSL_add_all_digests (); -display_openssl_errors (__LINE__); +drain_openssl_errors (__LINE__,0 ); digest_algo =EVP_get_digestbyname (hash_algo);ERR (!digest_algo,"EVP_get_digestbyname" );
scripts/ssl-common.h +8 -15
@@ -3,7 +3,7 @@* SSL helper functions shared by sign-file and extract-cert. */ -static void display_openssl_errors (int l) +static void drain_openssl_errors (int l,int silent) {const char *file;char buf[120 ];
@@ -11,28 +11,21 @@ static void display_openssl_errors(int lif (ERR_peek_error () ==0 )return ; -fprintf (stderr,"At main.c:%d:\n" , l); +if (!silent) +fprintf (stderr,"At main.c:%d:\n" , l); -while ((e =ERR_get_error_line (&file, &line))) { +while ((e =ERR_peek_error_line (&file, &line))) {ERR_error_string (e, buf); -fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); +if (!silent) +fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); +ERR_get_error (); } } -static void drain_openssl_errors (void ) -{ -const char *file; -int line; - -if (ERR_peek_error () ==0 ) -return ; -while (ERR_get_error_line (&file, &line)) {} -} -#define ERR (cond, fmt, ...) \ do { \ bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ + drain_openssl_errors(__LINE__, 0); \ if (__cond) { \ errx(1, fmt, ## __VA_ARGS__); \ } \
Greg Kroah-Hartman
maintainerPATCH 1116/1848 sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
commit 558bdc45dfb2669e1741384a0c80be9c82fa052c upstream.
ENGINE API has been deprecated since OpenSSL version 3.0 [1]. Distros have started dropping support from headers and in future it will likely disappear also from library.
It has been superseded by the PROVIDER API, so use it instead for OPENSSL MAJOR >= 3.
[1] https://github.com/openssl/openssl/blob/master/README-ENGINES.md
[jarkko: fixed up alignment issues reported by checkpatch.pl --strict]
--- scripts/extract-cert.c | 103 ++++++++++++++++++++++++++++++++++--------------- scripts/sign-file.c | 95 +++++++++++++++++++++++++++++++-------------- 2 files changed, 139 insertions(+), 59 deletions(-)
scripts/extract-cert.c +73 -30
@@ -21,17 +21,18 @@#include <openssl/bio.h> #include <openssl/pem.h> #include <openssl/err.h> -#include <openssl/engine.h> - +#if OPENSSL_VERSION_MAJOR >=3 +# define USE_PKCS11_PROVIDER +# include <openssl/provider.h> +# include <openssl/store.h> +#else +# if !defined(OPENSSL_NO_ENGINE ) && !defined(OPENSSL_NO_DEPRECATED_3_0 ) +# define USE_PKCS11_ENGINE +# include <openssl/engine.h> +# endif +#endif #include "ssl-common.h" -/* -* OpenSSL 3.0 deprecates the OpenSSL's ENGINE API. -* -* Remove this if/when that API is no longer used -*/ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#define PKEY_ID_PKCS7 2 static __attribute__((noreturn))
@@ -61,6 +62,66 @@ static void write_cert(X509 *x509)fprintf (stderr,"Extracted cert: %s\n" , buf); } +static X509 *load_cert_pkcs11 (const char *cert_src) +{ +X509 *cert =NULL ; +#ifdef USE_PKCS11_PROVIDER +OSSL_STORE_CTX *store; + +if (!OSSL_PROVIDER_try_load (NULL ,"pkcs11" , true)) +ERR (1 ,"OSSL_PROVIDER_try_load(pkcs11)" ); +if (!OSSL_PROVIDER_try_load (NULL ,"default" , true)) +ERR (1 ,"OSSL_PROVIDER_try_load(default)" ); + + store =OSSL_STORE_open (cert_src,NULL ,NULL ,NULL ,NULL ); +ERR (!store,"OSSL_STORE_open" ); + +while (!OSSL_STORE_eof (store)) { +OSSL_STORE_INFO *info =OSSL_STORE_load (store); + +if (!info) { +drain_openssl_errors (__LINE__,0 ); +continue ; + } +if (OSSL_STORE_INFO_get_type (info) ==OSSL_STORE_INFO_CERT ) { + cert =OSSL_STORE_INFO_get1_CERT (info); +ERR (!cert,"OSSL_STORE_INFO_get1_CERT" ); + } +OSSL_STORE_INFO_free (info); +if (cert) +break ; + } +OSSL_STORE_close (store); +#elif defined(USE_PKCS11_ENGINE ) +ENGINE *e; +struct { +const char *cert_id; +X509 *cert; + } parms; + + parms.cert_id = cert_src; + parms.cert =NULL ; + +ENGINE_load_builtin_engines (); +drain_openssl_errors (__LINE__,1 ); + e =ENGINE_by_id ("pkcs11" ); +ERR (!e,"Load PKCS#11 ENGINE" ); +if (ENGINE_init (e)) +drain_openssl_errors (__LINE__,1 ); +else +ERR (1 ,"ENGINE_init" ); +if (key_pass) +ERR (!ENGINE_ctrl_cmd_string (e,"PIN" , key_pass,0 ),"Set PKCS#11 PIN" ); +ENGINE_ctrl_cmd (e,"LOAD_CERT_CTRL" ,0 , &parms,NULL ,1 ); +ERR (!parms.cert,"Get X.509 from PKCS#11" ); + cert = parms.cert; +#else +fprintf (stderr,"no pkcs11 engine/provider available\n" ); +exit (1 ); +#endif +return cert; +} +int main (int argc,char **argv) {char *cert_src;
@@ -86,28 +147,10 @@ int main(int argc, char **argv)fclose (f);exit (0 ); }else if (!strncmp (cert_src,"pkcs11:" ,7 )) { -ENGINE *e; -struct { -const char *cert_id; -X509 *cert; - } parms; - - parms.cert_id = cert_src; - parms.cert =NULL ; +X509 *cert =load_cert_pkcs11 (cert_src); -ENGINE_load_builtin_engines (); -drain_openssl_errors (__LINE__,1 ); - e =ENGINE_by_id ("pkcs11" ); -ERR (!e,"Load PKCS#11 ENGINE" ); -if (ENGINE_init (e)) -drain_openssl_errors (__LINE__,1 ); -else -ERR (1 ,"ENGINE_init" ); -if (key_pass) -ERR (!ENGINE_ctrl_cmd_string (e,"PIN" , key_pass,0 ),"Set PKCS#11 PIN" ); -ENGINE_ctrl_cmd (e,"LOAD_CERT_CTRL" ,0 , &parms,NULL ,1 ); -ERR (!parms.cert,"Get X.509 from PKCS#11" ); -write_cert (parms.cert); +ERR (!cert,"load_cert_pkcs11 failed" ); +write_cert (cert); }else {BIO *b;X509 *x509;
scripts/sign-file.c +66 -29
121 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 1117/1848 extract-cert: Wrap key_pass with #ifdef USE_PKCS11_ENGINE
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 4f96b7c68a9904e01049ef610d701b382dca9574 upstream.
A recent strengthening of -Wunused-but-set-variable (enabled with -Wall) in clang under a new subwarning, -Wunused-but-set-global, points out an unused static global variable in certs/extract-cert.c:
certs/extract-cert.c:46:20: error: variable 'key_pass' set but not used [-Werror,-Wunused-but-set-global]
46 | static const char *key_pass;
| ^After commit 558bdc45dfb2 ("sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3"), key_pass is only used with the OpenSSL engine API, not the new provider API. Wrap key_pass's declaration and assignment with '#ifdef USE_PKCS11_ENGINE' so that it is only included with its use to clear up the warning. While this is a little uglier than just marking key_pass with the unused attribute, this will make it easier to clean up all code associated with the use of the engine API if it were ever removed in the future. While in the area, use a tab for the key_pass assignment line to match the rest of the file.
--- scripts/extract-cert.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/extract-cert.c +5 -1
@@ -43,7 +43,9 @@ void format(void)exit (2 ); } +#ifdef USE_PKCS11_ENGINE static const char *key_pass; +#endif static BIO *wb;static char *cert_dst;static int kbuild_verbose;
@@ -132,7 +134,9 @@ int main(int argc, char **argv) kbuild_verbose =atoi (getenv ("KBUILD_VERBOSE" )?:"0" ); - key_pass =getenv ("KBUILD_SIGN_PIN" ); +#ifdef USE_PKCS11_ENGINE + key_pass =getenv ("KBUILD_SIGN_PIN" ); +#endif if (argc !=3 )format ();
Greg Kroah-Hartman
maintainerPATCH 1118/1848 crypto: ecdh - explicitly zeroize private_key
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joachim Vandersmissen <[email protected]>
commit 73e5984e540a76a2ee1868b91590c922da8c24c9 upstream.
private_key is overwritten with the key parameter passed in by the caller (if present), or alternatively a newly generated private key. However, it is possible that the caller provides a key (or the newly generated key) which is shorter than the previous key. In that scenario, some key material from the previous key would not be overwritten. The easiest solution is to explicitly zeroize the entire private_key array first.
Note that this patch slightly changes the behavior of this function:
previously, if the ecc_gen_privkey failed, the old private_key would remain. Now, the private_key is always zeroized. This behavior is consistent with the case where params.key is set and ecc_is_key_valid fails.
--- crypto/ecdh.c | 2 ++ 1 file changed, 2 insertions(+)
crypto/ecdh.c +2 -0
@@ -33,6 +33,8 @@ static int ecdh_set_secret(struct crypto params.key_size > sizeof(u64) * ctx->ndigits)return -EINVAL ; +memset (ctx->private_key,0 ,sizeof (ctx->private_key)); +if (!params.key || !params.key_size)return ecc_gen_privkey (ctx->curve_id, ctx->ndigits, ctx->private_key);
Greg Kroah-Hartman
maintainerPATCH 1119/1848 drm/komeda: Fix bits parsing of GLB_CORE_ID
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raveendra Talabattula <[email protected]>
[ Upstream commit ec902de0221747094f9ccbb61454e9633fbf282f ]
GLB_CORE_ID contains the product and version information returned by the hardware. The current macros parses VERSION_MINOR as a 4-bit field and VERSION_STATUS as an 8-bit field, which does not match the register layout. As a result, the driver reports an incorrect version number.
Fix the parsing macros to match the hardware specification:
- VERSION_MINOR is 8 bits at [11:4]
- VERSION_STATUS is 4 bits at [3:0]
--- drivers/gpu/drm/arm/display/include/malidp_product.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/display/include/malidp_product.h +7 -3
@@ -8,14 +8,18 @@#define _MALIDP_PRODUCT_H_/* Product identification */ +/* GLB_CORE_ID fields as per HW specification: +* MINOR is 8 bits ([11:4]) and STATUS is 4 bits ([3:0]). +* Update masks/shifts accordingly. +*/ #define MALIDP_CORE_ID (__product, __major, __minor, __status) \ ((((__product) & 0xFFFF) << 16) | (((__major) & 0xF) << 12) | \ - (((__minor) & 0xF) << 8) | ((__status) & 0xFF)) + (((__minor) & 0xFF) << 4) | ((__status) & 0xF))#define MALIDP_CORE_ID_PRODUCT_ID (__core_id) ((__u32)(__core_id) >> 16)#define MALIDP_CORE_ID_MAJOR (__core_id) (((__u32)(__core_id) >> 12) & 0xF) -#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 8) & 0xF) -#define MALIDP_CORE_ID_STATUS (__core_id) (((__u32)(__core_id)) & 0xFF) +#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 4) & 0xFF) +#define MALIDP_CORE_ID_STATUS (__core_id) ((__u32)(__core_id) & 0xF)/* Mali-display product IDs */ #define MALIDP_D71_PRODUCT_ID 0x0071
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1120/1848 drm/panfrost: Prevent division by 0
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit fd4227f03546c323b5b21568f727233e9792d298 ]
When updating and debug-printing devfreq stats, in the very unlikely off-chance that total device time is less than 100 ns, division by 0 would happen. Fix the divisor when relevant and rearrange operands.
--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_devfreq.c +1 -1
@@ -74,7 +74,7 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,dev_dbg (pfdev->dev,"busy %lu total %lu %lu %% freq %lu MHz\n" , status->busy_time, status->total_time, - status->busy_time / (status->total_time /100 ), + status->busy_time *100 /MAX (status->total_time,1 ), status->current_frequency /1000 /1000 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1121/1848 bpftool: Fix spurious batch file read error
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 713c02b59e21840f623a3e31c43d967026c75181 ]
do_batch() checks errno after the read loop to detect read failures, but fgets() does not clear errno on success, so a stale errno left by a previously executed command (e.g. map dump's EBADF from a double close) makes bpftool report a batch file read failure and exit with an error even though every command succeeded.
Clear errno before each fgets() call, so the post-loop check only sees the outcome of the last read: zero on success or EOF, E2BIG for an overlong line, and a genuine errno when fgets() fails.
Since errno is now reset before every read in batch mode, drop the USE_LIBCAP errno reset in main() that existed only to keep errno clean for the batch mode.
--- tools/bpf/bpftool/main.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
tools/bpf/bpftool/main.c +5 -11
@@ -300,7 +300,11 @@ static int do_batch(int argc, char **argv)if (json_output)jsonw_start_array (json_wtr); -while (fgets (buf,sizeof (buf), fp)) { +for (;;) { + errno =0 ; +if (!fgets (buf,sizeof (buf), fp)) +break ; + cp =strchr (buf,'#' );if (cp) *cp ='\0' ;
@@ -398,16 +402,6 @@ int main(int argc, char **argv)setlinebuf (stdout); -#ifdef USE_LIBCAP -/* Libcap < 2.63 hooks before main() to compute the number of -* capabilities of the running kernel, and doing so it calls prctl() -* which may fail and set errno to non-zero. -* Let's reset errno to make sure this does not interfere with the -* batch mode. -*/ - errno =0 ; -#endif - last_do_help = do_help; pretty_output = false; json_output = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1122/1848 regulator: fixed: reject incompatible platform devices
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chandradhar Kumar <[email protected]>
[ Upstream commit f7396c2dbbc1bed6c2c554d1ddf80d16e4780a7d ]
The fixed regulator driver expects non-DT platform devices to provide their configuration through platform_data as a struct fixed_voltage_config.
An explicitly bound driver can bypass the normal platform device/driver matching and attach the fixed regulator driver to an unrelated platform device. This causes the driver's platform_data to be interpreted as a struct fixed_voltage_config even though it contains data for a different device.
Reject non-DT platform devices whose name does not match the fixed regulator driver before accessing their platform data.
--- drivers/regulator/fixed.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/regulator/fixed.c +4 -0
@@ -27,6 +27,7 @@#include <linux/regulator/of_regulator.h> #include <linux/regulator/machine.h> #include <linux/clk.h> +#include <linux/string.h> struct fixed_voltage_data {
@@ -142,6 +143,9 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)enum gpiod_flags gflags;int ret; +if (!pdev->dev.of_node &&strcmp (pdev->name,"reg-fixed-voltage" )) +return -ENODEV ; + drvdata =devm_kzalloc (&pdev->dev,sizeof (struct fixed_voltage_data ),GFP_KERNEL );if (!drvdata)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1123/1848 spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
[ Upstream commit 6bae252a9452ca8496670230a7821c34450763a2 ]
Convert MSIOF Transmit and Receive Mode Register 1 field accesses to use the FIELD_PREP() bitfield access macro.
This gets rid of explicit shifts.
Stable-dep-of: 152867998da9 ("spi: sh-msiof: propagate setup runtime-PM errors")
--- drivers/spi/spi-sh-msiof.c | 45 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-)
drivers/spi/spi-sh-msiof.c +24 -21
@@ -7,6 +7,7 @@* Copyright (C) 2014-2017 Glider bvba */ +#include <linux/bitfield.h> #include <linux/bitmap.h> #include <linux/clk.h> #include <linux/completion.h>
@@ -84,20 +85,19 @@ struct sh_msiof_spi_priv {/* SITMDR1 and SIRMDR1 */ #define SIMDR1_TRMD BIT(31)/* Transfer Mode (1 = Master mode) */ -#define SIMDR1_SYNCMD_MASK GENMASK(29, 28)/* SYNC Mode */ -#define SIMDR1_SYNCMD_SPI (2 << 28)/* Level mode/SPI */ -#define SIMDR1_SYNCMD_LR (3 << 28)/* L/R mode */ -#define SIMDR1_SYNCAC_SHIFT 25/* Sync Polarity (1 = Active-low) */ -#define SIMDR1_BITLSB_SHIFT 24/* MSB/LSB First (1 = LSB first) */ -#define SIMDR1_DTDL_SHIFT 20/* Data Pin Bit Delay for MSIOF_SYNC */ -#define SIMDR1_SYNCDL_SHIFT 16/* Frame Sync Signal Timing Delay */ -#define SIMDR1_FLD_MASK GENMASK(3, 2)/* Frame Sync Signal Interval (0-3) */ -#define SIMDR1_FLD_SHIFT 2 +#define SIMDR1_SYNCMD GENMASK(29, 28)/* SYNC Mode */ +#define SIMDR1_SYNCMD_SPI 2U/* Level mode/SPI */ +#define SIMDR1_SYNCMD_LR 3U/* L/R mode */ +#define SIMDR1_SYNCAC BIT(25)/* Sync Polarity (1 = Active-low) */ +#define SIMDR1_BITLSB BIT(24)/* MSB/LSB First (1 = LSB first) */ +#define SIMDR1_DTDL GENMASK(22, 20)/* Data Pin Bit Delay for MSIOF_SYNC */ +#define SIMDR1_SYNCDL GENMASK(18, 16)/* Frame Sync Signal Timing Delay */ +#define SIMDR1_FLD GENMASK(3, 2)/* Frame Sync Signal Interval (0-3) */ #define SIMDR1_XXSTP BIT(0)/* Transmission/Reception Stop on FIFO */ /* SITMDR1 */ #define SITMDR1_PCON BIT(30)/* Transfer Signal Connection */ -#define SITMDR1_SYNCCH_MASK GENMASK(27, 26)/* Sync Signal Channel Select */ -#define SITMDR1_SYNCCH_SHIFT 26/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */ +#define SITMDR1_SYNCCH GENMASK(27, 26)/* Sync Signal Channel Select */ +/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */ /* SITMDR2 and SIRMDR2 */ #define SIMDR2_BITLEN1 (i) (((i) - 1) << 24)/* Data Size (8-32 bits) */
@@ -337,8 +337,9 @@ static u32 sh_msiof_spi_get_dtdl_and_syncdl(struct sh_msiof_spi_priv *p)return 0 ; } - val =sh_msiof_get_delay_bit (p->info->dtdl) <<SIMDR1_DTDL_SHIFT ; - val |=sh_msiof_get_delay_bit (p->info->syncdl) <<SIMDR1_SYNCDL_SHIFT ; + val =FIELD_PREP (SIMDR1_DTDL ,sh_msiof_get_delay_bit (p->info->dtdl)) | +FIELD_PREP (SIMDR1_SYNCDL , +sh_msiof_get_delay_bit (p->info->syncdl));return val; }
@@ -357,16 +358,18 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,* 1 0 11 11 0 0 * 1 1 11 11 1 1 */ - tmp =SIMDR1_SYNCMD_SPI |1 <<SIMDR1_FLD_SHIFT |SIMDR1_XXSTP ; - tmp |= !cs_high <<SIMDR1_SYNCAC_SHIFT ; - tmp |= lsb_first <<SIMDR1_BITLSB_SHIFT ; + tmp =FIELD_PREP (SIMDR1_SYNCMD ,SIMDR1_SYNCMD_SPI ) | +FIELD_PREP (SIMDR1_FLD ,1 ) |SIMDR1_XXSTP | +FIELD_PREP (SIMDR1_SYNCAC , !cs_high) | +FIELD_PREP (SIMDR1_BITLSB , lsb_first); tmp |=sh_msiof_spi_get_dtdl_and_syncdl (p);if (spi_controller_is_slave (p->ctlr)) {sh_msiof_write (p,SITMDR1 , tmp |SITMDR1_PCON ); }else {sh_msiof_write (p,SITMDR1 , tmp |SIMDR1_TRMD |SITMDR1_PCON | - (ss <MAX_SS ? ss :0 ) <<SITMDR1_SYNCCH_SHIFT ); +FIELD_PREP (SITMDR1_SYNCCH , + ss <MAX_SS ? ss :0 )); }if (p->ctlr->flags &SPI_CONTROLLER_MUST_TX ) {/* These bits are reserved if RX needs TX */
@@ -561,12 +564,12 @@ static int sh_msiof_spi_setup(struct spi_device *spi)return 0 ;/* Configure native chip select mode/polarity early */ - clr =SIMDR1_SYNCMD_MASK ; - set =SIMDR1_SYNCMD_SPI ; + clr =SIMDR1_SYNCMD ; + set =FIELD_PREP (SIMDR1_SYNCMD ,SIMDR1_SYNCMD_SPI );if (spi->mode &SPI_CS_HIGH ) - clr |=BIT (SIMDR1_SYNCAC_SHIFT ); + clr |=SIMDR1_SYNCAC ;else - set |=BIT (SIMDR1_SYNCAC_SHIFT ); + set |=SIMDR1_SYNCAC ;pm_runtime_get_sync (&p->pdev->dev); tmp =sh_msiof_read (p,SITMDR1 ) & ~clr;sh_msiof_write (p,SITMDR1 , tmp | set |SIMDR1_TRMD |SITMDR1_PCON );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1124/1848 spi: sh-msiof: propagate setup runtime-PM errors
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 152867998da9f331d6235d76aae1c7e1650708a9 ]
sh_msiof_spi_setup() ignores pm_runtime_get_sync() before programming native chip-select registers and marking the configuration initialized.
Use the checked runtime-PM helper and return failure before register access.
--- drivers/spi/spi-sh-msiof.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/spi/spi-sh-msiof.c +4 -1
@@ -555,6 +555,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi)struct sh_msiof_spi_priv *p =spi_controller_get_devdata (spi->controller);u32 clr, set, tmp; +int ret;if (spi->cs_gpiod ||spi_controller_is_slave (p->ctlr))return 0 ;
@@ -570,7 +571,9 @@ static int sh_msiof_spi_setup(struct spi_device *spi) clr |=SIMDR1_SYNCAC ; else set |= SIMDR1_SYNCAC; -pm_runtime_get_sync (&p->pdev->dev); + ret =pm_runtime_resume_and_get (&p->pdev->dev); +if (ret <0 ) +return ret; tmp =sh_msiof_read (p,SITMDR1 ) & ~clr;sh_msiof_write (p,SITMDR1 , tmp | set |SIMDR1_TRMD |SITMDR1_PCON ); tmp =sh_msiof_read (p,SIRMDR1 ) & ~clr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1125/1848 iio: humidity: hts221: report available values via read_avail()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adi Nata <[email protected]>
[ Upstream commit 003e99cf33e344a380ba10b3e04ccb862f3d9dc3 ]
Replace the custom oversampling_ratio_available sysfs attributes with the standard IIO read_avail() callback. This lets the IIO core create and format *_available attributes and exposes the lists to in-kernel consumers.
As a consequence, the incorrectly named in_humidity_oversampling_ratio_available attribute is replaced by the standard in_humidityrelative_oversampling_ratio_available name for the IIO_HUMIDITYRELATIVE channel. The temperature oversampling and sampling frequency available attribute names are unchanged.
--- drivers/iio/humidity/hts221_core.c | 106 +++++++++++------------------ 1 file changed, 40 insertions(+), 66 deletions(-)
drivers/iio/humidity/hts221_core.c +40 -66
@@ -10,7 +10,6 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h> -#include <linux/iio/sysfs.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/regmap.h>
@@ -48,7 +47,7 @@ struct hts221_odr {struct hts221_avg {u8 addr;u8 mask; -u16 avg_avl[HTS221_AVG_DEPTH ]; +int avg_avl[HTS221_AVG_DEPTH ]; };static const struct hts221_odr hts221_odr_table[] = {
@@ -57,6 +56,8 @@ static const struct hts221_odr hts221_odr_table[] = { { 13, 0x03 }, /* 12.5Hz */ }; +static const int hts221_odr_avail[] = { 1, 7, 13 }; + static const struct hts221_avg hts221_avg_list[] = { { .addr = 0x10,
@@ -96,7 +97,11 @@ static const struct iio_chan_spec hts221_channels[] = {BIT (IIO_CHAN_INFO_OFFSET ) |BIT (IIO_CHAN_INFO_SCALE ) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 0, .scan_type = { .sign = 's',
@@ -112,7 +117,11 @@ static const struct iio_chan_spec hts221_channels[] = {BIT (IIO_CHAN_INFO_OFFSET ) |BIT (IIO_CHAN_INFO_SCALE ) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 1, .scan_type = { .sign = 's',
@@ -191,53 +200,35 @@ static int hts221_update_avg(struct hts221_hw *hw,return 0 ; } -static ssize_t hts221_sysfs_sampling_freq (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -int i; -ssize_t len =0 ; - -for (i =0 ; i <ARRAY_SIZE (hts221_odr_table); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - hts221_odr_table[i].hz); - buf[len -1 ] ='\n' ; - -return len; -} - -static ssize_t -hts221_sysfs_rh_oversampling_avail (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -const struct hts221_avg *avg = &hts221_avg_list[HTS221_SENSOR_H ]; -ssize_t len =0 ; -int i; - -for (i =0 ; i <ARRAY_SIZE (avg->avg_avl); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - avg->avg_avl[i]); - buf[len -1 ] ='\n' ; - -return len; -} - -static ssize_t -hts221_sysfs_temp_oversampling_avail (struct device *dev, -struct device_attribute *attr, -char *buf) +static int hts221_read_avail (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length, +long mask) { -const struct hts221_avg *avg = &hts221_avg_list[HTS221_SENSOR_T ]; -ssize_t len =0 ; -int i; - -for (i =0 ; i <ARRAY_SIZE (avg->avg_avl); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - avg->avg_avl[i]); - buf[len -1 ] ='\n' ; - -return len; +switch (mask) { +case IIO_CHAN_INFO_OVERSAMPLING_RATIO : +switch (chan->type) { +case IIO_HUMIDITYRELATIVE : + *vals = hts221_avg_list[HTS221_SENSOR_H ].avg_avl; + *length =ARRAY_SIZE (hts221_avg_list[HTS221_SENSOR_H ].avg_avl); +break ; +case IIO_TEMP : + *vals = hts221_avg_list[HTS221_SENSOR_T ].avg_avl; + *length =ARRAY_SIZE (hts221_avg_list[HTS221_SENSOR_T ].avg_avl); +break ; +default : +return -EINVAL ; + } + *type =IIO_VAL_INT ; +return IIO_AVAIL_LIST ; +case IIO_CHAN_INFO_SAMP_FREQ : + *vals = hts221_odr_avail; + *type =IIO_VAL_INT ; + *length =ARRAY_SIZE (hts221_odr_avail); +return IIO_AVAIL_LIST ; +default : +return -EINVAL ; + } }int hts221_set_enable (struct hts221_hw *hw,bool enable)
@@ -521,27 +512,10 @@ static int hts221_validate_trigger(struct iio_dev *iio_dev,return hw->trig == trig ?0 : -EINVAL ; } -static IIO_DEVICE_ATTR(in_humidity_oversampling_ratio_available, S_IRUGO, - hts221_sysfs_rh_oversampling_avail, NULL, 0); -static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available, S_IRUGO, - hts221_sysfs_temp_oversampling_avail, NULL, 0); -static IIO_DEV_ATTR_SAMP_FREQ_AVAIL (hts221_sysfs_sampling_freq); - -static struct attribute *hts221_attributes[] = { - &iio_dev_attr_sampling_frequency_available.dev_attr.attr, - &iio_dev_attr_in_humidity_oversampling_ratio_available.dev_attr.attr, - &iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group hts221_attribute_group = { - .attrs = hts221_attributes, -}; -static const struct iio_info hts221_info = { - .attrs = &hts221_attribute_group, .read_raw = hts221_read_raw, .write_raw = hts221_write_raw, + .read_avail = hts221_read_avail, .validate_trigger = hts221_validate_trigger, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1126/1848 ARM: dts: helios4: fix lm75 supply name
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit ef473a83c63e3173ac472e42727e990b923b99db ]
The lm75 driver requests a regulator named "vs" (the +VS power pin of the chip). The Helios4 DTS incorrectly used vcc-supply instead of vs-supply, causing the regulator core to emit:
lm75 0-004c: supply vs not found, using dummy regulator
Fix the property name to match the binding and the driver.
--- arch/arm/boot/dts/armada-388-helios4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/armada-388-helios4.dts +1 -1
@@ -200,7 +200,7 @@ usb3_ilimit { temp_sensor: temp@4c { compatible = "ti,lm75"; reg = <0x4c>; - vcc-supply = <®_3p3v>; + vs-supply = <®_3p3v>; }; eeprom@53 {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1127/1848 ARM: dts: armada-385-clearfog-gtr: fix vmmc property name
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 337d10963f601d5a3dfb4b7aa273ca8c0b4d5172 ]
The SDHCI node references the 3.3V regulator through a bare "vmmc" property, which is not part of the mmc controller DT binding; the correct property is "vmmc-supply".
--- arch/arm/boot/dts/armada-385-clearfog-gtr.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/armada-385-clearfog-gtr.dtsi +1 -1
@@ -202,7 +202,7 @@ sdhci@d8000 { pinctrl-0 = <&cf_gtr_sdhci_pins>; pinctrl-names = "default"; status = "okay"; - vmmc = <®_3p3v>; + vmmc-supply = <®_3p3v>; wp-inverted; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1128/1848 ARM: dts: armada-395-gp: drop unsupported SDHCI clock-frequency
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit a56183c7f15215d804290808a2b5a1fa997aa9cd ]
The SDHCI node carries a "clock-frequency" property, but the marvell,armada-380-sdhci binding does not define it and dtbs_check rejects the node as a result. No driver consumes it either: only a few other sdhci-pltfm based drivers (imx, mcf, iproc, arasan, dwcmshc, xenon) read that property, while sdhci-pxav3 derives the maximum clock from the io clock rate.
Remove the property.
--- arch/arm/boot/dts/armada-395-gp.dts | 1 - 1 file changed, 1 deletion(-)
arch/arm/boot/dts/armada-395-gp.dts +0 -1
@@ -59,7 +59,6 @@ sata@a8000 { /* CON18 */ sdhci@d8000 { - clock-frequency = <200000000>; broken-cd; wp-inverted; bus-width = <8>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1129/1848 ARM: dts: armada-388-helios4: fix vmmc property name
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 008e9faadef8c0aaa9b8a3ff05a2126e3c5b08b7 ]
The sdhci@d8000 node references the 3.3V regulator through a bare "vmmc" property, which is not part of the mmc controller DT binding. The binding requires supply properties in the form "vmmc-supply", so the current entry is ignored by the driver.
Rename the property to "vmmc-supply" so the fixed regulator is correctly wired up as the card power supply.
--- arch/arm/boot/dts/armada-388-helios4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/armada-388-helios4.dts +1 -1
@@ -269,7 +269,7 @@ sdhci@d8000 { &helios_sdhci_cd_pins>; pinctrl-names = "default"; status = "okay"; - vmmc = <®_3p3v>; + vmmc-supply = <®_3p3v>; wp-inverted; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1130/1848 ARM: dts: helios4: fix vbus-supply for USB2 PHY
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit a132798a133e76a7bb575ba95b2b64eadd245438 ]
The usb-nop-xceiv binding and driver use "vbus-supply"; the driver acquires the VBUS regulator via devm_regulator_get_exclusive("vbus") (phy-generic.c). The stale "vbus-regulator" name is never read by the driver and dtbs_check rejects it as an unknown property. Rename the property so reg_5p0v_usb is honored.
--- arch/arm/boot/dts/armada-388-helios4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/armada-388-helios4.dts +1 -1
@@ -140,7 +140,7 @@ fan2: j17-pwm { usb2_phy: usb2-phy { compatible = "usb-nop-xceiv"; - vbus-regulator = <®_5p0v_usb>; + vbus-supply = <®_5p0v_usb>; }; usb3_phy: usb3-phy {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1131/1848 ARM: dts: helios4: fix spi1 location
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 5df4320a30a87f9bb918ace7b389026917c8d896 ]
This spi node is specified in armada-38x.dtsi with proper compatible strings whereas they are not present here. Instead of copy and pasting various lines, just reference the node in the dtsi.
This dts seems to predate the move of spi from internal-regs to the soc node so this moves it in line there.
Allows proper probing of SPI at runtime.
Remove the microsom_spi1_cs_pins pinctrl group and its reference in &spi1. The group only muxed mpp59 to the "spi1" function, but that pin (SPI1 cs0) is already covered by spi1_pins, which selects the same function for mpp56-59 in armada-38x.dtsi.
--- arch/arm/boot/dts/armada-388-helios4.dts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
arch/arm/boot/dts/armada-388-helios4.dts +6 -11
@@ -254,13 +254,6 @@ sata3: sata-port@1 { }; }; - spi@10680 { - pinctrl-0 = <&spi1_pins - µsom_spi1_cs_pins>; - pinctrl-names = "default"; - status = "okay"; - }; - sdhci@d8000 { bus-width = <4>; cd-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
@@ -327,11 +320,13 @@ helios_fan2_pins: helios_fan2_pins { marvell,pins = "mpp48", "mpp55"; marvell,function = "gpio"; }; - microsom_spi1_cs_pins: spi1-cs-pins { - marvell,pins = "mpp59"; - marvell,function = "spi1"; - }; }; }; }; }; + +&spi1 { + pinctrl-0 = <&spi1_pins>; + pinctrl-names = "default"; + status = "okay"; +};
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1132/1848 kexec_file: stop the top-down search before it underflows
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit c711461303af9f796b293b5ac06f49a885e46e71 ]
locate_mem_hole_top_down() walks candidates downwards by subtracting PAGE_SIZE whenever the window conflicts with an existing segment or with an architecture exclude range.
Nothing stops that subtraction at zero, so a search that reaches the bottom of the address space wraps temp_start around and continues.
The walk starts inside the range being scanned and only moves down, so bail out once a candidate ends up above end. That covers every step in the loop rather than the subtractions alone, and it matches locate_mem_hole_bottom_up(), which already bounds its candidate on both sides.
This is a better check than subtracting with check_sub_overflow(), given that we would have 3 subtractions in this block, and this single fix would take care of them all (instead of three check_sub_overflow()).
--- kernel/kexec_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/kexec_file.c +3 -1
@@ -433,7 +433,9 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end,/* align down start */ temp_start = temp_start & (~(kbuf->buf_align -1 )); -if (temp_start < start || temp_start < kbuf->buf_min) +/* A candidate above the range means the walk wrapped around */ +if (temp_start < start || temp_start < kbuf->buf_min || + temp_start > end)return 0 ; temp_end = temp_start + kbuf->memsz -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1133/1848 perf jitdump: Fix extended header read that always fails
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 598e905931380f0714d5fd50cecfac615a1ec742 ]
jit_open() sets bsz = bs before the fread() that uses bs - bsz as the read size, making the expression always evaluate to zero. fread() with size 0 returns 0, which triggers the ret != 1 error path — so extended jitdump headers (total_size > sizeof(header)) have been silently broken since the original implementation.
Additionally, when 0 < bs <= bsz the if (bs > bsz) block is skipped entirely, leaving extended header bytes unread in the stream. Subsequent jit_get_next_entry() calls then parse those leftover bytes as a jr_prefix, corrupting the record stream.
Fix by separating the buffer growth from the read: realloc only when bs > bsz, then unconditionally fread bs bytes when bs > 0.
--- tools/perf/util/jitdump.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/jitdump.c +5 -3
@@ -217,10 +217,12 @@ jit_open(struct jit_buf_desc *jd, const char *name) n =realloc (buf, bs);if (!n) goto error; - bsz = bs; buf = n; -/* read extra we do not know about */ - ret =fread (buf, bs - bsz,1 , jd->in); + bsz = bs; + } +if (bs >0 ) { +/* consume extended header bytes from the stream */ + ret =fread (buf, bs,1 , jd->in);if (ret !=1 ) goto error; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1134/1848 perf jitdump: Fix debug_data and unwinding_data leaks
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 2bd967f3adcba1d3e54f10b0d8b25f950e4f03fd ]
jit_repipe_debug_info() overwrites jd->debug_data without freeing the previous allocation. If two consecutive JIT_CODE_DEBUG_INFO records appear without an intervening LOAD record consuming the data, the first allocation leaks.
The sibling jit_repipe_unwinding_info() already frees the old jd->unwinding_data before reassignment — add the same pattern to jit_repipe_debug_info() using zfree().
Also add cleanup of both buffers in jit_close() so they are freed when the jitdump session ends, even if no LOAD record consumed them.
--- tools/perf/util/jitdump.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/jitdump.c +3 -0
@@ -113,6 +113,8 @@ jit_close(struct jit_buf_desc *jd)funlockfile (jd->in);fclose (jd->in); jd->in =NULL ; +zfree (&jd->debug_data); +zfree (&jd->unwinding_data); } static int
@@ -620,6 +622,7 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)memcpy (data, &jr->info.entries, sz); +zfree (&jd->debug_data); jd->debug_data = data;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1135/1848 perf jitdump: Validate code_size against total_size in code load
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 06c7cf7a072fcd52e68471628c56630d2bdcc650 ]
jit_repipe_code_load() reads code_size from the jitdump record and uses it to compute a pointer to the code blob:
code = (unsigned long)jr + jr->load.p.total_size - csize;
An oversized code_size underflows the pointer arithmetic, causing OOB reads into earlier heap memory. Validate that code_size fits within the record (total_size - sizeof(jr->load)) before the pointer computation.
code_size is uint64_t but csize is int; values above INT_MAX wrap negative when narrowed into csize, which defeats the bounds check and sends the code pointer past the end of the record. Reject those too.
--- tools/perf/util/jitdump.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/perf/util/jitdump.c +11 -0
@@ -9,6 +9,7 @@#include <fcntl.h> #include <unistd.h> #include <inttypes.h> +#include <limits.h> #include <byteswap.h> #include <sys/stat.h> #include <sys/mman.h>
@@ -427,6 +428,16 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) csize = jr->load.code_size; usize = jd->unwinding_mapped_size; addr = jr->load.code_addr; + +/* code blob lives at the end of the record, validate it fits */ +if (jr->load.p.total_size <sizeof (jr->load) || + jr->load.code_size > jr->load.p.total_size -sizeof (jr->load) || + jr->load.code_size >INT_MAX ) { +pr_warning ("jitdump: invalid code_size %" PRIu64" (total_size=%u) in code_load record\n" , + (uint64_t )jr->load.code_size, jr->load.p.total_size); +return -1 ; + } + sym = (void *)((unsigned long )jr +sizeof (jr->load)); code = (unsigned long )jr + jr->load.p.total_size - csize; count = jr->load.code_index;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1136/1848 perf jitdump: Prevent integer underflow in debug info size calculation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit dfe8fe96efca3c32979dc0859f88e15b677d25f1 ]
jit_repipe_debug_info() and jit_repipe_unwinding_info() compute payload sizes by subtracting the fixed header size from total_size:
sz = jr->prefix.total_size - sizeof(jr->info);
When total_size is smaller than the header struct (from a truncated or corrupted jitdump record), the subtraction underflows to a massive value, causing an oversized allocation followed by an OOB memcpy.
Validate that total_size covers at least the fixed header before the subtraction in both functions.
--- tools/perf/util/jitdump.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/jitdump.c +8 -0
@@ -626,6 +626,10 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)if (!(jd && jr))return -1 ; +/* total_size must cover at least the fixed header */ +if (jr->prefix.total_size <sizeof (jr->info)) +return -1 ; + sz = jr->prefix.total_size -sizeof (jr->info); data =malloc (sz);if (!data)
@@ -654,6 +658,10 @@ jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)if (!(jd && jr))return -1 ; +/* total_size must cover at least the fixed header */ +if (jr->prefix.total_size <sizeof (jr->unwinding)) +return -1 ; + unwinding_data_size = jr->prefix.total_size -sizeof (jr->unwinding); unwinding_data =malloc (unwinding_data_size);if (!unwinding_data)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1137/1848 perf jitdump: Bounds-check debug entry byte-swap loop
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit ede3cd8151675c2983cd49104b1e9b25a3712ed8 ]
The byte-swap loop for JIT_CODE_DEBUG_INFO uses array indexing (jr->info.entries[n]) to iterate debug entries. struct debug_entry has a flexible array member name[], so each entry has a different size. Array indexing computes offsets assuming fixed-size elements, landing inside variable-length name strings after the first entry and byte-swapping garbage.
Additionally, nr_entry is read from untrusted jitdump input without validation against total_size, so a crafted value causes OOB reads.
Replace the array indexing with debug_entry_next() pointer arithmetic (which correctly accounts for the variable-length name) and bounds-check each entry against the record's total_size before byte-swapping.
--- tools/perf/util/jitdump.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
tools/perf/util/jitdump.c +22 -4
@@ -310,14 +310,32 @@ jit_get_next_entry(struct jit_buf_desc *jd)switch (id) {case JIT_CODE_DEBUG_INFO :if (jd->needs_bswap) { +void *end = (void *)jr + jr->prefix.total_size; +struct debug_entry *ent;uint64_t n; + jr->info.code_addr =bswap_64 (jr->info.code_addr); jr->info.nr_entry =bswap_64 (jr->info.nr_entry); -for (n =0 ; n < jr->info.nr_entry; n++) { - jr->info.entries[n].addr =bswap_64 (jr->info.entries[n].addr); - jr->info.entries[n].lineno =bswap_32 (jr->info.entries[n].lineno); - jr->info.entries[n].discrim =bswap_32 (jr->info.entries[n].discrim); + +/* +* debug_entry has a variable-length name[], so array +* indexing would compute wrong offsets — use +* debug_entry_next() and bounds-check each entry. +*/ + ent = &jr->info.entries[0 ]; +for (n =0 ; n < jr->info.nr_entry; n++) { +if ((void *)ent +sizeof (*ent) > end) +break ; +/* name must be NUL-terminated within the record */ +if (!memchr (ent->name,'\0' , (char *)end - ent->name)) +break ; + ent->addr =bswap_64 (ent->addr); + ent->lineno =bswap_32 (ent->lineno); + ent->discrim =bswap_32 (ent->discrim); + ent =debug_entry_next (ent); } +/* clamp so downstream consumers don't overrun */ + jr->info.nr_entry = n; }break ;case JIT_CODE_UNWINDING_INFO :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1138/1848 perf jitdump: Check snprintf return before computing header size
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 0155f05ea6e133c18a04b8b5945cac59870da156 ]
snprintf() returns the would-have-been length on truncation. When the jitted filename exceeds PATH_MAX, the unclamped 'size' value inflates sizeof(event->mmap2.filename) - size into a massive underflow, causing the header.size computation to write an oversized header. The subsequent write to 'id = event + header.size - idr_size' then corrupts the heap.
Clamp size to PATH_MAX - 1 after snprintf in both jit_repipe_code_load() and jit_repipe_code_move().
--- tools/perf/util/jitdump.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/jitdump.c +6 -0
@@ -470,6 +470,9 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) jd->dir, pid, count); +/* snprintf returns would-be length on truncation, clamp to buffer */ +if (size >=sizeof (event->mmap2.filename)) + size =sizeof (event->mmap2.filename) -1 ; size++;/* for \0 */
@@ -581,6 +584,9 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr) jd->dir, pid, jr->move.code_index); +/* snprintf returns would-be length on truncation, clamp to buffer */ +if (size >=sizeof (event->mmap2.filename)) + size =sizeof (event->mmap2.filename) -1 ; size++;/* for \0 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1139/1848 perf jitdump: Fix funlockfile on unlocked stream in jit_open() error path
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit bfde6848c1e24fd979d0138c57c1cc28c35093c3 ]
If the malloc() for the initial read buffer fails, jit_open() jumps to the error label which calls funlockfile(jd->in). However, flockfile() is called later in the function, so at this point the stream was never locked. Calling funlockfile() on an unlocked stream is undefined behavior per POSIX.
Split the error path into two labels: 'error' (after flockfile) calls funlockfile before cleanup, 'error_noflock' (before flockfile) skips the unlock.
--- tools/perf/util/jitdump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/jitdump.c +3 -1
@@ -150,7 +150,7 @@ jit_open(struct jit_buf_desc *jd, const char *name) buf =malloc (bsz);if (!buf) - goto error; + goto error_noflock;/* * protect from writer modifying the file while we are reading it
@@ -238,6 +238,8 @@ jit_open(struct jit_buf_desc *jd, const char *name)return 0 ; error:funlockfile (jd->in); +error_noflock: +free (buf);fclose (jd->in);return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1140/1848 perf inject jit: Add namespaces support
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yonatan Goldschmidt <[email protected]>
[ Upstream commit 67dec926931448d688efb5fe34f7b5a22470fc0a ]
This patch fixes "perf inject --jit" to properly operate on namespaced/containerized processes:
* jitdump files are generated by the process, thus they should be looked up in its mount NS.
* DSOs of injected MMAP events will later be looked up in the process mount NS, so write them into its NS.
* PIDs & TIDs from jitdump events need to be translated to the PID as seen by "perf record" before written into MMAP events.
For a process in a different PID NS, the TID & PID given in the jitdump event are actually ignored; I use the TID & PID of the thread which mmap()ed the jitdump file. This is simplified and won't do for forks of the initial process, if they continue using the same jitdump file. Future patches might improve it.
This was tested by recording a NodeJS process running with "--perf-prof", inside a Docker container, and by recording another NodeJS process running in the same namespaces as perf itself, to make sure it's not broken for non-containerized processes.
Stable-dep-of: 4eddf7d9e341 ("perf jitdump: Use dirname() return value in jit_open()")
--- tools/perf/builtin-inject.c | 4 +- tools/perf/util/jit.h | 2 +- tools/perf/util/jitdump.c | 84 ++++++++++++++++++++++++++++-------- tools/perf/util/namespaces.c | 12 ++++++ tools/perf/util/namespaces.h | 2 + 5 files changed, 82 insertions(+), 22 deletions(-)
tools/perf/builtin-inject.c +2 -2
@@ -313,7 +313,7 @@ static int perf_event__jit_repipe_mmap(struct perf_tool *tool,* if jit marker, then inject jit mmaps and generate ELF images */ ret =jit_process (inject->session, &inject->output, machine, - event->mmap.filename, event->mmap.pid, &n); + event->mmap.filename, event->mmap.pid, event->mmap.tid, &n);if (ret <0 )return ret;if (ret) {
@@ -414,7 +414,7 @@ static int perf_event__jit_repipe_mmap2(struct perf_tool *tool,* if jit marker, then inject jit mmaps and generate ELF images */ ret =jit_process (inject->session, &inject->output, machine, - event->mmap2.filename, event->mmap2.pid, &n); + event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n);if (ret <0 )return ret;if (ret) {
tools/perf/util/jit.h +1 -1
@@ -5,7 +5,7 @@#include <data.h> int jit_process (struct perf_session *session,struct perf_data *output, -struct machine *machine,char *filename,pid_t pid,u64 *nbytes); +struct machine *machine,char *filename,pid_t pid,pid_t tid,u64 *nbytes);int jit_inject_record (const char *filename);
tools/perf/util/jitdump.c +65 -19
228 lines not on this page · raw message
tools/perf/util/namespaces.c +12 -0
@@ -280,3 +280,15 @@ char *nsinfo__realpath(const char *path, struct nsinfo *nsi)return rpath; } + +int nsinfo__stat (const char *filename,struct stat *st,struct nsinfo *nsi) +{ +int ret; +struct nscookie nsc; + +nsinfo__mountns_enter (nsi, &nsc); + ret =stat (filename, st); +nsinfo__mountns_exit (&nsc); + +return ret; +}
tools/perf/util/namespaces.h +2 -0
@@ -8,6 +8,7 @@#define __PERF_NAMESPACES_H#include <sys/types.h> +#include <sys/stat.h> #include <linux/stddef.h> #include <linux/perf_event.h> #include <linux/refcount.h>
@@ -55,6 +56,7 @@ void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc);void nsinfo__mountns_exit (struct nscookie *nc);char *nsinfo__realpath (const char *path,struct nsinfo *nsi); +int nsinfo__stat (const char *filename,struct stat *st,struct nsinfo *nsi);static inline void __nsinfo__zput (struct nsinfo **nsip) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1141/1848 perf jit: Fix a few memory leaks
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit dc67c7837a832952459c4f7829e89b9d8d15f420 ]
As reported by leak sanitizer.
Stable-dep-of: 4eddf7d9e341 ("perf jitdump: Use dirname() return value in jit_open()")
--- tools/perf/util/genelf_debug.c | 45 +++++++++++++++++++++------------- tools/perf/util/jitdump.c | 7 +++++- 2 files changed, 34 insertions(+), 18 deletions(-)
tools/perf/util/genelf_debug.c +28 -17
@@ -87,6 +87,12 @@ buffer_ext_init(struct buffer_ext *be) be->max_sz =0 ; } +static void +buffer_ext_exit (struct buffer_ext *be) +{ +free (be->data); +} +static inline size_t buffer_ext_size (struct buffer_ext *be) {
@@ -487,28 +493,28 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entriesElf_Scn *scn;Elf_Shdr *shdr;struct buffer_ext dl, di, da; -int ret; +int ret =-1 ;buffer_ext_init (&dl);buffer_ext_init (&di);buffer_ext_init (&da); - ret =jit_process_debug_info (code_addr, debug, nr_debug_entries, &dl, &da, &di); -if (ret) -return -1 ; +if (jit_process_debug_info (code_addr, debug, nr_debug_entries, &dl, &da, &di)) + goto out; +/* * setup .debug_line section */ scn =elf_newscn (e);if (!scn) {warnx ("cannot create section" ); -return -1 ; + goto out; } d =elf_newdata (scn);if (!d) {warnx ("cannot get new data" ); -return -1 ; + goto out; } d->d_align =1 ;
@@ -521,7 +527,7 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries shdr =elf_getshdr (scn);if (!shdr) {warnx ("cannot get section header" ); -return -1 ; + goto out; } shdr->sh_name =52 ;/* .debug_line */
@@ -536,13 +542,13 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries scn =elf_newscn (e);if (!scn) {warnx ("cannot create section" ); -return -1 ; + goto out; } d =elf_newdata (scn);if (!d) {warnx ("cannot get new data" ); -return -1 ; + goto out; } d->d_align =1 ;
@@ -555,7 +561,7 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries shdr =elf_getshdr (scn);if (!shdr) {warnx ("cannot get section header" ); -return -1 ; + goto out; } shdr->sh_name =64 ;/* .debug_info */
@@ -570,13 +576,13 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries scn =elf_newscn (e);if (!scn) {warnx ("cannot create section" ); -return -1 ; + goto out; } d =elf_newdata (scn);if (!d) {warnx ("cannot get new data" ); -return -1 ; + goto out; } d->d_align =1 ;
@@ -589,7 +595,7 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries shdr =elf_getshdr (scn);if (!shdr) {warnx ("cannot get section header" ); -return -1 ; + goto out; } shdr->sh_name =76 ;/* .debug_info */
@@ -601,9 +607,14 @@ jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries/* * now we update the ELF image with all the sections */ -if (elf_update (e,ELF_C_WRITE ) <0 ) { +if (elf_update (e,ELF_C_WRITE ) <0 )warnx ("elf_update debug failed" ); -return -1 ; - } -return 0 ; +else + ret =0 ; + +out: +buffer_ext_exit (&dl); +buffer_ext_exit (&di); +buffer_ext_exit (&da); +return ret; }
tools/perf/util/jitdump.c +6 -1
@@ -247,9 +247,11 @@ jit_open(struct jit_buf_desc *jd, const char *name)*/ strcpy (jd->dir, name);dirname (jd->dir); +free (buf);return 0 ; error: +free (buf);funlockfile (jd->in); error_noflock:free (buf);
@@ -568,7 +570,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) ret =perf_event__process_mmap2 (tool, event, &sample, jd->machine);if (ret) -return ret; + goto out; ret =jit_inject_event (jd, event);/*
@@ -577,6 +579,8 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)if (!ret)build_id__mark_dso_hit (tool, event, &sample,NULL , jd->machine); +out: +free (event);return ret; }
@@ -926,6 +930,7 @@ jit_process(struct perf_session *session, }nsinfo__put (jd.nsi); +free (jd.buf);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1142/1848 perf: replace strcpy() with strncpy() in util/jitdump.c
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hrishikesh Suresh <[email protected]>
[ Upstream commit 9bef5cead63d5d8fad3ba7ebaf26f3f4ee172c82 ]
Usage of strcpy() can lead to buffer overflows. Therefore, it has been replaced with strncpy(). The output file path is provided as a parameter and might be restricted by command-line by default. But this defensive patch will prevent any potential overflow, making the code more robust against future changes in input handling.
Testing:
- ran perf test from tools/perf and did not observe any regression with the earlier code
Stable-dep-of: 4eddf7d9e341 ("perf jitdump: Use dirname() return value in jit_open()")
--- tools/perf/util/jitdump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/jitdump.c +2 -1
@@ -245,7 +245,8 @@ jit_open(struct jit_buf_desc *jd, const char *name)/* * keep dirname for generating files and mmap records */ -strcpy (jd->dir, name); +strncpy (jd->dir, name,PATH_MAX ); + jd->dir[PATH_MAX -1 ] ='\0' ;dirname (jd->dir);free (buf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1143/1848 perf jitdump: Use dirname() return value in jit_open()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 4eddf7d9e341eb8c41704b8aa27b4a91f4e2c7c9 ]
jit_open() calls dirname(jd->dir) but ignores the return value. POSIX says dirname() may return a pointer to internal static storage — glibc does this when the path has no '/', returning "." from a static buffer and leaving jd->dir unchanged with the original filename.
Capture the return value and copy it back to jd->dir when dirname() returns a different pointer.
--- tools/perf/util/jitdump.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/jitdump.c +4 -1
@@ -152,6 +152,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)ssize_t bs, bsz =0 ;void *n, *buf =NULL ;int ret, retval =-1 ; +char *dname;nsinfo__mountns_enter (jd->nsi, &nsc); jd->in =fopen (name,"r" );
@@ -247,7 +248,9 @@ jit_open(struct jit_buf_desc *jd, const char *name)*/ strncpy (jd->dir, name,PATH_MAX ); jd->dir[PATH_MAX -1 ] ='\0' ; -dirname (jd->dir); + dname =dirname (jd->dir); +if (dname != jd->dir) +strlcpy (jd->dir, dname,sizeof (jd->dir));free (buf);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1144/1848 perf jitdump: Validate debug entries on native (non-swap) path
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 51e14e495f0cea061bbad33e7635f7fd857113ad ]
The bounds-checking and nr_entry clamping added for the byte-swap path only runs when jd->needs_bswap is true. On native-endian files, nr_entry passes through unvalidated to jit_repipe_debug_info(), which stores it as jd->nr_debug_entries. Downstream, jit_process_debug_info() in genelf_debug.c iterates nr_debug_entries times via debug_entry_next(), which calls strlen() on each entry's name field — a crafted nr_entry causes OOB reads and writes.
Add bounds-checked iteration in jit_repipe_debug_info() that validates each debug_entry fits in the payload and its name is NUL-terminated before calling debug_entry_next(). Clamp nr_debug_entries to the count of valid entries.
--- tools/perf/util/jitdump.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
tools/perf/util/jitdump.c +22 -5
@@ -683,8 +683,10 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)static int jit_repipe_debug_info (struct jit_buf_desc *jd,union jr_entry *jr) { -void *data; -size_t sz; +struct debug_entry *ent; +void *data, *end; +size_t sz, valid; +uint64_t i;if (!(jd && jr))return -1 ;
@@ -704,10 +706,25 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr) jd->debug_data = data;/* -* we must use nr_entry instead of size here because -* we cannot distinguish actual entry from padding otherwise +* Clamp nr_debug_entries to entries that actually fit in the +* payload. The byte-swap path already does this for cross-endian +* files; validate on the native path too, since downstream +* jit_process_debug_info() iterates via debug_entry_next() which +* calls strlen() on each entry's name field. */ - jd->nr_debug_entries = jr->info.nr_entry; + end = data + sz; + ent = data; + valid =0 ; +for (i =0 ; i < jr->info.nr_entry; i++) { +if ((void *)ent +sizeof (*ent) > end) +break ; +/* name must be NUL-terminated within the payload */ +if (!memchr (ent->name,'\0' , (char *)end - ent->name)) +break ; + ent =debug_entry_next (ent); + valid++; + } + jd->nr_debug_entries = valid;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1145/1848 perf jitdump: Validate sym string NUL-termination in code load
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 98bfe1142ccbaa5ffdca5dcdddd26f238ad33585 ]
jit_repipe_code_load() computes sym = (void *)jr + sizeof(jr->load) and passes it to jit_emit_elf() which calls strlen(sym) via jit_write_elf(). If code_size equals total_size - sizeof(jr->load), the sym pointer aliases the code blob with no NUL terminator, and strlen() scans past the buffer into adjacent heap memory.
Add a memchr() check to verify the symbol name is NUL-terminated within the region between the load header and the code blob before use.
--- tools/perf/util/jitdump.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/util/jitdump.c +7 -0
@@ -494,6 +494,13 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) sym = (void *)((unsigned long )jr +sizeof (jr->load)); code = (unsigned long )jr + jr->load.p.total_size - csize; + +/* sym string lives between the load header and the code blob */ +if (!memchr (sym,'\0' , code - (unsigned long )sym)) { +pr_warning ("jitdump: unterminated symbol name in code_load record\n" ); +return -1 ; + } + count = jr->load.code_index; idr_size = jd->machine->id_hdr_size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1146/1848 perf jitdump: Validate unwinding sizes against record payload
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 92d50319b4f0c0bbee8a236a09063272cd22faab ]
jit_repipe_unwinding_info() copies unwinding_size and eh_frame_hdr_size from the jitdump record into jd-> fields without checking them against the actual payload size. Downstream, jit_add_eh_frame_info() in genelf.c computes unwinding_table_size = unwinding_size - eh_frame_hdr_size, which underflows when eh_frame_hdr_size > unwinding_size. The result is passed as d->d_size to libelf, causing an OOB heap read into the output ELF file.
Validate that unwinding_size fits within the record payload and that eh_frame_hdr_size does not exceed unwinding_size before allocating or storing the values, so a bogus record cannot force a large allocation that is then discarded.
mapped_size is likewise taken from the record and was narrowed into an int for the mmap2 len computation in jit_repipe_code_load() and jit_repipe_code_move(); values above INT_MAX would turn negative, producing a wrong mmap2 length. Use uint64_t for usize so the value cannot truncate.
--- tools/perf/util/jitdump.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
tools/perf/util/jitdump.c +16 -3
@@ -469,7 +469,8 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)u16 idr_size;const char *sym;uint64_t count; -int ret, csize, usize; +int ret, csize; +uint64_t usize;pid_t nspid, pid, tid;struct {u32 pid, tid;
@@ -550,7 +551,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) event->mmap2.pgoff =GEN_ELF_TEXT_OFFSET ; event->mmap2.start = addr; - event->mmap2.len = usize ?ALIGN_8 (csize) + usize : csize; + event->mmap2.len = usize ?ALIGN_8 ((uint64_t )csize) + usize : (uint64_t )csize; event->mmap2.pid = pid; event->mmap2.tid = tid; event->mmap2.ino = st.st_ino;
@@ -603,7 +604,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)char *filename;size_t size;struct stat st; -int usize; +uint64_t usize;u16 idr_size;int ret;pid_t nspid, pid, tid;
@@ -750,6 +751,18 @@ jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)return -1 ; unwinding_data_size = jr->prefix.total_size -sizeof (jr->unwinding); + +/* +* Validate sizes before allocating — jit_add_eh_frame_info() +* computes unwinding_size - eh_frame_hdr_size and uses the +* result as a buffer length for libelf. +*/ +if (jr->unwinding.unwinding_size > unwinding_data_size || + jr->unwinding.eh_frame_hdr_size > jr->unwinding.unwinding_size) { +pr_warning ("jitdump: invalid unwinding sizes in unwinding_info record\n" ); +return -1 ; + } + unwinding_data =malloc (unwinding_data_size);if (!unwinding_data)return -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1147/1848 remoteproc: qcom_q6v5_adsp: Fix double jiffies conversion in adsp_start()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anup Vishwakarma <[email protected]>
[ Upstream commit f559ef6316971fe39dc5f5edd6a483429ba03768 ]
adsp_start() computes 5 * HZ, an already-converted jiffies count, and passes it into msecs_to_jiffies(), which expects milliseconds -- reinterpreting the value and shrinking the intended timeout. Every other caller (q6v5_start() in qcom_q6v5_mss.c, qcom_pas_start() in qcom_q6v5_pas.c) passes msecs_to_jiffies(5000) directly, matching qcom_q6v5_wait_for_start()'s kerneldoc, which documents @timeout as already being in jiffies.
On CONFIG_HZ=250 this shrinks the intended 5 second timeout to ~1.25 seconds, causing a DSP that legitimately takes 2-3 seconds to signal ready to be spuriously torn down as a boot failure.
Fix by passing msecs_to_jiffies(5000) directly, matching every other caller.
--- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_adsp.c +1 -1
@@ -230,7 +230,7 @@ static int adsp_start(struct rproc *rproc) goto disable_adsp_clks; } - ret =qcom_q6v5_wait_for_start (&adsp->q6v5,msecs_to_jiffies (5 *HZ )); + ret =qcom_q6v5_wait_for_start (&adsp->q6v5,msecs_to_jiffies (5000 ));if (ret == -ETIMEDOUT ) {dev_err (adsp->dev,"start timed out\n" ); goto disable_adsp_clks;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1148/1848 pwm: renesas-tpu: Implement .apply() callback
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit ec00cd5e63f05461ab48128775c73c851c3c2b18 ]
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply().
As pwm->state might not be updated in tpu_pwm_apply() before calling tpu_pwm_config(), an additional parameter is needed for tpu_pwm_config() to not change the implemented logic.
Stable-dep-of: 62cff15fbf2b ("pwm: renesas-tpu: Fix runtime PM reference leak")
--- drivers/pwm/pwm-renesas-tpu.c | 44 ++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-)
drivers/pwm/pwm-renesas-tpu.c +38 -6
@@ -242,7 +242,7 @@ static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *_pwm) }static int tpu_pwm_config (struct pwm_chip *chip,struct pwm_device *_pwm, -int duty_ns,int period_ns) +int duty_ns,int period_ns,bool enabled) {static const unsigned int prescalers[] = {1 ,4 ,16 ,64 };struct tpu_pwm_device *pwm =pwm_get_chip_data (_pwm);
@@ -293,7 +293,7 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm, pwm->duty = duty;/* If the channel is disabled we're done. */ -if (!pwm_is_enabled (_pwm)) +if (!enabled)return 0 ;if (duty_only && pwm->timer_on) {
@@ -366,13 +366,45 @@ static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *_pwm)tpu_pwm_timer_stop (pwm); } +static int tpu_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) +{ +int err; +bool enabled = pwm->state.enabled; + +if (state->polarity != pwm->state.polarity) { +if (enabled) { +tpu_pwm_disable (chip, pwm); + enabled = false; + } + + err =tpu_pwm_set_polarity (chip, pwm, state->polarity); +if (err) +return err; + } + +if (!state->enabled) { +if (enabled) +tpu_pwm_disable (chip, pwm); + +return 0 ; + } + + err =tpu_pwm_config (pwm->chip, pwm, + state->duty_cycle, state->period, enabled); +if (err) +return err; + +if (!enabled) + err =tpu_pwm_enable (chip, pwm); + +return err; +} +static const struct pwm_ops tpu_pwm_ops = { .request = tpu_pwm_request, .free = tpu_pwm_free, - .config = tpu_pwm_config, - .set_polarity = tpu_pwm_set_polarity, - .enable = tpu_pwm_enable, - .disable = tpu_pwm_disable, + .apply = tpu_pwm_apply, .owner =THIS_MODULE , };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1149/1848 pwm: renesas-tpu: Rename variables to match the usual naming
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 208ab8676b9c787b4285364fcb52a159f94b861d ]
The driver used "pwm" for struct tpu_pwm_device pointers. This name is usually only used for struct pwm_device pointers which this driver calls "_pwm". So rename to the driver data pointers to "tpd" which then allows to drop the underscore from "_pwm".
Stable-dep-of: 62cff15fbf2b ("pwm: renesas-tpu: Fix runtime PM reference leak")
--- drivers/pwm/pwm-renesas-tpu.c | 172 +++++++++++++++++----------------- 1 file changed, 86 insertions(+), 86 deletions(-)
drivers/pwm/pwm-renesas-tpu.c +86 -86
@@ -89,71 +89,71 @@ struct tpu_device {#define to_tpu_device (c) container_of(c, struct tpu_device, chip) -static void tpu_pwm_write (struct tpu_pwm_device *pwm,int reg_nr,u16 value) +static void tpu_pwm_write (struct tpu_pwm_device *tpd,int reg_nr,u16 value) { -void __iomem *base = pwm->tpu->base +TPU_CHANNEL_OFFSET - + pwm->channel *TPU_CHANNEL_SIZE ; +void __iomem *base = tpd->tpu->base +TPU_CHANNEL_OFFSET + + tpd->channel *TPU_CHANNEL_SIZE ;iowrite16 (value, base + reg_nr); } -static void tpu_pwm_set_pin (struct tpu_pwm_device *pwm, +static void tpu_pwm_set_pin (struct tpu_pwm_device *tpd,enum tpu_pin_state state) {static const char *const states[] = {"inactive" ,"PWM" ,"active" }; -dev_dbg (&pwm->tpu->pdev->dev,"%u: configuring pin as %s\n" , - pwm->channel, states[state]); +dev_dbg (&tpd->tpu->pdev->dev,"%u: configuring pin as %s\n" , + tpd->channel, states[state]);switch (state) {case TPU_PIN_INACTIVE : -tpu_pwm_write (pwm, TPU_TIORn, - pwm->polarity ==PWM_POLARITY_INVERSED ? +tpu_pwm_write (tpd, TPU_TIORn, + tpd->polarity ==PWM_POLARITY_INVERSED ?TPU_TIOR_IOA_1 :TPU_TIOR_IOA_0 );break ;case TPU_PIN_PWM : -tpu_pwm_write (pwm, TPU_TIORn, - pwm->polarity ==PWM_POLARITY_INVERSED ? +tpu_pwm_write (tpd, TPU_TIORn, + tpd->polarity ==PWM_POLARITY_INVERSED ?TPU_TIOR_IOA_0_SET :TPU_TIOR_IOA_1_CLR );break ;case TPU_PIN_ACTIVE : -tpu_pwm_write (pwm, TPU_TIORn, - pwm->polarity ==PWM_POLARITY_INVERSED ? +tpu_pwm_write (tpd, TPU_TIORn, + tpd->polarity ==PWM_POLARITY_INVERSED ?TPU_TIOR_IOA_0 :TPU_TIOR_IOA_1 );break ; } } -static void tpu_pwm_start_stop (struct tpu_pwm_device *pwm,int start) +static void tpu_pwm_start_stop (struct tpu_pwm_device *tpd,int start) {unsigned long flags;u16 value; -spin_lock_irqsave (&pwm->tpu->lock, flags); - value =ioread16 (pwm->tpu->base +TPU_TSTR ); +spin_lock_irqsave (&tpd->tpu->lock, flags); + value =ioread16 (tpd->tpu->base +TPU_TSTR );if (start) - value |=1 << pwm->channel; + value |=1 << tpd->channel;else - value &= ~(1 << pwm->channel); + value &= ~(1 << tpd->channel); -iowrite16 (value, pwm->tpu->base +TPU_TSTR ); -spin_unlock_irqrestore (&pwm->tpu->lock, flags); +iowrite16 (value, tpd->tpu->base +TPU_TSTR ); +spin_unlock_irqrestore (&tpd->tpu->lock, flags); } -static int tpu_pwm_timer_start (struct tpu_pwm_device *pwm) +static int tpu_pwm_timer_start (struct tpu_pwm_device *tpd) {int ret; -if (!pwm->timer_on) { +if (!tpd->timer_on) {/* Wake up device and enable clock. */ -pm_runtime_get_sync (&pwm->tpu->pdev->dev); - ret =clk_prepare_enable (pwm->tpu->clk); +pm_runtime_get_sync (&tpd->tpu->pdev->dev); + ret =clk_prepare_enable (tpd->tpu->clk);if (ret) { -dev_err (&pwm->tpu->pdev->dev,"cannot enable clock\n" ); +dev_err (&tpd->tpu->pdev->dev,"cannot enable clock\n" );return ret; } - pwm->timer_on = true; + tpd->timer_on = true; }/*
@@ -161,8 +161,8 @@ static int tpu_pwm_timer_start(struct tpu_pwm_device *pwm)* completely. First drive the pin to the inactive state to avoid * glitches. */ -tpu_pwm_set_pin (pwm,TPU_PIN_INACTIVE ); -tpu_pwm_start_stop (pwm, false); +tpu_pwm_set_pin (tpd,TPU_PIN_INACTIVE ); +tpu_pwm_start_stop (tpd, false);/* * - Clear TCNT on TGRB match
@@ -172,80 +172,80 @@ static int tpu_pwm_timer_start(struct tpu_pwm_device *pwm)* - Output 1 until TGRA, output 0 until TGRB (active high polarity * - PWM mode */ -tpu_pwm_write (pwm, TPU_TCRn,TPU_TCR_CCLR_TGRB |TPU_TCR_CKEG_RISING | - pwm->prescaler); -tpu_pwm_write (pwm, TPU_TMDRn,TPU_TMDR_MD_PWM ); -tpu_pwm_set_pin (pwm,TPU_PIN_PWM ); -tpu_pwm_write (pwm, TPU_TGRAn, pwm->duty); -tpu_pwm_write (pwm, TPU_TGRBn, pwm->period); +tpu_pwm_write (tpd, TPU_TCRn,TPU_TCR_CCLR_TGRB |TPU_TCR_CKEG_RISING | + tpd->prescaler); +tpu_pwm_write (tpd, TPU_TMDRn,TPU_TMDR_MD_PWM ); +tpu_pwm_set_pin (tpd,TPU_PIN_PWM ); +tpu_pwm_write (tpd, TPU_TGRAn, tpd->duty); +tpu_pwm_write (tpd, TPU_TGRBn, tpd->period); -dev_dbg (&pwm->tpu->pdev->dev,"%u: TGRA 0x%04x TGRB 0x%04x\n" , - pwm->channel, pwm->duty, pwm->period); +dev_dbg (&tpd->tpu->pdev->dev,"%u: TGRA 0x%04x TGRB 0x%04x\n" , + tpd->channel, tpd->duty, tpd->period);/* Start the channel. */ -tpu_pwm_start_stop (pwm, true); +tpu_pwm_start_stop (tpd, true);return 0 ; } -static void tpu_pwm_timer_stop (struct tpu_pwm_device *pwm) +static void tpu_pwm_timer_stop (struct tpu_pwm_device *tpd) { -if (!pwm->timer_on) +if (!tpd->timer_on)return ;/* Disable channel. */ -tpu_pwm_start_stop (pwm, false); +tpu_pwm_start_stop (tpd, false);/* Stop clock and mark device as idle. */ -clk_disable_unprepare (pwm->tpu->clk); -pm_runtime_put (&pwm->tpu->pdev->dev); +clk_disable_unprepare (tpd->tpu->clk); +pm_runtime_put (&tpd->tpu->pdev->dev); - pwm->timer_on = false; + tpd->timer_on = false; }/* ----------------------------------------------------------------------------- * PWM API */ -static int tpu_pwm_request (struct pwm_chip *chip,struct pwm_device *_pwm) +static int tpu_pwm_request (struct pwm_chip *chip,struct pwm_device *pwm) {struct tpu_device *tpu =to_tpu_device (chip); -struct tpu_pwm_device *pwm; +struct tpu_pwm_device *tpd; -if (_pwm->hwpwm >=TPU_CHANNEL_MAX ) +if (pwm->hwpwm >=TPU_CHANNEL_MAX )return -EINVAL ; - pwm =kzalloc (sizeof (*pwm),GFP_KERNEL ); -if (pwm ==NULL ) + tpd =kzalloc (sizeof (*tpd),GFP_KERNEL ); +if (tpd ==NULL )return -ENOMEM ; - pwm->tpu = tpu; - pwm->channel = _pwm->hwpwm; - pwm->polarity =PWM_POLARITY_NORMAL ; - pwm->prescaler =0 ; - pwm->period =0 ; - pwm->duty =0 ; + tpd->tpu = tpu; + tpd->channel = pwm->hwpwm; + tpd->polarity =PWM_POLARITY_NORMAL ; + tpd->prescaler =0 ; + tpd->period =0 ; + tpd->duty =0 ; - pwm->timer_on = false; + tpd->timer_on = false; -pwm_set_chip_data (_pwm, pwm); +pwm_set_chip_data (pwm, tpd);return 0 ; } -static void tpu_pwm_free (struct pwm_chip *chip,struct pwm_device *_pwm) +static void tpu_pwm_free (struct pwm_chip *chip,struct pwm_device *pwm) { -struct tpu_pwm_device *pwm =pwm_get_chip_data (_pwm); +struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm); -tpu_pwm_timer_stop (pwm); -kfree (pwm); +tpu_pwm_timer_stop (tpd); +kfree (tpd); } -static int tpu_pwm_config (struct pwm_chip *chip,struct pwm_device *_pwm, +static int tpu_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm,int duty_ns,int period_ns,bool enabled) {static const unsigned int prescalers[] = {1 ,4 ,16 ,64 }; -struct tpu_pwm_device *pwm =pwm_get_chip_data (_pwm); +struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm);struct tpu_device *tpu =to_tpu_device (chip);unsigned int prescaler;bool duty_only = false;
@@ -285,29 +285,29 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,"rate %u, prescaler %u, period %u, duty %u\n" , clk_rate, prescalers[prescaler], period, duty); -if (pwm->prescaler == prescaler && pwm->period == period) +if (tpd->prescaler == prescaler && tpd->period == period) duty_only = true; - pwm->prescaler = prescaler; - pwm->period = period; - pwm->duty = duty; + tpd->prescaler = prescaler; + tpd->period = period; + tpd->duty = duty;/* If the channel is disabled we're done. */ if (!enabled)return 0 ; -if (duty_only && pwm->timer_on) { +if (duty_only && tpd->timer_on) {/* * If only the duty cycle changed and the timer is already * running, there's no need to reconfigure it completely, Just * modify the duty cycle. */ -tpu_pwm_write (pwm, TPU_TGRAn, pwm->duty); -dev_dbg (&tpu->pdev->dev,"%u: TGRA 0x%04x\n" , pwm->channel, - pwm->duty); +tpu_pwm_write (tpd, TPU_TGRAn, tpd->duty); +dev_dbg (&tpu->pdev->dev,"%u: TGRA 0x%04x\n" , tpd->channel, + tpd->duty); }else {/* Otherwise perform a full reconfiguration. */ - ret =tpu_pwm_timer_start (pwm); + ret =tpu_pwm_timer_start (tpd);if (ret <0 )return ret; }
@@ -317,29 +317,29 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,* To avoid running the timer when not strictly required, handle * 0% and 100% duty cycles as fixed levels and stop the timer. */ -tpu_pwm_set_pin (pwm, duty ?TPU_PIN_ACTIVE :TPU_PIN_INACTIVE ); -tpu_pwm_timer_stop (pwm); +tpu_pwm_set_pin (tpd, duty ?TPU_PIN_ACTIVE :TPU_PIN_INACTIVE ); +tpu_pwm_timer_stop (tpd); }return 0 ; } -static int tpu_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *_pwm, +static int tpu_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm,enum pwm_polarity polarity) { -struct tpu_pwm_device *pwm =pwm_get_chip_data (_pwm); +struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm); - pwm->polarity = polarity; + tpd->polarity = polarity;return 0 ; } -static int tpu_pwm_enable (struct pwm_chip *chip,struct pwm_device *_pwm) +static int tpu_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) { -struct tpu_pwm_device *pwm =pwm_get_chip_data (_pwm); +struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm);int ret; - ret =tpu_pwm_timer_start (pwm); + ret =tpu_pwm_timer_start (tpd);if (ret <0 )return ret;
@@ -347,23 +347,23 @@ static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *_pwm)* To avoid running the timer when not strictly required, handle 0% and * 100% duty cycles as fixed levels and stop the timer. */ -if (pwm->duty ==0 || pwm->duty == pwm->period) { -tpu_pwm_set_pin (pwm, pwm->duty ? +if (tpd->duty ==0 || tpd->duty == tpd->period) { +tpu_pwm_set_pin (tpd, tpd->duty ?TPU_PIN_ACTIVE :TPU_PIN_INACTIVE ); -tpu_pwm_timer_stop (pwm); +tpu_pwm_timer_stop (tpd); }return 0 ; } -static void tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *_pwm) +static void tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) { -struct tpu_pwm_device *pwm =pwm_get_chip_data (_pwm); +struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm);/* The timer must be running to modify the pin output configuration. */ -tpu_pwm_timer_start (pwm); -tpu_pwm_set_pin (pwm,TPU_PIN_INACTIVE ); -tpu_pwm_timer_stop (pwm); +tpu_pwm_timer_start (tpd); +tpu_pwm_set_pin (tpd,TPU_PIN_INACTIVE ); +tpu_pwm_timer_stop (tpd); } static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1150/1848 pwm: renesas-tpu: Improve maths to compute register settings
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 3c173376efc461dc670b02ba2846c2a533491104 ]
The newly computed register values are intended to exactly match the previously computed values. The main improvement is that the prescaler is computed without a loop that involves two divisions in each step. This uses the fact, that prescalers[i] = 1 << (2 * i).
Assuming a moderately smart compiler, the needed number of divisions for the case where the requested period is too big, is reduced from 5 to 2.
Stable-dep-of: 62cff15fbf2b ("pwm: renesas-tpu: Fix runtime PM reference leak")
--- drivers/pwm/pwm-renesas-tpu.c | 50 ++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 15 deletions(-)
drivers/pwm/pwm-renesas-tpu.c +35 -15
@@ -244,7 +244,6 @@ static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)static int tpu_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm,int duty_ns,int period_ns,bool enabled) { -static const unsigned int prescalers[] = {1 ,4 ,16 ,64 };struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm);struct tpu_device *tpu =to_tpu_device (chip);unsigned int prescaler;
@@ -254,26 +253,47 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,u32 duty;int ret; + clk_rate =clk_get_rate (tpu->clk); + + period = clk_rate / (NSEC_PER_SEC / period_ns); +/* -* Pick a prescaler to avoid overflowing the counter. -* TODO: Pick the highest acceptable prescaler. +* Find the minimal prescaler in [0..3] such that +* +* period >> (2 * prescaler) < 0x10000 +* +* This could be calculated using something like: +* +* prescaler = max(ilog2(period) / 2, 7) - 7; +* +* but given there are only four allowed results and that ilog2 isn't +* cheap on all platforms using a switch statement is more effective. */ - clk_rate =clk_get_rate (tpu->clk); +switch (period) { + case 1 ... 0xffff: + prescaler =0 ; +break ; -for (prescaler =0 ; prescaler <ARRAY_SIZE (prescalers); ++prescaler) { - period = clk_rate / prescalers[prescaler] - / (NSEC_PER_SEC / period_ns); -if (period <=0xffff ) -break ; - } + case 0x10000 ... 0x3ffff: + prescaler =1 ; +break ; -if (prescaler ==ARRAY_SIZE (prescalers) || period ==0 ) { -dev_err (&tpu->pdev->dev,"clock rate mismatch\n" ); -return -ENOTSUPP ; + case 0x40000 ... 0xfffff: + prescaler =2 ; +break ; + + case 0x100000 ... 0x3fffff: + prescaler =3 ; +break ; + +default : +return -EINVAL ; } + period >>=2 * prescaler; +if (duty_ns) { - duty = clk_rate / prescalers[prescaler] + duty = (clk_rate >>2 * prescaler) / (NSEC_PER_SEC / duty_ns);if (duty > period)return -EINVAL ;
@@ -283,7 +303,7 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,dev_dbg (&tpu->pdev->dev,"rate %u, prescaler %u, period %u, duty %u\n" , - clk_rate, prescalers[prescaler], period, duty); + clk_rate,1 << (2 * prescaler), period, duty);if (tpd->prescaler == prescaler && tpd->period == period) duty_only = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1151/1848 pwm: renesas: Drop usage of pwm_[gs]et_chip_data()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit ec63391a0d402cafa5f4dfd11e05cd325ae7e2f5 ]
Instead of distributing the driver's bookkeeping over 5 (i.e. TPU_CHANNEL_MAX + 1) separately allocated memory chunks, put all together in struct tpu_device. This reduces the number of memory allocations and so fragmentation and maybe even the number of cache misses. Also &tpu->tpd[pwm->hwpwm] is cheaper to evaluate than pwm_get_chip_data(pwm) as the former is just an addition in machine code while the latter involves a function call.
Stable-dep-of: 62cff15fbf2b ("pwm: renesas-tpu: Fix runtime PM reference leak")
--- drivers/pwm/pwm-renesas-tpu.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/pwm/pwm-renesas-tpu.c +11 -11
@@ -85,6 +85,7 @@ struct tpu_device {void __iomem *base;struct clk *clk; +struct tpu_pwm_device tpd[TPU_CHANNEL_MAX ]; };#define to_tpu_device (c) container_of(c, struct tpu_device, chip)
@@ -215,9 +216,7 @@ static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)if (pwm->hwpwm >=TPU_CHANNEL_MAX )return -EINVAL ; - tpd =kzalloc (sizeof (*tpd),GFP_KERNEL ); -if (tpd ==NULL ) -return -ENOMEM ; + tpd = &tpu->tpd[pwm->hwpwm]; tpd->tpu = tpu; tpd->channel = pwm->hwpwm;
@@ -228,24 +227,22 @@ static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) tpd->timer_on = false; -pwm_set_chip_data (pwm, tpd); -return 0 ; }static void tpu_pwm_free (struct pwm_chip *chip,struct pwm_device *pwm) { -struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm); +struct tpu_device *tpu =to_tpu_device (chip); +struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];tpu_pwm_timer_stop (tpd); -kfree (tpd); }static int tpu_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm,int duty_ns,int period_ns,bool enabled) { -struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm);struct tpu_device *tpu =to_tpu_device (chip); +struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];unsigned int prescaler;bool duty_only = false;u32 clk_rate;
@@ -347,7 +344,8 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,static int tpu_pwm_set_polarity (struct pwm_chip *chip,struct pwm_device *pwm,enum pwm_polarity polarity) { -struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm); +struct tpu_device *tpu =to_tpu_device (chip); +struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; tpd->polarity = polarity;
@@ -356,7 +354,8 @@ static int tpu_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,static int tpu_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) { -struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm); +struct tpu_device *tpu =to_tpu_device (chip); +struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];int ret; ret =tpu_pwm_timer_start (tpd);
@@ -378,7 +377,8 @@ static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)static void tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) { -struct tpu_pwm_device *tpd =pwm_get_chip_data (pwm); +struct tpu_device *tpu =to_tpu_device (chip); +struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];/* The timer must be running to modify the pin output configuration. */ tpu_pwm_timer_start (tpd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1152/1848 pwm: renesas-tpu: Fix runtime PM reference leak
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 62cff15fbf2b12ebbb0b01ca720030c2bc12aed1 ]
tpu_pwm_timer_start() used pm_runtime_get_sync() without checking its return value before touching the TPU clock. A failed runtime resume was therefore ignored, and the callback continued into register access.
Use pm_runtime_resume_and_get() and propagate a failed resume. Keep the matching put when clock preparation fails after a successful resume.
tpu_pwm_disable() also needs to propagate a failed start so that the PWM apply callback does not access registers while runtime PM is inactive.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/pwm/pwm-renesas-tpu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/pwm/pwm-renesas-tpu.c +18 -5
@@ -148,10 +148,14 @@ static int tpu_pwm_timer_start(struct tpu_pwm_device *tpd)if (!tpd->timer_on) {/* Wake up device and enable clock. */ -pm_runtime_get_sync (&tpd->tpu->pdev->dev); + ret =pm_runtime_resume_and_get (&tpd->tpu->pdev->dev); +if (ret <0 ) +return ret; + ret =clk_prepare_enable (tpd->tpu->clk);if (ret) {dev_err (&tpd->tpu->pdev->dev,"cannot enable clock\n" ); +pm_runtime_put (&tpd->tpu->pdev->dev);return ret; } tpd->timer_on = true;
@@ -375,15 +379,21 @@ static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)return 0 ; } -static void tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) +static int tpu_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) {struct tpu_device *tpu =to_tpu_device (chip);struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; +int ret;/* The timer must be running to modify the pin output configuration. */ -tpu_pwm_timer_start (tpd); + ret =tpu_pwm_timer_start (tpd); +if (ret <0 ) +return ret; +tpu_pwm_set_pin (tpd,TPU_PIN_INACTIVE );tpu_pwm_timer_stop (tpd); + +return 0 ; } static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -394,7 +404,10 @@ static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,if (state->polarity != pwm->state.polarity) {if (enabled) { -tpu_pwm_disable (chip, pwm); + err =tpu_pwm_disable (chip, pwm); +if (err) +return err; + enabled = false; }
@@ -405,7 +418,7 @@ static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,if (!state->enabled) {if (enabled) -tpu_pwm_disable (chip, pwm); +return tpu_pwm_disable (chip, pwm);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1153/1848 spi: omap2-mcspi: Remove unbalanced pm_runtime_put_sync() calls
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit 5f01cb141169fe422c42279f7d502479b1ff9fd2 ]
pm_runtime_put_sync() is called in the probe error path and in remove when nothing holds a runtime PM reference anymore, so it underflows the usage count.
--- drivers/spi/spi-omap2-mcspi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/spi/spi-omap2-mcspi.c +0 -2
@@ -1523,7 +1523,6 @@ static int omap2_mcspi_probe(struct platform_device *pdev) disable_pm:pm_runtime_dont_use_autosuspend (&pdev->dev); -pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev); free_master:omap2_mcspi_release_dma (master);
@@ -1539,7 +1538,6 @@ static int omap2_mcspi_remove(struct platform_device *pdev)omap2_mcspi_release_dma (master);pm_runtime_dont_use_autosuspend (mcspi->dev); -pm_runtime_put_sync (mcspi->dev);pm_runtime_disable (&pdev->dev);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1154/1848 staging: octeon: schedule the TX cleanup tasklet every 1024th packet
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Orgad Shaneh <[email protected]>
[ Upstream commit db57f6517bf65523968ae29cd34a790bfa7d32af ]
cvm_oct_xmit() means to schedule the cleanup tasklet once every 1024 packets, as its comment says, to cover the pathological case of heavy traffic on one port delaying the cleanup of another port blocked waiting for it.
The test is inverted: total_to_clean & 0x3ff is true for 1023 of every 1024 values, and false only on the multiples of 1024. So the tasklet is scheduled on nearly every packet, and skipped on exactly the packet the comment wants. That costs one TASKLET softirq per transmitted packet, each walking every port and doing an FAU fetch-and-add per non-empty queue, and it buys nothing for this port, which already frees its completed skbs inline from the skb_to_free value it reads out of the FAU.
Test the mask against zero. On a CN50XX board (2 cores at 300MHz) carrying ~6.9k transmitted packets/s, TASKLET softirqs drop from 7133/s to 597/s with no throughput change; the freeing work is conserved, so this removes softirq entries, not work.
--- drivers/staging/octeon/ethernet-tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/octeon/ethernet-tx.c +1 -1
@@ -485,7 +485,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)cvmx_fau_fetch_and_add32 (FAU_TOTAL_TX_TO_CLEAN ,1 ); } -if (total_to_clean &0x3ff ) { +if ((total_to_clean &0x3ff ) ==0 ) {/* * Schedule the cleanup tasklet every 1024 packets for * the pathological case of high traffic on one port
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1155/1848 microblaze: CCF: fix refcount leak
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander A. Klimov <[email protected]>
[ Upstream commit aeedf85beac51c7cd8f7bf4c918a0104dfdb8b78 ]
Every value returned from of_clk_get() is supposed to be cleaned up via clk_put() once not needed anymore.
--- arch/microblaze/kernel/cpu/cpuinfo.c | 1 + 1 file changed, 1 insertion(+)
arch/microblaze/kernel/cpu/cpuinfo.c +1 -0
@@ -133,6 +133,7 @@ void __init setup_cpuinfo_clk(void) cpuinfo.cpu_clock_freq =fcpu (cpu,"timebase-frequency" ); }else { cpuinfo.cpu_clock_freq =clk_get_rate (clk); +clk_put (clk); }if (!cpuinfo.cpu_clock_freq) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1156/1848 microblaze: prevent ptrace writes to MSR and pt_mode
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 8518fd17ccef4a7d77877ccb0403b722106ad1a4 ]
arch_ptrace() accepts PTRACE_POKEUSR for every aligned offset below PT_SIZE. This includes the saved machine status register and pt_mode, which are kernel-owned execution state rather than general registers.
On return from an exception, rtbd copies MSR_UMS to the live MSR_UM bit. An unprivileged same-UID tracer can therefore clear MSR_UMS in its tracee's saved register frame and make the tracee resume in supervisor mode. pt_mode also controls whether later entry paths classify the frame as kernel or user state.
Reject PTRACE_POKEUSR writes to both fields while retaining read access.
--- arch/microblaze/kernel/ptrace.c | 3 +++ 1 file changed, 3 insertions(+)
arch/microblaze/kernel/ptrace.c +3 -0
@@ -102,6 +102,9 @@ long arch_ptrace(struct task_struct *child, long request, }else { rval = -EIO ; } + }else if (request ==PTRACE_POKEUSR && + (addr ==PT_MSR || addr ==PT_MODE )) { + rval = -EIO ; }else if (addr <PT_SIZE && (addr &0x3 ) ==0 ) {microblaze_reg_t *reg_addr =reg_save_addr (addr, child);if (request ==PTRACE_PEEKUSR )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1157/1848 wifi: rtw88: debugfs: dont vzalloc(0) when rsvd_page is read unconfigured
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdurrahman Karadag <[email protected]>
[ Upstream commit 81510c3d6f2199889a4a936d8cf8b9e05911b10e ]
Reading the rsvd_page debugfs entry before writing a page offset and count to it calls vzalloc() with a size of zero, because rsvd_page.page_num defaults to 0. vmalloc warns about this:
WARNING: mm/vmalloc.c:4019 at __vmalloc_node_range_noprof+0x9ac/0xa30 ... Call Trace: __vmalloc_node_noprof+0x4c/0x70 rtw_debugfs_get_rsvd_page+0x4c/0x110 [rtw88_core] seq_read_iter+0x132/0x4b0 seq_read+0x12e/0x1c0 full_proxy_read+0x6f/0xc0 vfs_read+0xdd/0x490
rtw_fw_dump_fifo() would reject the zero size anyway, but only after the allocation. Check for a zero buffer size first and print a short usage hint instead of allocating.
--- drivers/net/wireless/realtek/rtw88/debug.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/debug.c +5 -0
@@ -227,6 +227,11 @@ static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v)int i;int ret; +if (!buf_size) { +seq_puts (m,"usage: echo <page_offset> <page_num> > rsvd_page\n" ); +return 0 ; + } + buf =vzalloc (buf_size);if (!buf)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1158/1848 dmaengine: fsl_raid: dont invoke client callback under desc_lock
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 62c267ce97444f8a381f2bb3cd5d534eb362c540 ]
fsl_re_dequeue() holds re_chan->desc_lock while calling fsl_re_desc_done(), which synchronously invokes the DMA client completion callback via dmaengine_desc_get_callback_invoke(). If that callback submits new work (e.g. fsl_re_tx_submit()), it tries to reacquire the same desc_lock and deadlocks on the spinlock.
Collect completed descriptors into a local list under the lock, then release the lock and invoke the callbacks before moving the descriptors to the ack queue.
--- drivers/dma/fsl_raid.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/dma/fsl_raid.c +13 -2
@@ -161,6 +161,7 @@ static void fsl_re_dequeue(struct tasklet_struct *t)struct fsl_re_hw_desc *hwdesc;unsigned long flags;unsigned int count, oub_count; +LIST_HEAD (completed);int found;fsl_re_cleanup_descs (re_chan);
@@ -181,8 +182,7 @@ static void fsl_re_dequeue(struct tasklet_struct *t) }if (found) { -fsl_re_desc_done (desc); -list_move_tail (&desc->node, &re_chan->ack_q); +list_move_tail (&desc->node, &completed); }else {dev_err (re_chan->dev,"found hwdesc not in sw queue, discard it\n" );
@@ -195,6 +195,17 @@ static void fsl_re_dequeue(struct tasklet_struct *t) FSL_RE_RMVD_JOB(1)); }spin_unlock_irqrestore (&re_chan->desc_lock, flags); + +/* Invoke the client callbacks outside the channel lock. The callback +* may submit new work which re-acquires desc_lock, so holding it here +* would deadlock. +*/ +list_for_each_entry_safe (desc, _desc, &completed, node) { +fsl_re_desc_done (desc); +spin_lock_irqsave (&re_chan->desc_lock, flags); +list_move_tail (&desc->node, &re_chan->ack_q); +spin_unlock_irqrestore (&re_chan->desc_lock, flags); + } }/* Per Job Ring interrupt handler */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1159/1848 dmaengine: fsl_raid: avoid free_q underflow in free_chan_resources
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit d805aa5b6088b193debabaa80cc0991bfa2bd057 ]
fsl_re_free_chan_resources() loops alloc_count times calling list_first_entry() on free_q without checking whether the list still has entries. If descriptors remain un-acked or pending in submit_q / active_q / ack_q when the channel resources are freed, free_q becomes smaller than alloc_count and list_first_entry() returns the list head, causing list_del() to corrupt the list head and dereference a bogus pointer.
Walk free_q with list_for_each_entry_safe() until it is empty, decrementing alloc_count per freed descriptor, instead of relying on the alloc_count count.
--- drivers/dma/fsl_raid.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/dma/fsl_raid.c +3 -6
@@ -612,18 +612,15 @@ static int fsl_re_alloc_chan_resources(struct dma_chan *chan)static void fsl_re_free_chan_resources (struct dma_chan *chan) {struct fsl_re_chan *re_chan; -struct fsl_re_desc *desc; +struct fsl_re_desc *desc, *_desc; re_chan = container_of(chan, struct fsl_re_chan, chan); -while (re_chan->alloc_count--) { - desc =list_first_entry (&re_chan->free_q, - struct fsl_re_desc, - node); - +list_for_each_entry_safe (desc, _desc, &re_chan->free_q, node) {list_del (&desc->node);dma_pool_free (re_chan->re_dev->cf_desc_pool, desc->cf_addr, desc->cf_paddr);kfree (desc); + re_chan->alloc_count--; }if (!list_empty (&re_chan->free_q))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1160/1848 clk: Use the generic OF phandle parsing in only one place
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal (Schneider Electric) <[email protected]>
[ Upstream commit 57d728b4ab15a8af890013bb0f302e7733f7c1c6 ]
Ideally, there should be one single entry in the OF world. This way, the DT parsing logic is always identical. At this stage, we call of_parse_phandle_with_args() in:
- of_parse_clkspec()
- of_clk_get_parent_name()
which kinds of defeats the above statement. Furthermore, when this call is done from of_clk_get_parent_name(), we fail to parse the 'clock-ranges' property.
Make sure DT world is entered only once by calling of_parse_clkspec() from of_clk_get_parent_name(). Doing so implies that we do not try the "clock-ranges" path if we already found a "clocks" property.
--- drivers/clk/clk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/clk.c +3 -2
@@ -4825,6 +4825,8 @@ static int of_parse_clkspec(const struct device_node *np, int index,* has a "clock-ranges" property, then we can try one of its * clocks. */ +if (of_property_present (np,"clocks" )) +break ; np = np->parent;if (np && !of_get_property (np,"clock-ranges" ,NULL ))break ;
@@ -4970,8 +4972,7 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index)int count;struct clk *clk; - rc =of_parse_phandle_with_args (np,"clocks" ,"#clock-cells" , index, - &clkspec); + rc =of_parse_clkspec (np, index,NULL , &clkspec);if (rc)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1161/1848 selftests/clone3: tighten CLONE_CLEAR_SIGHAND conflict test
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Dolan <[email protected]>
[ Upstream commit aeebb4884f0e8feb9929f013067488b7f2081f33 ]
The CLONE_CLEAR_SIGHAND test intends to verify that CLONE_CLEAR_SIGHAND and CLONE_SIGHAND are mutually exclusive. However, CLONE_SIGHAND without CLONE_VM is independently invalid, so the test input has another reason to fail with EINVAL.
Add CLONE_VM so that CLONE_SIGHAND is otherwise valid, and require clone3() to fail with EINVAL. This ensures the test exercises the intended flag conflict and does not accept an unrelated failure.
--- tools/testing/selftests/clone3/clone3_clear_sighand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/clone3/clone3_clear_sighand.c +3 -3
@@ -54,12 +54,12 @@ static void test_clone3_clear_sighand(void)* Check that CLONE_CLEAR_SIGHAND and CLONE_SIGHAND are mutually * exclusive. */ - args.flags |=CLONE_CLEAR_SIGHAND |CLONE_SIGHAND ; + args.flags |=CLONE_VM |CLONE_CLEAR_SIGHAND |CLONE_SIGHAND ; args.exit_signal =SIGCHLD ; pid =sys_clone3 (&args,sizeof (args)); -if (pid >0 ) +if (pid !=-1 || errno !=EINVAL )ksft_exit_fail_msg ( -"clone3(CLONE_CLEAR_SIGHAND | CLONE_SIGHAND) succeeded\n" ); +"clone3(CLONE_CLEAR_SIGHAND | CLONE_SIGHAND) did not fail with EINVAL\n" ); act.sa_handler = nop_handler; ret =sigemptyset (&act.sa_mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1162/1848 hwrng: cctrng - Fix runtime PM usage counter leak
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 58d27c41542be6c40edac4f91f35a1dd8bf0d2c2 ]
pm_runtime_get_sync() increments the device usage counter even when runtime resume fails. cctrng_read() propagates errors from cc_trng_pm_get() without scheduling the work that later drops the counter, so a clock or reset-completion failure in cctrng_resume() leaves the counter elevated.
Use pm_runtime_resume_and_get(), which drops the usage counter when resume fails and returns zero on success. This preserves the existing success path while balancing the error path.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/char/hw_random/cctrng.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/char/hw_random/cctrng.c +1 -6
@@ -86,12 +86,7 @@ static inline u32 cc_ioread(struct cctrng_drvdata *drvdata, u32 reg)static int cc_trng_pm_get (struct device *dev) { -int rc =0 ; - - rc =pm_runtime_get_sync (dev); - -/* pm_runtime_get_sync() can return 1 as a valid return code */ -return (rc ==1 ?0 : rc); +return pm_runtime_resume_and_get (dev); }static void cc_trng_pm_put_suspend (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1163/1848 crypto: asymmetric_keys - fix OOB read in pefile_parse_binary
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabrice Derepas <[email protected]>
[ Upstream commit 37d550172c2d3cdb3a5ace3e6cb0625967d86349 ]
pefile_parse_binary() reads the size field of the certificate table's data-directory entry, which sits at fixed index 4 of the PE optional header's data directory:
ctx->certs_size = ddir->certs.size;
but nothing ensures index 4 is present. n_data_dirents (the untrusted NumberOfRvaAndSizes) is only upper-bounded against header_size and may be 0, and header_size need only satisfy cursor < header_size < datalen. A crafted PE with n_data_dirents = 0 and a tiny header_size therefore causes the ddir->certs.size read to land past the end of the image (CWE-125). The chkaddr() that bounds the certificate blob runs only after this read.
verify_pefile_signature() is reached from kexec_file_load() (the lockdown/secure-boot enforced PE-image signature path), and the image is parsed before its signature is checked. The trigger needs CAP_SYS_BOOT and the access is out-of-bounds read only (no write).
Require the certificate table's data-directory entry (index 4) to be present; the existing upper-bound check then keeps ddir->certs within [cursor, header_size).
--- crypto/asymmetric_keys/verify_pefile.c | 5 +++++ 1 file changed, 5 insertions(+)
crypto/asymmetric_keys/verify_pefile.c +5 -0
@@ -87,6 +87,11 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen,if (ctx->n_data_dirents > (ctx->header_size - cursor) /sizeof (*dde))return -ELIBBAD ; +/* the certificate table entry must be present in the data directory */ +if (ctx->n_data_dirents <= + offsetof(struct data_directory , certs) /sizeof (*dde)) +return -ELIBBAD ; + ddir = pebuf + cursor; cursor +=sizeof (*dde) * ctx->n_data_dirents;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1164/1848 wifi: mac80211: fix swapped fq_overlimit/fq_overmemory in aqm debugfs
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julius Bairaktaris <[email protected]>
[ Upstream commit 25f3f2ff88ae604a3b473b501fc55d58fcb0f5eb ]
The two scnprintf arguments for fq_overlimit and fq_overmemory are in the wrong order, which results in the aqm debugfs file showing the overmemory count under the fq_overlimit label and vice versa.
--- net/mac80211/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/debugfs.c +1 -1
@@ -98,8 +98,8 @@ static ssize_t aqm_read(struct file *file,"RW fq_quantum %u\n" , fq->flows_cnt, fq->backlog, - fq->overmemory, fq->overlimit, + fq->overmemory, fq->collisions, fq->memory_usage, fq->memory_limit,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1165/1848 memory: brcmstb_dpfe: validate firmware section sizes
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit e61c1a1103e2617e8f86288368911a8591e35c1e ]
The firmware header is read before the image has been shown to contain a complete header. In addition, the final size check adds two firmware-provided u32 section lengths before comparing the result with fw->size, so the addition can wrap.
Reject images shorter than the fixed header and checksum before reading the header. Then derive the available payload length with subtraction and require the two declared sections to fill it exactly.
--- drivers/memory/brcmstb_dpfe.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/memory/brcmstb_dpfe.c +9 -8
@@ -534,9 +534,15 @@ static int __verify_firmware(struct init_data *init, const struct firmware *fw) {const struct dpfe_firmware_header *header = (void *)fw->data; -unsigned int dmem_size, imem_size, total_size; +unsigned int dmem_size, imem_size;bool is_big_endian = false;const u32 *chksum_ptr; +size_t payload_size; + +if (fw->size <sizeof (*header) +sizeof (*chksum_ptr)) +return ERR_INVALID_SIZE ; + + payload_size = fw->size -sizeof (*header) -sizeof (*chksum_ptr);if (header->magic ==DPFE_BE_MAGIC ) is_big_endian = true;
@@ -555,13 +561,8 @@ static int __verify_firmware(struct init_data *init,if ((dmem_size %sizeof (u32)) !=0 || (imem_size %sizeof (u32)) !=0 )return ERR_INVALID_SIZE ; -/* -* The header + the data section + the instruction section + the -* checksum must be equal to the total firmware size. -*/ - total_size = dmem_size + imem_size +sizeof (*header) + -sizeof (*chksum_ptr); -if (total_size != fw->size) +/* The data and instruction sections must fill the payload exactly. */ +if (dmem_size > payload_size || imem_size != payload_size - dmem_size)return ERR_INVALID_SIZE ;/* The checksum comes at the very end. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1166/1848 regulator: mp886x: Convert to use regulator_set_ramp_delay_regmap
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Axel Lin <[email protected]>
[ Upstream commit e1e8d55bb90c9a07aa66a0c9fa17bd5a67d2689c ]
Use regulator_set_ramp_delay_regmap instead of open-coded.
Message-Id: <[email protected]>
Stable-dep-of: 24fa0eadc2e3 ("regulator: mp886x: fix vsel_mask")
--- drivers/regulator/mp886x.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-)
drivers/regulator/mp886x.c +7 -25
@@ -26,7 +26,7 @@struct mp886x_cfg_info {const struct regulator_ops *rops; -const int slew_rates[8 ]; +const unsigned int slew_rates[8 ];const int switch_freq[4 ];const u8 fs_reg;const u8 fs_shift;
@@ -42,28 +42,6 @@ struct mp886x_device_info {unsigned int sel; }; -static int mp886x_set_ramp (struct regulator_dev *rdev,int ramp) -{ -struct mp886x_device_info *di =rdev_get_drvdata (rdev); -const struct mp886x_cfg_info *ci = di->ci; -int reg =-1 , i; - -for (i =0 ; i <ARRAY_SIZE (ci->slew_rates); i++) { -if (ramp <= ci->slew_rates[i]) - reg = i; -else -break ; - } - -if (reg <0 ) { -dev_err (di->dev,"unsupported ramp value %d\n" , ramp); -return -EINVAL ; - } - -return regmap_update_bits (rdev->regmap,MP886X_SYSCNTLREG1 , -MP886X_SLEW_MASK , reg <<MP886X_SLEW_SHIFT ); -} -static void mp886x_set_switch_freq (struct mp886x_device_info *di,struct regmap *regmap,u32 freq)
@@ -169,7 +147,7 @@ static const struct regulator_ops mp8869_regulator_ops = { .is_enabled = regulator_is_enabled_regmap, .set_mode = mp886x_set_mode, .get_mode = mp886x_get_mode, - .set_ramp_delay = mp886x_set_ramp, + .set_ramp_delay = regulator_set_ramp_delay_regmap, };static const struct mp886x_cfg_info mp8869_ci = {
@@ -248,7 +226,7 @@ static const struct regulator_ops mp8867_regulator_ops = { .is_enabled = regulator_is_enabled_regmap, .set_mode = mp886x_set_mode, .get_mode = mp886x_get_mode, - .set_ramp_delay = mp886x_set_ramp, + .set_ramp_delay = regulator_set_ramp_delay_regmap, };static const struct mp886x_cfg_info mp8867_ci = {
@@ -290,6 +268,10 @@ static int mp886x_regulator_register(struct mp886x_device_info *di, rdesc->uV_step =10000 ; rdesc->vsel_reg =MP886X_VSEL ; rdesc->vsel_mask =0x3f ; + rdesc->ramp_reg =MP886X_SYSCNTLREG1 ; + rdesc->ramp_mask =MP886X_SLEW_MASK ; + rdesc->ramp_delay_table = di->ci->slew_rates; + rdesc->n_ramp_values =ARRAY_SIZE (di->ci->slew_rates); rdesc->owner =THIS_MODULE ; rdev =devm_regulator_register (di->dev, &di->desc, config);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1167/1848 regulator: mp886x: fix vsel_mask
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jisheng Zhang <[email protected]>
[ Upstream commit 24fa0eadc2e3c7e9397924197dca7777ec08b8d7 ]
The MP886X vsel is 7bits, fix the vsel_mask.
--- drivers/regulator/mp886x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/mp886x.c +1 -1
@@ -267,7 +267,7 @@ static int mp886x_regulator_register(struct mp886x_device_info *di, rdesc->min_uV =600000 ; rdesc->uV_step =10000 ; rdesc->vsel_reg =MP886X_VSEL ; - rdesc->vsel_mask =0x3f ; + rdesc->vsel_mask =0x7f ; rdesc->ramp_reg =MP886X_SYSCNTLREG1 ; rdesc->ramp_mask =MP886X_SLEW_MASK ; rdesc->ramp_delay_table = di->ci->slew_rates;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1168/1848 efi: cper: check section header more appropriately
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuai Xue <[email protected]>
[ Upstream commit 1be72c8e0786727df375f11c8178ce7e65eea20e ]
When checking a generic status block, we iterate over all the generic data blocks. The loop condition checks that the generic data block is valid. Because the size of data blocks (excluding error data) may vary depending on the revision and the revision is contained within the data block, we should ensure that enough of the current data block is valid appropriately for different revision.
Stable-dep-of: a5a612cd3eec ("efi/cper: Reject CPER records with an out-of-range error_data_length")
--- drivers/firmware/efi/cper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/cper.c +1 -1
@@ -699,7 +699,7 @@ int cper_estatus_check(const struct acpi_hest_generic_status *estatus) data_len = estatus->data_length;apei_estatus_for_each_section (estatus, gdata) { -if (sizeof (struct acpi_hest_generic_data ) > data_len) +if (acpi_hest_get_size (gdata) > data_len)return -EINVAL ; record_size =acpi_hest_get_record_size (gdata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1169/1848 efi/cper: Reject CPER records with an out-of-range error_data_length
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit a5a612cd3eecbadf135df1e9b2b40bc9f4c28f1c ]
cper_estatus_check() sizes each section with acpi_hest_get_record_size(), which adds the firmware-controlled u32 error_data_length to the header size as a signed int (see <acpi/ghes.h>). A value in the top sizeof(*gdata) bytes of the u32 range wraps the sum small rather than large, so it slips past the "record_size > data_len" check: against the 72-byte v300 header, 0xffffffb9 sizes the record at 1 and acpi_hest_get_next() walks it a byte at a time, off the end. 0xffffffb8 sizes it at 0 and loops forever.
Use check_add_overflow() to reject a sum that will not fit the int those helpers return, since the walk advances by that value. That subsumes the "acpi_hest_get_size(gdata) > data_len" test above it, because record_size is never smaller than the header.
The later "len < sizeof(*foo)" guards rely on this per-section upper bound; they are lower bounds only.
--- drivers/firmware/efi/cper.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/firmware/efi/cper.c +11 -3
@@ -689,7 +689,7 @@ EXPORT_SYMBOL_GPL(cper_estatus_check_header);int cper_estatus_check (const struct acpi_hest_generic_status *estatus) {struct acpi_hest_generic_data *gdata; -unsigned int data_len, record_size; +unsigned int data_len;int rc; rc =cper_estatus_check_header (estatus);
@@ -699,10 +699,18 @@ int cper_estatus_check(const struct acpi_hest_generic_status *estatus) data_len = estatus->data_length;apei_estatus_for_each_section (estatus, gdata) { -if (acpi_hest_get_size (gdata) > data_len) +int record_size; + +/* +* The <acpi/ghes.h> helpers sum these as a signed int, so a +* huge error_data_length wraps small rather than large and the +* walk then advances by that wrapped value. Reject a size an +* int cannot carry. +*/ +if (check_add_overflow (acpi_hest_get_size (gdata), + gdata->error_data_length, &record_size))return -EINVAL ; - record_size =acpi_hest_get_record_size (gdata);if (record_size > data_len)return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1170/1848 efi/cper: Reject an error status block length that wraps a u32
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 41e25ef5e417c62eb7bf39b187242b283b3ef9f1 ]
cper_estatus_len() sums the firmware-controlled data_length (or raw_data_offset plus raw_data_length) into a u32. A data_length of 0xffffffec wraps that sum to 0, and a length that reads back short defeats every bound built on it: bert_print_all() passes its "remain < estatus_len" check, then advances "estatus += estatus_len" by zero and loops forever. GHES survives only because __ghes_check_estatus() rejects a length below sizeof(*estatus) first.
Reject a length that cannot be expressed in a u32 in cper_estatus_check_header(), which both of today's callers reach: GHES via __ghes_check_estatus() and BERT via cper_estatus_check(). extlog reaches neither yet; a later patch routes it through cper_estatus_check(), whose ELOG_ENTRY_LEN bound needs this to hold.
--- drivers/firmware/efi/cper.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/firmware/efi/cper.c +11 -0
@@ -682,6 +682,17 @@ int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus) estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length) return -EINVAL; +/* +* cper_estatus_len() sums these into a u32, and a wrapped sum reads +* back smaller than the record. Reject a length that cannot be +* expressed so no caller is handed the short value. +*/ +if ((u64 )sizeof (*estatus) + estatus->data_length >U32_MAX ) +return -EINVAL ; +if (estatus->raw_data_length && + (u64 )estatus->raw_data_offset + estatus->raw_data_length >U32_MAX ) +return -EINVAL ; +return 0 ; }EXPORT_SYMBOL_GPL (cper_estatus_check_header);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1171/1848 ACPI: extlog: Validate elog record length before walking sections
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit e1fd582a8134150aa10c1f0286dbce00cf63b086 ]
extlog_print() copies a fixed ELOG_ENTRY_LEN (4096) bytes from the elog record into elog_buf, then walks the sections using the firmware-controlled data_length. Nothing keeps data_length inside the buffer, so a malformed record walks the section pointer past elog_buf and reads adjacent memory. Unlike the GHES paths, extlog never calls cper_estatus_check().
Reject a record longer than ELOG_ENTRY_LEN and run cper_estatus_check() before walking the sections. The length test alone is not enough: a wrapped length reads back short and passes it, which cper_estatus_check() catches via the header check added earlier. Drop a malformed record with NOTIFY_DONE and without MCE_HANDLED_EXTLOG, since extlog did not consume it.
--- drivers/acpi/acpi_extlog.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/acpi/acpi_extlog.c +9 -0
@@ -159,6 +159,15 @@ static int extlog_print(struct notifier_block *nb, unsigned long val, tmp = (struct acpi_hest_generic_status *)elog_buf; +/* +* Bound the length before cper_estatus_check() walks the sections: it +* iterates over data_length, which is not yet known to fit elog_buf. +* cper_estatus_check_header() then rejects a length that wrapped, which +* the bound cannot see. +*/ +if (cper_estatus_len (tmp) >ELOG_ENTRY_LEN ||cper_estatus_check (tmp)) +return NOTIFY_DONE ; +if (!ras_userspace_consumers ()) {print_extlog_rcd (NULL , tmp, cpu); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1172/1848 efi/cper: Read only validated fields in cper_mem_err_pack()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 92480a2b00a15b0add512b6fc474151ec5340a8e ]
cper_mem_err_pack() copies extended, rank, mem_array_handle and mem_dev_handle unconditionally. Those live at offsets 73 to 79, past the end of struct cper_sec_mem_err_old, the 73-byte UEFI 2.1/2.2 layout that older firmware still emits and that cper_estatus_print_section() admits. On such a record the copy reads up to seven bytes past the payload, and off the end of the error status block when that section is the last one.
Copy each of the four only when its validation bit is set, and zero it otherwise. Nothing is lost: a 2.1/2.2 record leaves those bits clear, and every consumer of struct cper_mem_err_compact already gates the fields on the same bits. Zeroing also stops callers reading them back out of the uninitialised on-stack struct they pass in.
--- drivers/firmware/efi/cper.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/firmware/efi/cper.c +22 -4
@@ -361,10 +361,28 @@ void cper_mem_err_pack(const struct cper_sec_mem_err *mem, cmem->requestor_id = mem->requestor_id; cmem->responder_id = mem->responder_id; cmem->target_id = mem->target_id; - cmem->extended = mem->extended; - cmem->rank = mem->rank; - cmem->mem_array_handle = mem->mem_array_handle; - cmem->mem_dev_handle = mem->mem_dev_handle; + +/* +* These four sit past the end of the UEFI 2.1/2.2 layout, which older +* firmware still emits, so reading them unconditionally runs off a +* short record. Every consumer of the compact record gates them on the +* same validation bits, so leave them zero when firmware does not +* claim them. +*/ + cmem->extended =0 ; + cmem->rank =0 ; + cmem->mem_array_handle =0 ; + cmem->mem_dev_handle =0 ; + +if (mem->validation_bits & + (CPER_MEM_VALID_ROW_EXT |CPER_MEM_VALID_CHIP_ID )) + cmem->extended = mem->extended; +if (mem->validation_bits &CPER_MEM_VALID_RANK_NUMBER ) + cmem->rank = mem->rank; +if (mem->validation_bits &CPER_MEM_VALID_CARD_HANDLE ) + cmem->mem_array_handle = mem->mem_array_handle; +if (mem->validation_bits &CPER_MEM_VALID_MODULE_HANDLE ) + cmem->mem_dev_handle = mem->mem_dev_handle; } const char *cper_mem_err_unpack(struct trace_seq *p,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1173/1848 spi: mtk-nor: fix runtime PM usage count leak in probe error path
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
[ Upstream commit 4cee1ed13e2687f1a9fec7dd50e31eb179506d75 ]
mtk_nor_probe() takes a runtime PM reference with pm_runtime_get_noresume() before registering the controller, but the error path never drops it.
Balance the get with pm_runtime_put_noidle() in the error path.
--- drivers/spi/spi-mtk-nor.c | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spi-mtk-nor.c +1 -0
@@ -847,6 +847,7 @@ static int mtk_nor_probe(struct platform_device *pdev)return 0 ; err_probe: +pm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev);pm_runtime_set_suspended (&pdev->dev);pm_runtime_dont_use_autosuspend (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1174/1848 gpio: crystalcove: add missing MODULE_ALIAS()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 32c7f7f80e5f7f2764682fd456054478fc11c8d9 ]
The crystalcove GPIO driver lacks a MODULE_ALIAS() to allow it to be auto-loaded.
Fix this by adding the missing platform alias.
--- drivers/gpio/gpio-crystalcove.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpio-crystalcove.c +1 -0
@@ -392,3 +392,4 @@ module_platform_driver(crystalcove_gpio_driver);MODULE_AUTHOR ("Yang, Bin <[email protected]>" );MODULE_DESCRIPTION ("Intel Crystal Cove GPIO Driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:crystal_cove_gpio" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1175/1848 drivers/base/node: fix UAF on device_register() failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit 6d7e9bc51d8f2d73b3403c759c769f880082f9ae ]
node_init_node_access() frees the access node with kfree() if device_register() fails. After device_register() the embedded device is initialized and must be released with put_device() so that node_access_release() can free it.
--- drivers/base/node.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/base/node.c +8 -9
@@ -140,20 +140,19 @@ static struct node_access_nodes *node_init_node_access(struct node *node, dev->parent = &node->dev; dev->release = node_access_release; dev->groups = node_access_node_groups; -if (dev_set_name (dev,"access%u" , access)) - goto free; +if (dev_set_name (dev,"access%u" , access)) { +kfree (access_node); +return NULL ; + } -if (device_register (dev)) - goto free_name; +if (device_register (dev)) { +put_device (dev); +return NULL ; + }pm_runtime_no_callbacks (dev);list_add_tail (&access_node->list_node, &node->access_list);return access_node; -free_name: -kfree_const (dev->kobj.name); -free: -kfree (access_node); -return NULL ; }#ifdef CONFIG_HMEM_REPORTING
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1176/1848 irqchip/gic-v3: Switch to bitmap_zalloc()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit ff5fe8867a5feaf90b1cb9b766f3de3a1caf9f33 ]
Switch to bitmap_zalloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *.
Stable-dep-of: 135d9e67f7ab ("irqchip/gic-v3-its: Don't WARN on LPI free allocation failure")
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++--- drivers/irqchip/irq-gic-v3-mbi.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +3 -3
@@ -2166,7 +2166,7 @@ static unsigned long *its_lpi_alloc(int nr_irqs, u32 *base, int *nr_ids)if (err) goto out; - bitmap =kcalloc (BITS_TO_LONGS (nr_irqs),sizeof (long ),GFP_ATOMIC ); + bitmap =bitmap_zalloc (nr_irqs,GFP_ATOMIC );if (!bitmap) goto out;
@@ -2182,7 +2182,7 @@ static unsigned long *its_lpi_alloc(int nr_irqs, u32 *base, int *nr_ids)static void its_lpi_free (unsigned long *bitmap,u32 base,u32 nr_ids) {WARN_ON (free_lpi_range (base, nr_ids)); -kfree (bitmap); +bitmap_free (bitmap); }static void gic_reset_prop_table (void *va)
@@ -3417,7 +3417,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) {kfree (dev);kfree (itt); -kfree (lpi_map); +bitmap_free (lpi_map);kfree (col_map);return NULL ; }
drivers/irqchip/irq-gic-v3-mbi.c +2 -3
@@ -290,8 +290,7 @@ int __init mbi_init(struct fwnode_handle *fwnode, struct irq_domain *parent)if (ret) goto err_free_mbi; - mbi_ranges[n].bm =kcalloc (BITS_TO_LONGS (mbi_ranges[n].nr_spis), -sizeof (long ),GFP_KERNEL ); + mbi_ranges[n].bm =bitmap_zalloc (mbi_ranges[n].nr_spis,GFP_KERNEL );if (!mbi_ranges[n].bm) { ret = -ENOMEM ; goto err_free_mbi;
@@ -329,7 +328,7 @@ int __init mbi_init(struct fwnode_handle *fwnode, struct irq_domain *parent) err_free_mbi:if (mbi_ranges) {for (n =0 ; n < mbi_range_nr; n++) -kfree (mbi_ranges[n].bm); +bitmap_free (mbi_ranges[n].bm);kfree (mbi_ranges); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1177/1848 irqchip/gic-v3-its: Dont WARN on LPI free allocation failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 135d9e67f7ab4f261c2157ee2de1f93a4de39a41 ]
free_lpi_range() cannot give LPIs back to the allocator without allocating a struct lpi_range to describe the freed range, so it returns -ENOMEM (its only failure mode) when that allocation fails, and its_lpi_free() turns this into a WARN_ON().
syzbot triggers the WARN_ON() by injecting a slab allocation failure on device teardown, which with panic_on_warn becomes a panic:
WARNING: drivers/irqchip/irq-gic-v3-its.c:2251 at its_msi_teardown+0x3a4/0x424 its_msi_teardown+0x3a4/0x424 msi_remove_device_irq_domain+0x16c/0x27c msi_device_data_release+0x38/0x9c
The failure is transient and the consequence benign: the freed range is simply never returned to the allocator. This does not warrant a WARN_ON() backtrace, so log a rate-limited error instead.
--- drivers/irqchip/irq-gic-v3-its.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +2 -1
@@ -2181,7 +2181,8 @@ static unsigned long *its_lpi_alloc(int nr_irqs, u32 *base, int *nr_ids)static void its_lpi_free (unsigned long *bitmap,u32 base,u32 nr_ids) { -WARN_ON (free_lpi_range (base, nr_ids)); +if (free_lpi_range (base, nr_ids)) +pr_err_ratelimited ("ITS: failed to free LPI range %u:%u\n" , base, nr_ids);bitmap_free (bitmap); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1178/1848 ASoC: mediatek: mt6797: fix wrong unwind order and error code in enable_clock
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit e967d479b65c778cd2394ab185e289beefcf996d ]
The error paths in mt6797_afe_enable_clock() use incorrect goto labels, causing clocks that failed to enable to be disabled during cleanup.
Fix the goto labels to only unwind clocks that were successfully enabled, and return the actual error code.
--- sound/soc/mediatek/mt6797/mt6797-afe-clk.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
sound/soc/mediatek/mt6797/mt6797-afe-clk.c +6 -8
@@ -63,21 +63,21 @@ int mt6797_afe_enable_clock(struct mtk_base_afe *afe)if (ret) {dev_err (afe->dev,"%s(), clk_prepare_enable %s fail %d\n" , __func__, aud_clks[CLK_INFRA_SYS_AUD ], ret); - goto CLK_INFRA_SYS_AUDIO_ERR; +return ret; } ret =clk_prepare_enable (afe_priv->clk[CLK_INFRA_SYS_AUD_26M ]);if (ret) {dev_err (afe->dev,"%s(), clk_prepare_enable %s fail %d\n" , __func__, aud_clks[CLK_INFRA_SYS_AUD_26M ], ret); - goto CLK_INFRA_SYS_AUD_26M_ERR; + goto CLK_INFRA_SYS_AUDIO_ERR; } ret =clk_prepare_enable (afe_priv->clk[CLK_TOP_MUX_AUD ]);if (ret) {dev_err (afe->dev,"%s(), clk_prepare_enable %s fail %d\n" , __func__, aud_clks[CLK_TOP_MUX_AUD ], ret); - goto CLK_MUX_AUDIO_ERR; + goto CLK_INFRA_SYS_AUD_26M_ERR; } ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD],
@@ -93,13 +93,11 @@ int mt6797_afe_enable_clock(struct mtk_base_afe *afe)if (ret) {dev_err (afe->dev,"%s(), clk_prepare_enable %s fail %d\n" , __func__, aud_clks[CLK_TOP_MUX_AUD_BUS ], ret); - goto CLK_MUX_AUDIO_INTBUS_ERR; + goto CLK_MUX_AUDIO_ERR; } -return ret; +return 0 ; -CLK_MUX_AUDIO_INTBUS_ERR: -clk_disable_unprepare (afe_priv->clk[CLK_TOP_MUX_AUD_BUS ]); CLK_MUX_AUDIO_ERR:clk_disable_unprepare (afe_priv->clk[CLK_TOP_MUX_AUD ]); CLK_INFRA_SYS_AUD_26M_ERR:
@@ -107,7 +105,7 @@ int mt6797_afe_enable_clock(struct mtk_base_afe *afe) CLK_INFRA_SYS_AUDIO_ERR:clk_disable_unprepare (afe_priv->clk[CLK_INFRA_SYS_AUD ]); -return 0 ; +return ret; }int mt6797_afe_disable_clock (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1179/1848 pwm: lp3943: Drop usage of pwm_[gs]et_chip_data()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 06cc4767750337ad162a0a7bcfd6f6eff6e0fe92 ]
Instead of distributing the driver's bookkeeping over 3 (i.e. LP3943_NUM_PWMS + 1) separately allocated memory chunks, put all together in struct lp3943_pwm. This reduces the number of memory allocations and so fragmentation and maybe even the number of cache misses. Also &lp3943_pwm->pwm_map[pwm->hwpwm] is cheaper to evaluate than pwm_get_chip_data(pwm) as the former is just an addition in machine code while the latter involves a function call.
Stable-dep-of: 17dbb6938d3a ("pwm: lp3943: fix NULL pointer dereference for an unconfigured channel")
--- drivers/pwm/pwm-lp3943.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
drivers/pwm/pwm-lp3943.c +7 -14
@@ -23,6 +23,7 @@ struct lp3943_pwm {struct pwm_chip chip;struct lp3943 *lp3943;struct lp3943_platform_data *pdata; +struct lp3943_pwm_map pwm_map[LP3943_NUM_PWMS ]; };static inline struct lp3943_pwm *to_lp3943_pwm (struct pwm_chip *_chip)
@@ -35,13 +36,9 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm) {struct lp3943_platform_data *pdata = lp3943_pwm->pdata;struct lp3943 *lp3943 = lp3943_pwm->lp3943; -struct lp3943_pwm_map *pwm_map; +struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[hwpwm];int i, offset; - pwm_map =kzalloc (sizeof (*pwm_map),GFP_KERNEL ); -if (!pwm_map) -return ERR_PTR (-ENOMEM ); - pwm_map->output = pdata->pwms[hwpwm]->output; pwm_map->num_outputs = pdata->pwms[hwpwm]->num_outputs;
@@ -49,10 +46,8 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm) offset = pwm_map->output[i];/* Return an error if the pin is already assigned */ -if (test_and_set_bit (offset, &lp3943->pin_used)) { -kfree (pwm_map); +if (test_and_set_bit (offset, &lp3943->pin_used))return ERR_PTR (-EBUSY ); - } }return pwm_map;
@@ -67,7 +62,7 @@ static int lp3943_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)if (IS_ERR (pwm_map))return PTR_ERR (pwm_map); -return pwm_set_chip_data (pwm, pwm_map); +return 0 ; } static void lp3943_pwm_free_map(struct lp3943_pwm *lp3943_pwm,
@@ -80,14 +75,12 @@ static void lp3943_pwm_free_map(struct lp3943_pwm *lp3943_pwm, offset = pwm_map->output[i];clear_bit (offset, &lp3943->pin_used); } - -kfree (pwm_map); }static void lp3943_pwm_free (struct pwm_chip *chip,struct pwm_device *pwm) {struct lp3943_pwm *lp3943_pwm =to_lp3943_pwm (chip); -struct lp3943_pwm_map *pwm_map =pwm_get_chip_data (pwm); +struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm];lp3943_pwm_free_map (lp3943_pwm, pwm_map); }
@@ -154,7 +147,7 @@ static int lp3943_pwm_set_mode(struct lp3943_pwm *lp3943_pwm,static int lp3943_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) {struct lp3943_pwm *lp3943_pwm =to_lp3943_pwm (chip); -struct lp3943_pwm_map *pwm_map =pwm_get_chip_data (pwm); +struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm];u8 val;if (pwm->hwpwm ==0 )
@@ -173,7 +166,7 @@ static int lp3943_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)static void lp3943_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) {struct lp3943_pwm *lp3943_pwm =to_lp3943_pwm (chip); -struct lp3943_pwm_map *pwm_map =pwm_get_chip_data (pwm); +struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm];/* * LP3943 outputs are open-drain, so the pin should be configured
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1180/1848 pwm: lp3943: fix NULL pointer dereference for an unconfigured channel
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manush Prajwal <[email protected]>
[ Upstream commit 17dbb6938d3ab444cd6be1c95506450595a8800d ]
lp3943_pwm_probe() unconditionally registers a pwmchip with LP3943_NUM_PWMS(2) hwpwm channels, but lp3943_pwm_parse_dt() only populates pdata->pwms[i] for the channels whose ti,pwm0/ti,pwm1 property is actually present in the devicetree (the binding explicitly allows each PWM generator to drive zero or more outputs, and lp3943_pwm_parse_dt() only fails outright with -ENODATA if *neither* property is present). A devicetree that configures only one of the two channels leaves pdata->pwms[] NULL for the other.
lp3943_pwm_request_map() dereferences pdata->pwms[hwpwm] with no NULL check:
pwm_map->output = pdata->pwms[hwpwm]->output; pwm_map->num_outputs = pdata->pwms[hwpwm]->num_outputs;
so requesting the unconfigured channel (e.g. exporting it from sysfs) crashes with a NULL pointer dereference instead of failing cleanly.
Return -ENODEV from lp3943_pwm_request_map() when the channel was never configured, before the pointer is dereferenced. The caller, lp3943_pwm_request(), already propagates an ERR_PTR return correctly (it does so today for the existing -EBUSY case).
--- drivers/pwm/pwm-lp3943.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pwm/pwm-lp3943.c +3 -0
@@ -39,6 +39,9 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[hwpwm];int i, offset; +if (!pdata->pwms[hwpwm]) +return ERR_PTR (-ENODEV ); + pwm_map->output = pdata->pwms[hwpwm]->output; pwm_map->num_outputs = pdata->pwms[hwpwm]->num_outputs;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1181/1848 mtd: spinand: Fix spinand_manufacturer_ops kernel-doc
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 7e874b1750a40f3dc9a629aeb72eba09c77f77e9 ]
The kernel-doc heading for struct spinand_manufacturer_ops misspells and truncates its name as manufacurer_ops. As a result, kernel-doc cannot match the comment to the structure declaration.
Use the structure's actual name.
--- include/linux/mtd/spinand.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mtd/spinand.h +1 -1
@@ -208,7 +208,7 @@ struct spinand_devid { };/** -* struct manufacurer_ops - SPI NAND manufacturer specific operations +* struct spinand_manufacturer_ops - SPI NAND manufacturer specific operations * @init: initialize a SPI NAND device * @cleanup: cleanup a SPI NAND device *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1182/1848 dmaengine: sun6i: Do not use virt_to_phys
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Holland <[email protected]>
[ Upstream commit 9aa48806edb8c37e82532dbc6098b03f6bd4245e ]
This breaks on RISC-V, because dma_pool_alloc returns addresses which are not in the linear map. Instead, plumb through the physical address which is already known anyway.
Stable-dep-of: f472919f4c06 ("dmaengine: sun6i-dma: Fix use-after-free in error handling paths")
--- drivers/dma/sun6i-dma.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/dma/sun6i-dma.c +19 -19
@@ -241,9 +241,7 @@ static inline void sun6i_dma_dump_com_regs(struct sun6i_dma_dev *sdev)static inline void sun6i_dma_dump_chan_regs (struct sun6i_dma_dev *sdev,struct sun6i_pchan *pchan) { -phys_addr_t reg =virt_to_phys (pchan->base); - -dev_dbg (sdev->slave.dev,"Chan %d reg: %pa\n" +dev_dbg (sdev->slave.dev,"Chan %d reg:\n" "\t___en(%04x): \t0x%08x\n" "\tpause(%04x): \t0x%08x\n" "\tstart(%04x): \t0x%08x\n"
@@ -252,7 +250,7 @@ static inline void sun6i_dma_dump_chan_regs(struct sun6i_dma_dev *sdev,"\t__dst(%04x): \t0x%08x\n" "\tcount(%04x): \t0x%08x\n" "\t_para(%04x): \t0x%08x\n\n" , - pchan->idx, ®, + pchan->idx,DMA_CHAN_ENABLE ,readl (pchan->base +DMA_CHAN_ENABLE ), DMA_CHAN_PAUSE,
@@ -387,17 +385,16 @@ static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev, }static inline void sun6i_dma_dump_lli (struct sun6i_vchan *vchan, -struct sun6i_dma_lli *lli) +struct sun6i_dma_lli *v_lli, +dma_addr_t p_lli) { -phys_addr_t p_lli =virt_to_phys (lli); -dev_dbg (chan2dev (&vchan->vc.chan), -"\n\tdesc: p - %pa v - 0x%p\n" +"\n\tdesc:\tp - %pad v - 0x%p\n" "\t\tc - 0x%08x s - 0x%08x d - 0x%08x\n" "\t\tl - 0x%08x p - 0x%08x n - 0x%08x\n" , - &p_lli, lli, - lli->cfg, lli->src, lli->dst, - lli->len, lli->para, lli->p_lli_next); + &p_lli, v_lli, + v_lli->cfg, v_lli->src, v_lli->dst, + v_lli->len, v_lli->para, v_lli->p_lli_next); }static void sun6i_dma_free_desc (struct virt_dma_desc *vd)
@@ -447,7 +444,7 @@ static int sun6i_dma_start_desc(struct sun6i_vchan *vchan) pchan->desc =to_sun6i_desc (&desc->tx); pchan->done =NULL ; -sun6i_dma_dump_lli (vchan, pchan->desc->v_lli); +sun6i_dma_dump_lli (vchan, pchan->desc->v_lli, pchan->desc->p_lli); irq_reg = pchan->idx /DMA_IRQ_CHAN_NR ; irq_offset = pchan->idx %DMA_IRQ_CHAN_NR ;
@@ -672,7 +669,7 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(sun6i_dma_lli_add (NULL , v_lli, p_lli, txd); -sun6i_dma_dump_lli (vchan, v_lli); +sun6i_dma_dump_lli (vchan, v_lli, p_lli);return vchan_tx_prep (&vchan->vc, &txd->vd, flags);
@@ -748,14 +745,16 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg( }dev_dbg (chan2dev (chan),"First: %pad\n" , &txd->p_lli); -for (prev = txd->v_lli; prev; prev = prev->v_lli_next) -sun6i_dma_dump_lli (vchan, prev); +for (p_lli = txd->p_lli, v_lli = txd->v_lli; v_lli; + p_lli = v_lli->p_lli_next, v_lli = v_lli->v_lli_next) +sun6i_dma_dump_lli (vchan, v_lli, p_lli);return vchan_tx_prep (&vchan->vc, &txd->vd, flags); err_lli_free: -for (prev = txd->v_lli; prev; prev = prev->v_lli_next) -dma_pool_free (sdev->pool, prev,virt_to_phys (prev)); +for (p_lli = txd->p_lli, v_lli = txd->v_lli; v_lli; + p_lli = v_lli->p_lli_next, v_lli = v_lli->v_lli_next) +dma_pool_free (sdev->pool, v_lli, p_lli);kfree (txd);return NULL ; }
@@ -822,8 +821,9 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_cyclic(return vchan_tx_prep (&vchan->vc, &txd->vd, flags); err_lli_free: -for (prev = txd->v_lli; prev; prev = prev->v_lli_next) -dma_pool_free (sdev->pool, prev,virt_to_phys (prev)); +for (p_lli = txd->p_lli, v_lli = txd->v_lli; v_lli; + p_lli = v_lli->p_lli_next, v_lli = v_lli->v_lli_next) +dma_pool_free (sdev->pool, v_lli, p_lli);kfree (txd);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1183/1848 dmaengine: sun6i-dma: Fix use-after-free in error handling paths
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit f472919f4c0650d7fb22bb230eacaada0c6ee951 ]
In error handling paths, the for loop frees v_lli in the loop body, then accesses v_lli->v_lli_next and v_lli->p_lli_next in the increment expression, which is use-after-free.
Fix by refactoring the cleanup into a helper function sun6i_dma_free_desc() that saves both the next virtual and physical pointers before freeing the current node, preventing the use-after-free.
--- drivers/dma/sun6i-dma.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
drivers/dma/sun6i-dma.c +16 -15
@@ -397,16 +397,12 @@ static inline void sun6i_dma_dump_lli(struct sun6i_vchan *vchan, v_lli->len, v_lli->para, v_lli->p_lli_next); } -static void sun6i_dma_free_desc (struct virt_dma_desc *vd) +static void sun6i_dma_free_desc (struct sun6i_dma_dev *sdev, +struct sun6i_desc *txd) { -struct sun6i_desc *txd =to_sun6i_desc (&vd->tx); -struct sun6i_dma_dev *sdev =to_sun6i_dma_dev (vd->tx.chan->device);struct sun6i_dma_lli *v_lli, *v_next;dma_addr_t p_lli, p_next; -if (unlikely (!txd)) -return ; - p_lli = txd->p_lli; v_lli = txd->v_lli;
@@ -423,6 +419,17 @@ static void sun6i_dma_free_desc(struct virt_dma_desc *vd)kfree (txd); } +static void sun6i_dma_free_desc_virt (struct virt_dma_desc *vd) +{ +struct sun6i_desc *txd =to_sun6i_desc (&vd->tx); +struct sun6i_dma_dev *sdev =to_sun6i_dma_dev (vd->tx.chan->device); + +if (unlikely (!txd)) +return ; + +sun6i_dma_free_desc (sdev, txd); +} +static int sun6i_dma_start_desc (struct sun6i_vchan *vchan) {struct sun6i_dma_dev *sdev =to_sun6i_dma_dev (vchan->vc.chan.device);
@@ -752,10 +759,7 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_slave_sg(return vchan_tx_prep (&vchan->vc, &txd->vd, flags); err_lli_free: -for (p_lli = txd->p_lli, v_lli = txd->v_lli; v_lli; - p_lli = v_lli->p_lli_next, v_lli = v_lli->v_lli_next) -dma_pool_free (sdev->pool, v_lli, p_lli); -kfree (txd); +sun6i_dma_free_desc (sdev, txd);return NULL ; }
@@ -821,10 +825,7 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_cyclic(return vchan_tx_prep (&vchan->vc, &txd->vd, flags); err_lli_free: -for (p_lli = txd->p_lli, v_lli = txd->v_lli; v_lli; - p_lli = v_lli->p_lli_next, v_lli = v_lli->v_lli_next) -dma_pool_free (sdev->pool, v_lli, p_lli); -kfree (txd); +sun6i_dma_free_desc (sdev, txd);return NULL ; }
@@ -1354,7 +1355,7 @@ static int sun6i_dma_probe(struct platform_device *pdev)struct sun6i_vchan *vchan = &sdc->vchans[i];INIT_LIST_HEAD (&vchan->node); - vchan->vc.desc_free = sun6i_dma_free_desc; + vchan->vc.desc_free = sun6i_dma_free_desc_virt;vchan_init (&vchan->vc, &sdc->slave); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1184/1848 dmaengine: mediatek: hsdma: fix runtime PM leak on init failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit f10d96b1c549a2f43506e9bf847196839808b8dc ]
mtk_hsdma_hw_init() enables runtime PM and gets a runtime PM reference before enabling the HSDMA clock. It currently ignores failures from pm_runtime_get_sync(); if runtime resume fails, the usage count remains held. If clk_prepare_enable() then fails, the usage count remains held.
Use devm_pm_runtime_enable() to manage runtime PM enablement, and use pm_runtime_resume_and_get() so resume failures do not leak the usage count. If clk_prepare_enable() fails after a successful runtime resume, drop the runtime PM reference before returning.
The probe path also ignores the return value from mtk_hsdma_hw_init(), so a failed hardware init can continue as a successful probe. Propagate mtk_hsdma_hw_init() failures from probe, while keeping a separate unwind label so mtk_hsdma_hw_deinit() is only called after hardware init succeeds.
--- drivers/dma/mediatek/mtk-hsdma.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/dma/mediatek/mtk-hsdma.c +19 -7
@@ -849,17 +849,27 @@ static int mtk_hsdma_hw_init(struct mtk_hsdma_device *hsdma) {int err; -pm_runtime_enable (hsdma2dev (hsdma)); -pm_runtime_get_sync (hsdma2dev (hsdma)); + err =devm_pm_runtime_enable (hsdma2dev (hsdma)); +if (err) +return err; + + err =pm_runtime_resume_and_get (hsdma2dev (hsdma)); +if (err <0 ) +return err; err =clk_prepare_enable (hsdma->clk);if (err) -return err; + goto err_put_pm;mtk_dma_write (hsdma,MTK_HSDMA_INT_ENABLE ,0 );mtk_dma_write (hsdma,MTK_HSDMA_GLO ,MTK_HSDMA_GLO_DEFAULT );return 0 ; + +err_put_pm: +pm_runtime_put_sync (hsdma2dev (hsdma)); + +return err; }static int mtk_hsdma_hw_deinit (struct mtk_hsdma_device *hsdma)
@@ -869,7 +879,6 @@ static int mtk_hsdma_hw_deinit(struct mtk_hsdma_device *hsdma)clk_disable_unprepare (hsdma->clk);pm_runtime_put_sync (hsdma2dev (hsdma)); -pm_runtime_disable (hsdma2dev (hsdma));return 0 ; }
@@ -989,7 +998,9 @@ static int mtk_hsdma_probe(struct platform_device *pdev) goto err_unregister; } -mtk_hsdma_hw_init (hsdma); + err =mtk_hsdma_hw_init (hsdma); +if (err) + goto err_free; err = devm_request_irq(&pdev->dev, hsdma->irq, mtk_hsdma_irq, 0,
@@ -997,7 +1008,7 @@ static int mtk_hsdma_probe(struct platform_device *pdev)if (err) {dev_err (&pdev->dev,"request_irq failed with err %d\n" , err); - goto err_free; + goto err_deinit; }platform_set_drvdata (pdev, hsdma);
@@ -1006,8 +1017,9 @@ static int mtk_hsdma_probe(struct platform_device *pdev)return 0 ; -err_free: +err_deinit:mtk_hsdma_hw_deinit (hsdma); +err_free:of_dma_controller_free (pdev->dev.of_node); err_unregister:dma_async_device_unregister (dd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1185/1848 dmaengine: img-mdc: Fix runtime PM usage counter leak
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 4a1a2d8b8529cc569b769b92fcd71c53805cbeb2 ]
pm_runtime_get_sync() leaves the IMG MDC device's usage counter incremented when runtime resume fails. mdc_alloc_chan_resources() returns that error to the DMA core, so the channel's client count is not incremented and mdc_free_chan_resources() is not called to drop the reference. Repeated allocation attempts can therefore accumulate usage references and prevent runtime suspend.
Use pm_runtime_resume_and_get() so a failed resume does not retain a usage reference while successful allocations remain paired with mdc_free_chan_resources(). DMA core only treats negative return values as allocation failures, so the helper's zero success return preserves behavior.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/dma/img-mdc-dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/img-mdc-dma.c +1 -1
@@ -739,7 +739,7 @@ static int mdc_alloc_chan_resources(struct dma_chan *chan)struct mdc_chan *mchan =to_mdc_chan (chan);struct device *dev =mdma2dev (mchan->mdma); -return pm_runtime_get_sync (dev); +return pm_runtime_resume_and_get (dev); }static void mdc_free_chan_resources (struct dma_chan *chan)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1186/1848 dmaengine: zynqmp_dma: simplify with dev_err_probe
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Tretter <[email protected]>
[ Upstream commit 5637abaab994a933d7f00c95bc1456c7a58c83f4 ]
The clocks are provided by the ZynqMP firmware driver and are deferred until the firmware driver has probed. This leads to misleading error messages during probe of the zynqmp_dma driver.
Use dev_err_probe for printing errors during probe to avoid error messages for -EPROBE_DEFER.
Stable-dep-of: 0266dac57019 ("dmaengine: zynqmp_dma: Fix chan probe/remove error handling")
--- drivers/dma/xilinx/zynqmp_dma.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/dma/xilinx/zynqmp_dma.c +8 -10
@@ -1063,16 +1063,14 @@ static int zynqmp_dma_probe(struct platform_device *pdev) p->dev = &pdev->dev; zdev->clk_main =devm_clk_get (&pdev->dev,"clk_main" ); -if (IS_ERR (zdev->clk_main)) { -dev_err (&pdev->dev,"main clock not found.\n" ); -return PTR_ERR (zdev->clk_main); - } +if (IS_ERR (zdev->clk_main)) +return dev_err_probe (&pdev->dev,PTR_ERR (zdev->clk_main), +"main clock not found.\n" ); zdev->clk_apb =devm_clk_get (&pdev->dev,"clk_apb" ); -if (IS_ERR (zdev->clk_apb)) { -dev_err (&pdev->dev,"apb clock not found.\n" ); -return PTR_ERR (zdev->clk_apb); - } +if (IS_ERR (zdev->clk_apb)) +return dev_err_probe (&pdev->dev,PTR_ERR (zdev->clk_apb), +"apb clock not found.\n" );platform_set_drvdata (pdev, zdev);pm_runtime_set_autosuspend_delay (zdev->dev,ZDMA_PM_TIMEOUT );
@@ -1087,7 +1085,7 @@ static int zynqmp_dma_probe(struct platform_device *pdev) ret =zynqmp_dma_chan_probe (zdev, pdev);if (ret) { -dev_err (&pdev->dev,"Probing channel failed\n" ); +dev_err_probe (&pdev->dev, ret,"Probing channel failed\n" ); goto err_disable_pm; }
@@ -1099,7 +1097,7 @@ static int zynqmp_dma_probe(struct platform_device *pdev) ret =of_dma_controller_register (pdev->dev.of_node, of_zynqmp_dma_xlate, zdev);if (ret) { -dev_err (&pdev->dev,"Unable to register DMA to DT\n" ); +dev_err_probe (&pdev->dev, ret,"Unable to register DMA to DT\n" );dma_async_device_unregister (&zdev->common); goto free_chan_resources; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1187/1848 dmaengine: zynqmp_dma: Add support for AMD Versal Gen 2 DMA IP
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abin Joseph <[email protected]>
[ Upstream commit 13113f750a4ae0b1770fa25dc94852977ebfb942 ]
ZynqMP DMA IP and AMD Versal Gen 2 DMA IP are similar but have different interrupt register offset. Create a dedicated compatible string to support Versal Gen 2 DMA IP with Irq register offset for interrupt Enable/Disable/Status/Mask functionality.
Stable-dep-of: 0266dac57019 ("dmaengine: zynqmp_dma: Fix chan probe/remove error handling")
--- drivers/dma/xilinx/zynqmp_dma.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/dma/xilinx/zynqmp_dma.c +23 -4
@@ -24,10 +24,10 @@#include "../dmaengine.h" /* Register Offsets */ -#define ZYNQMP_DMA_ISR 0x100 -#define ZYNQMP_DMA_IMR 0x104 -#define ZYNQMP_DMA_IER 0x108 -#define ZYNQMP_DMA_IDS 0x10C +#define ZYNQMP_DMA_ISR (chan->irq_offset + 0x100) +#define ZYNQMP_DMA_IMR (chan->irq_offset + 0x104) +#define ZYNQMP_DMA_IER (chan->irq_offset + 0x108) +#define ZYNQMP_DMA_IDS (chan->irq_offset + 0x10c)#define ZYNQMP_DMA_CTRL0 0x110#define ZYNQMP_DMA_CTRL1 0x114#define ZYNQMP_DMA_DATA_ATTR 0x120
@@ -147,6 +147,9 @@#define tx_to_desc (tx) container_of(tx, struct zynqmp_dma_desc_sw, \ async_tx) +/* IRQ Register offset for Versal Gen 2 */ +#define IRQ_REG_OFFSET 0x308 +/** * struct zynqmp_dma_desc_ll - Hw linked list descriptor * @addr: Buffer address
@@ -213,6 +216,7 @@ struct zynqmp_dma_desc_sw {* @bus_width: Bus width * @src_burst_len: Source burst length * @dst_burst_len: Dest burst length +* @irq_offset: Irq register offset */ struct zynqmp_dma_chan {struct zynqmp_dma_device *zdev;
@@ -237,6 +241,7 @@ struct zynqmp_dma_chan {u32 bus_width;u32 src_burst_len;u32 dst_burst_len; +u32 irq_offset; };/**
@@ -255,6 +260,14 @@ struct zynqmp_dma_device {struct clk *clk_apb; }; +struct zynqmp_dma_config { +u32 offset; +}; + +static const struct zynqmp_dma_config versal2_dma_config = { + .offset =IRQ_REG_OFFSET , +}; +static inline void zynqmp_dma_writeq (struct zynqmp_dma_chan *chan,u32 reg,u64 value) {
@@ -879,6 +892,7 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev,struct zynqmp_dma_chan *chan;struct resource *res;struct device_node *node = pdev->dev.of_node; +const struct zynqmp_dma_config *match_data;int err; chan =devm_kzalloc (zdev->dev,sizeof (*chan),GFP_KERNEL );
@@ -907,6 +921,10 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev,return -EINVAL ; } + match_data =of_device_get_match_data (&pdev->dev); +if (match_data) + chan->irq_offset = match_data->offset; + chan->is_dmacoherent =of_property_read_bool (node,"dma-coherent" ); zdev->chan = chan;tasklet_setup (&chan->tasklet, zynqmp_dma_do_tasklet);
@@ -1140,6 +1158,7 @@ static int zynqmp_dma_remove(struct platform_device *pdev) }static const struct of_device_id zynqmp_dma_of_match[] = { + { .compatible ="amd,versal2-dma-1.0" , .data = &versal2_dma_config }, { .compatible ="xlnx,zynqmp-dma-1.0" , }, {} };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1188/1848 dmaengine: zynqmp_dma: Fix chan probe/remove error handling
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Golla Nagendra <[email protected]>
[ Upstream commit 0266dac57019201a14a81245d22750ab221d6c66 ]
Keep the real platform_get_irq() error by returning ret directly, stage IRQ setup via a local ret variable, and assign chan->irq only after devm_request_irq() succeeds.
Initialize chan->irq to -1 and initialize chan->common.device_node before it may be touched by teardown. In channel remove, free IRQ only for valid IRQ numbers and delete the channel node only when it is linked.
Register the channel node only after successful IRQ setup. On channel probe failure in zynqmp_dma_probe(), route cleanup through the existing free_chan_resources teardown path.
--- drivers/dma/xilinx/zynqmp_dma.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/dma/xilinx/zynqmp_dma.c +17 -11
@@ -207,7 +207,7 @@ struct zynqmp_dma_desc_sw {* @desc_pool_p: Physical allocated descriptor base * @desc_free_cnt: Descriptor available count * @dev: The dma device -* @irq: Channel IRQ +* @irq: Linux IRQ number, or -1 when not registered * @is_dmacoherent: Tells whether dma operations are coherent or not * @tasklet: Cleanup work after irq * @idle : Channel status;
@@ -873,10 +873,11 @@ static void zynqmp_dma_chan_remove(struct zynqmp_dma_chan *chan)if (!chan)return ; -if (chan->irq) +if (chan->irq >=0 )devm_free_irq (chan->zdev->dev, chan->irq, chan);tasklet_kill (&chan->tasklet); -list_del (&chan->common.device_node); +if (!list_empty (&chan->common.device_node)) +list_del (&chan->common.device_node); }/**
@@ -893,13 +894,14 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev,struct resource *res;struct device_node *node = pdev->dev.of_node;const struct zynqmp_dma_config *match_data; -int err; +int err, ret; chan =devm_kzalloc (zdev->dev,sizeof (*chan),GFP_KERNEL );if (!chan)return -ENOMEM ; chan->dev = zdev->dev; chan->zdev = zdev; + chan->irq =-1 ; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); chan->regs =devm_ioremap_resource (&pdev->dev, res);
@@ -933,22 +935,26 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev,INIT_LIST_HEAD (&chan->pending_list);INIT_LIST_HEAD (&chan->done_list);INIT_LIST_HEAD (&chan->free_list); +INIT_LIST_HEAD (&chan->common.device_node);dma_cookie_init (&chan->common); chan->common.device = &zdev->common; -list_add_tail (&chan->common.device_node, &zdev->common.channels); -zynqmp_dma_init (chan); - chan->irq =platform_get_irq (pdev,0 ); -if (chan->irq <0 ) -return -ENXIO ; - err =devm_request_irq (&pdev->dev, chan->irq, zynqmp_dma_irq_handler,0 , + ret =platform_get_irq (pdev,0 ); +if (ret <0 ) +return ret; + + err =devm_request_irq (&pdev->dev, ret, zynqmp_dma_irq_handler,0 ,"zynqmp-dma" , chan);if (err)return err; + chan->irq = ret; + chan->desc_size =sizeof (struct zynqmp_dma_desc_ll ); chan->idle = true; +list_add_tail (&chan->common.device_node, &zdev->common.channels); +return 0 ; }
@@ -1104,7 +1110,7 @@ static int zynqmp_dma_probe(struct platform_device *pdev) ret =zynqmp_dma_chan_probe (zdev, pdev);if (ret) {dev_err_probe (&pdev->dev, ret,"Probing channel failed\n" ); - goto err_disable_pm; + goto free_chan_resources; } p->dst_addr_widths =BIT (zdev->chan->bus_width /8 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1189/1848 dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Neeli <[email protected]>
[ Upstream commit b70ab341088b2114dcbc7be868588f3e97893e6a ]
The MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions, but the driver was using generic 'status' and 'sideband_status' fields for both. This led to incorrect residue calculations when the hardware updates direction-specific fields.
Refactor the descriptor structure to use unions with direction-specific field mappings, and update the residue calculation logic to select the correct status field based on DMA direction.
This matches the hardware descriptor layout and fixes incorrect residue reporting.
--- drivers/dma/xilinx/xilinx_dma.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +19 -7
@@ -217,6 +217,7 @@#define XILINX_MCDMA_IRQ_ERR_MASK BIT(7)#define XILINX_MCDMA_BD_EOP BIT(30)#define XILINX_MCDMA_BD_SOP BIT(31) +#define XILINX_MCDMA_BD_HW_SIZE 64/** * struct xilinx_vdma_desc_hw - Hardware Descriptor
@@ -271,8 +272,10 @@ struct xilinx_axidma_desc_hw {* @buf_addr_msb: MSB of Buffer address @0x0C * @rsvd: Reserved field @0x10 * @control: Control Information field @0x14 -* @status: Status field @0x18 -* @sideband_status: Status of sideband signals @0x1C +* @mm2s_ctrl_sideband: Sideband control info for mm2s @0x18 +* @s2mm_status: Status field for s2mm @0x18 +* @mm2s_status: Status field for mm2s @0x1C +* @s2mm_sideband_status: Sideband status for s2mm @0x1C * @app: APP Fields @0x20 - 0x30 */ struct xilinx_aximcdma_desc_hw {
@@ -282,10 +285,17 @@ struct xilinx_aximcdma_desc_hw {u32 buf_addr_msb;u32 rsvd;u32 control; -u32 status; -u32 sideband_status; +union { +u32 mm2s_ctrl_sideband; +u32 s2mm_status; + }; +union { +u32 mm2s_status; +u32 s2mm_sideband_status; + };u32 app[XILINX_DMA_NUM_APP_WORDS ]; }__aligned(64) ; +static_assert (sizeof (struct xilinx_aximcdma_desc_hw ) ==XILINX_MCDMA_BD_HW_SIZE );/** * struct xilinx_cdma_desc_hw - Hardware Descriptor
@@ -994,9 +1004,11 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw; - residue += - (aximcdma_hw->control & chan->xdev->max_buffer_len) - - (aximcdma_hw->status & chan->xdev->max_buffer_len); + residue += aximcdma_hw->control & chan->xdev->max_buffer_len; +if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len; +else + residue -= aximcdma_hw->mm2s_status & chan->xdev->max_buffer_len; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1190/1848 dmaengine: xilinx_dma: Freeup active list based on descriptor completion bit
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radhey Shyam Pandey <[email protected]>
[ Upstream commit 7bcdaa65810212c999d21e5c3019d03da37b3be3 ]
AXIDMA IP in SG mode sets completion bit to 1 when the transfer is completed. Read this bit to move descriptor from active list to the done list. This feature is needed when interrupt delay timeout and IRQThreshold is enabled i.e Dly_IrqEn is triggered w/o completing interrupt threshold.
Stable-dep-of: 5b585cc87781 ("dmaengine: xilinx_dma: Move descriptors to done list based on completion bit")
--- drivers/dma/xilinx/xilinx_dma.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/dma/xilinx/xilinx_dma.c +9 -0
@@ -180,6 +180,7 @@#define XILINX_DMA_CR_DELAY_SHIFT 24#define XILINX_DMA_BD_SOP BIT(27)#define XILINX_DMA_BD_EOP BIT(26) +#define XILINX_DMA_BD_COMP_MASK BIT(31)#define XILINX_DMA_COALESCE_MAX 255#define XILINX_DMA_NUM_DESCS 255#define XILINX_DMA_NUM_APP_WORDS 5
@@ -1717,6 +1718,14 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan)return ;list_for_each_entry_safe (desc, next, &chan->active_list, node) { +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +struct xilinx_axidma_tx_segment *seg; + + seg =list_last_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); +if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg) +break ; + }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA ) desc->residue =xilinx_dma_get_residue (chan, desc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1191/1848 dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Neeli <[email protected]>
[ Upstream commit 5b585cc8778185ae7a7c9903f8cd70d562b91282 ]
In AXI MCDMA, xilinx_dma_complete_descriptor() walks the channel's active_list and unconditionally moves every entry to the done_list. The MCDMA IOC interrupt handler invokes this function on every interrupt-on-completion, but with interrupt coalescing (IRQThreshold > 1) an IOC interrupt may fire after only a subset of the queued descriptors have actually been processed by the hardware. As a result, descriptors whose completion bit is not yet set in the BD status were being reported as completed to client drivers.
Add a check for the descriptor completion bit before moving entries from the active list to the done list, using the appropriate direction- specific status field (s2mm_status for DMA_DEV_TO_MEM, mm2s_status for DMA_MEM_TO_DEV).
This mirrors the AXIDMA fix in commit 7bcdaa658102 ("dmaengine:xilinx_dma: Freeup active list based on descriptor completion bit").
--- drivers/dma/xilinx/xilinx_dma.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/dma/xilinx/xilinx_dma.c +11 -0
@@ -1725,6 +1725,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ; + }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ; }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1192/1848 dmaengine: zynqmp_dma: drop redundant label
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vinod Koul <[email protected]>
[ Upstream commit 08f04d5ab868bc28d3115f7406499e8e5d1d1765 ]
Commit 3f30db282c28 ("dmaengine: zynqmp_dma: Fix chan probe/remove error handling") dropped the use of err_disable_pm label causing warning:
drivers/dma/xilinx/zynqmp_dma.c: In function ‘zynqmp_dma_probe’:drivers/dma/xilinx/zynqmp_dma.c:1171:1: error: label ‘err_disable_pm’ defined but not used [-Werror=unused-label]
1171 | err_disable_pm:
Drop it
--- drivers/dma/xilinx/zynqmp_dma.c | 1 - 1 file changed, 1 deletion(-)
drivers/dma/xilinx/zynqmp_dma.c +0 -1
@@ -1135,7 +1135,6 @@ static int zynqmp_dma_probe(struct platform_device *pdev) free_chan_resources:zynqmp_dma_chan_remove (zdev->chan); -err_disable_pm:if (!pm_runtime_enabled (zdev->dev))zynqmp_dma_runtime_suspend (zdev->dev);pm_runtime_disable (zdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1193/1848 ACPI: button: Add lid_init_state quirk for Razer Blade Stealth 13 (Early 2020) RZ09-0310
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Gallagher <[email protected]>
[ Upstream commit f16c512a07b954aa3b0b3c580e7abb5dd4f5e703 ]
This patch adds a quirk mapping for the "Blade Stealth 13 (Early 2020) - RZ09-0310" laptop, which exhibits the same issue as the following two related products already accounted for in this file.
- Razer Blade Stealth 13 Late 2019
- Blade Pro 17 (Early 2020) - RZ09-0329
Summary of the issue this fixes:
The firmware's _LID method still returns "closed" after resume when the lid was opened during S3, causing systemd-logind to suspend the system again within several seconds (15-40) after waking.
--- drivers/acpi/button.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/acpi/button.c +12 -0
@@ -135,6 +135,18 @@ static const struct dmi_system_id dmi_lid_quirks[] = { }, .driver_data = (void *)(long)ACPI_BUTTON_LID_INIT_OPEN, }, + { +/* +* Razer Blade Stealth 13 early 2020, when the lid is opened +* while suspended the open notification is lost and _LID keeps +* returning closed after resume, causing spurious re-suspends. +*/ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Razer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Blade Stealth 13 (Early 2020) - RZ09-0310"), + }, + .driver_data = (void *)(long)ACPI_BUTTON_LID_INIT_OPEN, + }, {/* * Samsung galaxybook2 ,initial _LID device notification returns
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1194/1848 ACPI: utils: Adjust message printing macros for ACPI objects
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 78ddbfaa72d68acc98cd5ba12eca071d452702c4 ]
The majority of acpi_handle_<level>() macros use neither pr_fmt() nor dev_fmt() and acpi_handle_debug() uses pr_fmt() like dev_fmt(), but only if dynamic debug is compiled in.
For more consistency, redefine all of the macros in question to use dev_fmt() because they are more similar to the analogous dev_*() family of macros than to the pr_*() ones and make all of them use it in the same way.
While at it, rephrase the comment documenting those macros for more clarity.
--- include/linux/acpi.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
include/linux/acpi.h +12 -12
@@ -1052,34 +1052,34 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#endif /* -* acpi_handle_<level>: Print message with ACPI prefix and object path +* acpi_handle_<level> - Print a message with ACPI prefix and object path * -* These interfaces acquire the global namespace mutex to obtain an object -* path. In interrupt context, it shows the object path as <n/a>. +* In thread context, the global namespace mutex is acquired to obtain the +* object path. In interrupt context, the object path is shown as <n/a>. */ #define acpi_handle_emerg (handle, fmt, ...) \ - acpi_handle_printk(KERN_EMERG, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_EMERG, handle, dev_fmt(fmt), ##__VA_ARGS__)#define acpi_handle_alert (handle, fmt, ...) \ - acpi_handle_printk(KERN_ALERT, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_ALERT, handle, dev_fmt(fmt), ##__VA_ARGS__)#define acpi_handle_crit (handle, fmt, ...) \ - acpi_handle_printk(KERN_CRIT, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_CRIT, handle, dev_fmt(fmt), ##__VA_ARGS__)#define acpi_handle_err (handle, fmt, ...) \ - acpi_handle_printk(KERN_ERR, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_ERR, handle, dev_fmt(fmt), ##__VA_ARGS__)#define acpi_handle_warn (handle, fmt, ...) \ - acpi_handle_printk(KERN_WARNING, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_WARNING, handle, dev_fmt(fmt), ##__VA_ARGS__)#define acpi_handle_notice (handle, fmt, ...) \ - acpi_handle_printk(KERN_NOTICE, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_NOTICE, handle, dev_fmt(fmt), ##__VA_ARGS__)#define acpi_handle_info (handle, fmt, ...) \ - acpi_handle_printk(KERN_INFO, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_INFO, handle, dev_fmt(fmt), ##__VA_ARGS__)#if defined(DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ - acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__) + acpi_handle_printk(KERN_DEBUG, handle, dev_fmt(fmt), ##__VA_ARGS__)#else #if defined(CONFIG_DYNAMIC_DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ _dynamic_func_call(fmt, __acpi_handle_debug, \ - handle, pr_fmt(fmt), ##__VA_ARGS__) + handle, dev_fmt(fmt), ##__VA_ARGS__)#else #define acpi_handle_debug (handle, fmt, ...) \ ({ \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1195/1848 wifi: ath11k: modify null check logic in ath11k_ce_rx_post_pipe()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Lobanov <[email protected]>
[ Upstream commit 52953d149ab4da0432d54b09f3c8add42b4d4a82 ]
The previous logic in ath11k_ce_rx_post_pipe() incorrectly required both dest_ring and status_ring to be NULL in order to exit the function. This caused the function to continue even if only one of the pointers was NULL, potentially leading to null pointer dereferences in ath11k_ce_rx_buf_enqueue_pipe().
Fix the condition by modifying the logic so that the function returns early if either dest_ring or status_ring is NULL.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/net/wireless/ath/ath11k/ce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ce.c +1 -1
@@ -263,7 +263,7 @@ static int ath11k_ce_rx_post_pipe(struct ath11k_ce_pipe *pipe)dma_addr_t paddr;int ret =0 ; -if (!(pipe->dest_ring || pipe->status_ring)) +if (!pipe->dest_ring || !pipe->status_ring)return 0 ;spin_lock_bh (&ab->ce.ce_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1196/1848 wifi: ath11k: fix locking problem in ath11k_dp_rx_tid_del_func()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Escande <[email protected]>
[ Upstream commit c7555d47b1d051e0406474349deccf74b491ae01 ]
In this function, we iterate over dp->reo_cmd_cache_flush_list using list_for_each_entry_safe(), under dp->reo_cmd_lock for concurrent access, and for each expired entries we :
- drop the lock
- call ath11k_dp_reo_cache_flush()
- kfree() the entry
- retake the lock to keep on iterating
list_for_each_entry_safe() protects us from deleting the entry during iteration but doesn't protect for concurrent access. So another thread can take the lock and modify the list in between and crash like below.
To fix the issue, move all entries that needs to be freed to a local list while under the lock and then iterate over the list to free the entries without holding the lock.
BUG: Unable to handle kernel paging request at virtual address 00000010ddbeef8c Call trace: ath11k_dp_rx_tid_del_func+0x164/0x3c8 ath11k_dp_process_reo_status+0x1d4/0x2fc ath11k_dp_service_srng+0x334/0x338 ath11k_pcic_ext_grp_napi_poll+0x30/0xc0 __napi_poll+0x34/0x184 napi_threaded_poll+0xb4/0x1d8 kthread+0xdc/0xe0 ret_from_fork+0x10/0x20
Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.9.0.1-01977-QCAHKSWPL_SILICONZ-1
--- drivers/net/wireless/ath/ath11k/dp_rx.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath11k/dp_rx.c +12 -7
@@ -729,6 +729,9 @@ static void ath11k_dp_rx_tid_del_func(struct ath11k_dp *dp, void *ctx,struct ath11k_base *ab = dp->ab;struct dp_rx_tid *rx_tid = ctx;struct dp_reo_cache_flush_elem *elem, *tmp; +struct list_head flush_list; + +INIT_LIST_HEAD (&flush_list);if (status ==HAL_REO_CMD_DRAIN ) { goto free_desc;
@@ -750,23 +753,25 @@ static void ath11k_dp_rx_tid_del_func(struct ath11k_dp *dp, void *ctx,list_add_tail (&elem->list, &dp->reo_cmd_cache_flush_list); dp->reo_cmd_cache_flush_count++; -/* Flush and invalidate aged REO desc from HW cache */ +/* identify aged REO desc that needs removal */ list_for_each_entry_safe (elem, tmp, &dp->reo_cmd_cache_flush_list, list) {if (dp->reo_cmd_cache_flush_count >DP_REO_DESC_FREE_THRESHOLD ||time_after (jiffies, elem->ts +msecs_to_jiffies (DP_REO_DESC_FREE_TIMEOUT_MS ))) { -list_del (&elem->list); +list_move_tail (&elem->list, &flush_list); dp->reo_cmd_cache_flush_count--; -spin_unlock_bh (&dp->reo_cmd_lock); - -ath11k_dp_reo_cache_flush (ab, &elem->data); -kfree (elem); -spin_lock_bh (&dp->reo_cmd_lock); } }spin_unlock_bh (&dp->reo_cmd_lock); +/* remove aged REO desc from HW */ +list_for_each_entry_safe (elem, tmp, &flush_list, list) { +ath11k_dp_reo_cache_flush (ab, &elem->data); +list_del (&elem->list); +kfree (elem); + } +return ; free_desc: dma_unmap_single(ab->dev, rx_tid->paddr, rx_tid->size,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1197/1848 power: supply: mp2629: Use the full batt_impedance_compensation name in the ABI document
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 1101833121a447999309a01f03d5b35bc1652e09 ]
drivers/power/supply/mp2629_charger.c creates the attribute with DEVICE_ATTR_RW(batt_impedance_compensation). The ABI file documents it under the truncated name batt_impedance_compen, which does not exist in sysfs.
Use the full name.
--- Documentation/ABI/testing/sysfs-class-power-mp2629 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-class-power-mp2629 +1 -1
@@ -1,4 +1,4 @@ -What: /sys/class/power_supply/mp2629_battery/batt_impedance_compen +What: /sys/class/power_supply/mp2629_battery/batt_impedance_compensation Date: April 2020 KernelVersion: 5.7 Description:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1198/1848 PM: wakeup: Unify device_init_wakeup() for PM_SLEEP and !PM_SLEEP
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Helgaas <[email protected]>
[ Upstream commit 09d3154a6f0f0bb5b604832095804780f3684b96 ]
Previously the CONFIG_PM_SLEEP and !CONFIG_PM_SLEEP device_init_wakeup() implementations differed in confusing ways:
- The PM_SLEEP version checked for a NULL device pointer and returned -EINVAL, while the !PM_SLEEP version did not and would simply dereference a NULL pointer.
- When called with "false", the !PM_SLEEP version cleared "capable" and "enable" in the opposite order of the PM_SLEEP version. That was harmless because for !PM_SLEEP they're simple assignments, but it's unnecessary confusion.
Use a simplified version of the PM_SLEEP implementation for both cases.
Stable-dep-of: ece9baab2a6e ("power: supply: bq24190_charger: use the wake irq API")
--- drivers/base/power/wakeup.c | 30 ------------------------------ include/linux/pm_wakeup.h | 31 +++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 38 deletions(-)
drivers/base/power/wakeup.c +0 -30
@@ -498,36 +498,6 @@ void device_set_wakeup_capable(struct device *dev, bool capable) }EXPORT_SYMBOL_GPL (device_set_wakeup_capable); -/** -* device_init_wakeup - Device wakeup initialization. -* @dev: Device to handle. -* @enable: Whether or not to enable @dev as a wakeup device. -* -* By default, most devices should leave wakeup disabled. The exceptions are -* devices that everyone expects to be wakeup sources: keyboards, power buttons, -* possibly network interfaces, etc. Also, devices that don't generate their -* own wakeup requests but merely forward requests from one bus to another -* (like PCI bridges) should have wakeup enabled by default. -*/ -int device_init_wakeup (struct device *dev,bool enable) -{ -int ret =0 ; - -if (!dev) -return -EINVAL ; - -if (enable) { -device_set_wakeup_capable (dev, true); - ret =device_wakeup_enable (dev); - }else { -device_wakeup_disable (dev); -device_set_wakeup_capable (dev, false); - } - -return ret; -} -EXPORT_SYMBOL_GPL (device_init_wakeup); -/** * device_set_wakeup_enable - Enable or disable a device to wake up the system. * @dev: Device to handle.
include/linux/pm_wakeup.h +23 -8
@@ -104,7 +104,6 @@ extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);extern int device_wakeup_enable (struct device *dev);extern int device_wakeup_disable (struct device *dev);extern void device_set_wakeup_capable (struct device *dev,bool capable); -extern int device_init_wakeup (struct device *dev,bool val);extern int device_set_wakeup_enable (struct device *dev,bool enable);extern void __pm_stay_awake (struct wakeup_source *ws);extern void pm_stay_awake (struct device *dev);
@@ -162,13 +161,6 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)return 0 ; } -static inline int device_init_wakeup (struct device *dev,bool val) -{ -device_set_wakeup_capable (dev, val); -device_set_wakeup_enable (dev, val); -return 0 ; -} -static inline bool device_may_wakeup (struct device *dev) {return dev->power.can_wakeup && dev->power.should_wakeup;
@@ -207,4 +199,27 @@ static inline void pm_wakeup_hard_event(struct device *dev) return pm_wakeup_dev_event(dev, 0, true); } +/** +* device_init_wakeup - Device wakeup initialization. +* @dev: Device to handle. +* @enable: Whether or not to enable @dev as a wakeup device. +* +* By default, most devices should leave wakeup disabled. The exceptions are +* devices that everyone expects to be wakeup sources: keyboards, power buttons, +* possibly network interfaces, etc. Also, devices that don't generate their +* own wakeup requests but merely forward requests from one bus to another +* (like PCI bridges) should have wakeup enabled by default. +*/ +static inline int device_init_wakeup (struct device *dev,bool enable) +{ +if (enable) { +device_set_wakeup_capable (dev, true); +return device_wakeup_enable (dev); + }else { +device_wakeup_disable (dev); +device_set_wakeup_capable (dev, false); +return 0 ; + } +} +#endif /* _LINUX_PM_WAKEUP_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1199/1848 PM: sleep: wakeirq: drop unused enable helpers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit e7b915219baa4b2bf30afe1dbaca7a24ff627ad2 ]
Drop the wake-irq enable and disable helpers which have not been used since commit bed570307ed7 ("PM / wakeirq: Fix dedicated wakeirq for drivers not using autosuspend").
Note that these functions are essentially just leftovers from the first iteration of the wake-irq implementation where device drivers were supposed to call these functions themselves instead of PM core (as is also indicated by the bogus kernel doc comments).
Stable-dep-of: ece9baab2a6e ("power: supply: bq24190_charger: use the wake irq API")
--- drivers/base/power/wakeirq.c | 49 ------------------------------------ include/linux/pm_wakeirq.h | 10 -------- 2 files changed, 59 deletions(-)
drivers/base/power/wakeirq.c +0 -49
@@ -200,7 +200,6 @@ static int __dev_pm_set_dedicated_wake_irq(struct device *dev, int irq, unsignedreturn err; } -/** * dev_pm_set_dedicated_wake_irq - Request a dedicated wake-up interrupt * @dev: Device entry
@@ -212,11 +211,6 @@ static int __dev_pm_set_dedicated_wake_irq(struct device *dev, int irq, unsigned* Sets up a threaded interrupt handler for a device that has * a dedicated wake-up interrupt in addition to the device IO * interrupt. -* -* The interrupt starts disabled, and needs to be managed for -* the device by the bus code or the device driver using -* dev_pm_enable_wake_irq*() and dev_pm_disable_wake_irq*() -* functions. */ int dev_pm_set_dedicated_wake_irq (struct device *dev,int irq) {
@@ -238,11 +232,6 @@ EXPORT_SYMBOL_GPL(dev_pm_set_dedicated_wake_irq);* the status of WAKE_IRQ_DEDICATED_REVERSE to tell rpm_suspend() * to enable dedicated wake-up interrupt after running the runtime suspend * callback for @dev. -* -* The interrupt starts disabled, and needs to be managed for -* the device by the bus code or the device driver using -* dev_pm_enable_wake_irq*() and dev_pm_disable_wake_irq*() -* functions. */ int dev_pm_set_dedicated_wake_irq_reverse (struct device *dev,int irq) {
@@ -250,44 +239,6 @@ int dev_pm_set_dedicated_wake_irq_reverse(struct device *dev, int irq) }EXPORT_SYMBOL_GPL (dev_pm_set_dedicated_wake_irq_reverse); -/** -* dev_pm_enable_wake_irq - Enable device wake-up interrupt -* @dev: Device -* -* Optionally called from the bus code or the device driver for -* runtime_resume() to override the PM runtime core managed wake-up -* interrupt handling to enable the wake-up interrupt. -* -* Note that for runtime_suspend()) the wake-up interrupts -* should be unconditionally enabled unlike for suspend() -* that is conditional. -*/ -void dev_pm_enable_wake_irq (struct device *dev) -{ -struct wake_irq *wirq = dev->power.wakeirq; - -if (wirq && (wirq->status &WAKE_IRQ_DEDICATED_ALLOCATED )) -enable_irq (wirq->irq); -} -EXPORT_SYMBOL_GPL (dev_pm_enable_wake_irq); - -/** -* dev_pm_disable_wake_irq - Disable device wake-up interrupt -* @dev: Device -* -* Optionally called from the bus code or the device driver for -* runtime_suspend() to override the PM runtime core managed wake-up -* interrupt handling to disable the wake-up interrupt. -*/ -void dev_pm_disable_wake_irq (struct device *dev) -{ -struct wake_irq *wirq = dev->power.wakeirq; - -if (wirq && (wirq->status &WAKE_IRQ_DEDICATED_ALLOCATED )) -disable_irq_nosync (wirq->irq); -} -EXPORT_SYMBOL_GPL (dev_pm_disable_wake_irq); -/** * dev_pm_enable_wake_irq_check - Checks and enables wake-up interrupt * @dev: Device
include/linux/pm_wakeirq.h +0 -10
@@ -20,8 +20,6 @@ extern int dev_pm_set_wake_irq(struct device *dev, int irq);extern int dev_pm_set_dedicated_wake_irq (struct device *dev,int irq);extern int dev_pm_set_dedicated_wake_irq_reverse (struct device *dev,int irq);extern void dev_pm_clear_wake_irq (struct device *dev); -extern void dev_pm_enable_wake_irq (struct device *dev); -extern void dev_pm_disable_wake_irq (struct device *dev);#else /* !CONFIG_PM */
@@ -44,13 +42,5 @@ static inline void dev_pm_clear_wake_irq(struct device *dev) { } -static inline void dev_pm_enable_wake_irq (struct device *dev) -{ -} - -static inline void dev_pm_disable_wake_irq (struct device *dev) -{ -} -#endif /* CONFIG_PM */ #endif /* _LINUX_PM_WAKEIRQ_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1200/1848 PM: wakeup: implement devm_device_init_wakeup() helper
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Hattori <[email protected]>
[ Upstream commit b317268368546d6401af788648668f82e3ba1bd3 ]
Some drivers that enable device wakeup fail to properly disable it during their cleanup, which results in a memory leak.
To address this, introduce devm_device_init_wakeup(), a managed variant of device_init_wakeup(dev, true).
With this managed helper, wakeup functionality will be automatically disabled when the device is released, ensuring a more reliable cleanup process.
This need for this addition arose during a previous discussion [1].
Stable-dep-of: ece9baab2a6e ("power: supply: bq24190_charger: use the wake irq API")
--- include/linux/pm_wakeup.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/linux/pm_wakeup.h +17 -0
@@ -222,4 +222,21 @@ static inline int device_init_wakeup(struct device *dev, bool enable) } } +static void device_disable_wakeup (void *dev) +{ +device_init_wakeup (dev, false); +} + +/** +* devm_device_init_wakeup - Resource managed device wakeup initialization. +* @dev: Device to handle. +* +* This function is the devm managed version of device_init_wakeup(dev, true). +*/ +static inline int devm_device_init_wakeup (struct device *dev) +{ +device_init_wakeup (dev, true); +return devm_add_action_or_reset (dev, device_disable_wakeup, dev); +} +#endif /* _LINUX_PM_WAKEUP_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1201/1848 PM: sleep: wakeirq: Introduce device-managed variant of dev_pm_set_wake_irq()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peng Fan <[email protected]>
[ Upstream commit fd8318a32573d73eb20637a0c80689de0dc98169 ]
Add device-managed variant of dev_pm_set_wake_irq which automatically clear the wake irq on device destruction to simplify error handling and resource management in drivers.
Stable-dep-of: ece9baab2a6e ("power: supply: bq24190_charger: use the wake irq API")
--- drivers/base/power/wakeirq.c | 26 ++++++++++++++++++++++++++ include/linux/pm_wakeirq.h | 6 ++++++ 2 files changed, 32 insertions(+)
drivers/base/power/wakeirq.c +26 -0
@@ -109,6 +109,32 @@ void dev_pm_clear_wake_irq(struct device *dev) }EXPORT_SYMBOL_GPL (dev_pm_clear_wake_irq); +static void devm_pm_clear_wake_irq (void *dev) +{ +dev_pm_clear_wake_irq (dev); +} + +/** +* devm_pm_set_wake_irq - device-managed variant of dev_pm_set_wake_irq +* @dev: Device entry +* @irq: Device IO interrupt +* +* +* Attach a device IO interrupt as a wake IRQ, same with dev_pm_set_wake_irq, +* but the device will be auto clear wake capability on driver detach. +*/ +int devm_pm_set_wake_irq (struct device *dev,int irq) +{ +int ret; + + ret =dev_pm_set_wake_irq (dev, irq); +if (ret) +return ret; + +return devm_add_action_or_reset (dev, devm_pm_clear_wake_irq, dev); +} +EXPORT_SYMBOL_GPL (devm_pm_set_wake_irq); +/** * handle_threaded_wake_irq - Handler for dedicated wake-up interrupts * @irq: Device specific dedicated wake-up interrupt
include/linux/pm_wakeirq.h +6 -0
@@ -20,6 +20,7 @@ extern int dev_pm_set_wake_irq(struct device *dev, int irq);extern int dev_pm_set_dedicated_wake_irq (struct device *dev,int irq);extern int dev_pm_set_dedicated_wake_irq_reverse (struct device *dev,int irq);extern void dev_pm_clear_wake_irq (struct device *dev); +extern int devm_pm_set_wake_irq (struct device *dev,int irq);#else /* !CONFIG_PM */
@@ -42,5 +43,10 @@ static inline void dev_pm_clear_wake_irq(struct device *dev) { } +static inline int devm_pm_set_wake_irq (struct device *dev,int irq) +{ +return 0 ; +} +#endif /* CONFIG_PM */ #endif /* _LINUX_PM_WAKEIRQ_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1202/1848 power: supply: bq24190_charger: use the wake irq API
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Brue <[email protected]>
[ Upstream commit ece9baab2a6e79224d3f591893be23b540b1625f ]
bq24190_probe() calls enable_irq_wake() on the charger interrupt and never calls disable_irq_wake(). That is wrong in three ways.
It is unbalanced. free_irq() does not touch desc->wake_depth -- only irq_set_irq_wake() does -- so after the driver is unbound the descriptor is still one wake reference deep and the irqchip is still configured for wake, forever, for an interrupt nobody owns any more.
It ignores the device's wakeup policy. The chip is made a system wake source whether or not anyone asked for it, and because device_init_wakeup() is never called there is no power/wakeup attribute for userspace to say otherwise. A board that would rather not be woken by its charger has no way to express that.
And it arms the interrupt for wake permanently, from probe onwards, rather than for the sleep it is meant to cover.
Use the wake irq API instead: devm_device_init_wakeup() to make the device wakeup-capable and enabled -- preserving today's behaviour -- and devm_pm_set_wake_irq() to hand the interrupt to the PM core, which arms it in dpm_suspend_noirq() (only if device_may_wakeup(), immediately before suspend_device_irqs()) and disarms it on resume. Both are unwound by devm, so the reference is balanced on unbind, and userspace gets the power/wakeup control it should have had.
No intended change in behaviour: charger events still wake the system by default.
The same conversion was made to another charger driver for the same reason, in commit 6c5393771c50 ("power: supply: qcom_pmi8998_charger: fix wakeirq").
--- drivers/power/supply/bq24190_charger.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/power/supply/bq24190_charger.c +8 -1
@@ -11,6 +11,7 @@#include <linux/of_irq.h> #include <linux/of_device.h> #include <linux/pm_runtime.h> +#include <linux/pm_wakeirq.h> #include <linux/power_supply.h> #include <linux/power/bq24190_charger.h> #include <linux/regulator/driver.h>
@@ -1821,7 +1822,13 @@ static int bq24190_probe(struct i2c_client *client,if (ret <0 ) goto out_charger; -enable_irq_wake (client->irq); + ret =devm_device_init_wakeup (dev); +if (ret <0 ) + goto out_charger; + + ret =devm_pm_set_wake_irq (dev, client->irq); +if (ret <0 ) + goto out_charger;pm_runtime_mark_last_busy (dev);pm_runtime_put_autosuspend (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1203/1848 power: supply: bq2515x: Propagate charge-enable read errors
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
[ Upstream commit 4a35810a847411c466a15d1737d11e8e818dc197 ]
bq2515x_get_charge_disable() returns bool even though reading the charger-disable state can fail. A negative error is therefore converted to true, so POWER_SUPPLY_PROP_STATUS reports NOT_CHARGING with success instead of propagating the failure. The GPIO read is not checked for errors either.
Return an int from the helper, check both reads, and only convert a valid charger-disable state to the charging-status boolean.
--- drivers/power/supply/bq2515x_charger.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/power/supply/bq2515x_charger.c +9 -6
@@ -415,7 +415,7 @@ static int bq2515x_get_battery_current_now(struct bq2515x_device *bq2515x) BQ2515X_ICHG_DIVISOR); } -static bool bq2515x_get_charge_disable (struct bq2515x_device *bq2515x) +static int bq2515x_get_charge_disable (struct bq2515x_device *bq2515x) {int ret;int ce_pin;
@@ -423,6 +423,8 @@ static bool bq2515x_get_charge_disable(struct bq2515x_device *bq2515x)int charger_disable; ce_pin =gpiod_get_value_cansleep (bq2515x->ce_gpio); +if (ce_pin <0 ) +return ce_pin; ret =regmap_read (bq2515x->regmap,BQ2515X_ICCTRL2 , &icctrl2);if (ret)
@@ -430,10 +432,7 @@ static bool bq2515x_get_charge_disable(struct bq2515x_device *bq2515x) charger_disable = icctrl2 &BQ2515X_CHARGER_DISABLE ; -if (charger_disable || ce_pin) -return true; - -return false; +return charger_disable || ce_pin; }static int bq2515x_set_charge_disable (struct bq2515x_device *bq2515x,int val)
@@ -610,7 +609,11 @@ static int bq2515x_charging_status(struct bq2515x_device *bq2515x,else status1_no_fault = false; - ce_status = (!bq2515x_get_charge_disable (bq2515x)); + ret =bq2515x_get_charge_disable (bq2515x); +if (ret <0 ) +return ret; + + ce_status = !ret;/* * If there are no faults and charging is enabled, then status is
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1204/1848 iio: imu: adis16400: Check return value of spi_setup()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
[ Upstream commit a7c07602e00596a45de8a4a700af96392953ed38 ]
In adis16400_initial_setup(), the return value of spi_setup() was ignored. If SPI configuration fails, the driver would proceed with the initialization anyway, leading to undefined behavior or silent failures during device setup.
Check the return value of spi_setup() and return the error code immediately if it fails.
--- drivers/iio/imu/adis16400.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/imu/adis16400.c +4 -1
@@ -450,7 +450,10 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev)else st->adis.spi->max_speed_hz =ADIS16400_SPI_FAST ; st->adis.spi->mode =SPI_MODE_3 ; -spi_setup (st->adis.spi); + + ret =spi_setup (st->adis.spi); +if (ret) +return ret; ret =adis_initial_startup (&st->adis);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1205/1848 efi/libstub: Fix efi_set_event_at() parameter documentation
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit c12a3a4b35e47fd511fbd550d3637318be41c4eb ]
efi_set_event_at() documents ids although its array index argument is named idx. This produces missing and excess parameter warnings.
Match the argument name and fix the adjacent spelling of array.
--- drivers/firmware/efi/libstub/efistub.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/efistub.h +2 -2
@@ -181,8 +181,8 @@ typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);* efi_set_event_at() - add event to events array * * @events: array of UEFI events -* @ids: index where to put the event in the array -* @event: event to add to the aray +* @idx: index where to put the event in the array +* @event: event to add to the array * * boottime->wait_for_event() takes an array of events as input. * Provide a helper to set it up correctly for mixed mode.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1206/1848 PCI: xgene: Use managed clock for PCIe controller
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit b9022584ebbae81f7bbe4a61bd1df0d0a95e1a99 ]
xgene_pcie_init_port() obtains and enables the controller clock manually. When xgene_pcie_setup() or pci_host_probe() fails, probe returns without disabling, unpreparing, or releasing the clock. A failed enable also leaves the clk_get() reference unreleased.
Use devm_clk_get_enabled() so the clock is unwound automatically on probe failure and device removal.
--- drivers/pci/controller/pci-xgene.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/pci/controller/pci-xgene.c +2 -9
@@ -327,18 +327,11 @@ static void xgene_pcie_linkup(struct xgene_pcie_port *port,static int xgene_pcie_init_port (struct xgene_pcie_port *port) {struct device *dev = port->dev; -int rc; - port->clk =clk_get (dev,NULL ); + port->clk =devm_clk_get_enabled (dev,NULL );if (IS_ERR (port->clk)) {dev_err (dev,"clock not available\n" ); -return -ENODEV ; - } - - rc =clk_prepare_enable (port->clk); -if (rc) { -dev_err (dev,"clock enable failed\n" ); -return rc; +return PTR_ERR (port->clk); }return 0 ;
Signature · 1 line
2.53.0