6.18.65-rc1 review
Greg Kroah-Hartman
maintainerPATCH 1605/2151 ext4: fix orig_mlen initialization in ext4_map_blocks()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yi <[email protected]>
[ Upstream commit 3ec0eefc07cb9e2bb1193f1fa3d8157302a737f5 ]
Save orig_mlen after clamping map->m_len to INT_MAX. Otherwise, the unclamped value may be passed below, bypassing its overflow protection.
--- fs/ext4/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/inode.c +2 -1
@@ -702,7 +702,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,struct extent_status es;int retval;int ret =0 ; -unsigned int orig_mlen = map->m_len; +unsigned int orig_mlen;#ifdef ES_AGGRESSIVE_TEST struct ext4_map_blocks orig_map;
@@ -718,6 +718,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,*/ if (unlikely (map->m_len >INT_MAX )) map->m_len =INT_MAX ; + orig_mlen = map->m_len;/* We can handle the block number less than EXT_MAX_BLOCKS */ if (unlikely (map->m_lblk >=EXT_MAX_BLOCKS ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1606/2151 ASoC: rt5645: Shut down the button timer on removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit f0ecc305442f20a6df2575943e9897825d80cc5d ]
jack_detect_work can rearm btn_check_timer, and the timer callback can queue jack_detect_work. Deleting the timer before cancelling the work does not break this cycle: an already running worker can rearm the timer after timer_delete_sync() returns. The timer can then outlive removal.
Use timer_shutdown_sync() before cancelling the delayed work so that subsequent attempts to rearm the timer are ignored. The IRQ producer has already been removed at this point. Keep the restartable timer deletion in the suspend path.
This issue was identified as part of our ongoing research while reviewing kernel code.
--- sound/soc/codecs/rt5645.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
sound/soc/codecs/rt5645.c +4 -3
@@ -18,6 +18,7 @@#include <linux/acpi.h> #include <linux/dmi.h> #include <linux/regulator/consumer.h> +#include <linux/timer.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h>
@@ -4289,10 +4290,10 @@ static void rt5645_i2c_remove(struct i2c_client *i2c)free_irq (i2c->irq, rt5645);/* -* Since the rt5645_btn_check_callback() can queue jack_detect_work, -* the timer need to be delted first +* The timer and jack_detect_work can rearm each other. Shut down the +* timer before cancelling the work. */ -timer_delete_sync (&rt5645->btn_check_timer); +timer_shutdown_sync (&rt5645->btn_check_timer);cancel_delayed_work_sync (&rt5645->jack_detect_work);cancel_delayed_work_sync (&rt5645->rcclock_work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1607/2151 selftests/ftrace: Avoid unlink error on first run
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaewon Jung <[email protected]>
[ Upstream commit 0abfa9ad5c6917cb9a509276f32009d944b3c269 ]
On the first run, ftracetest tries to unlink a symlink that does not exist.
Use rm -f to avoid the "No such file or directory" error.
--- tools/testing/selftests/ftrace/ftracetest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/ftracetest +1 -1
@@ -223,7 +223,7 @@ else mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" date > $LOG_FILE if [ "x-$LINK_PTR" != "x-" ]; then - unlink $LINK_PTR + rm -f $LINK_PTR ln -fs $LOG_DATE $LINK_PTR fi fi
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1608/2151 vdso/math64: Add and use __iter_div64_u64_rem()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit dcd65074e2c593a06bed36178bba6d49d6b6883c ]
The vDSO basetimes for CLOCK_MONOTONIC and CLOCK_BOOTTIME are stored in the scaled nanoseconds of tkr_mono, so normalising them requires a division by NSEC_PER_SEC << shift. That divisor does not fit the u32 parameter of __iter_div_u64_rem(), so update_vdso_time_data() open-codes the same iterative division twice.
Repeated subtraction is the appropriate form at these two sites because the quotient never exceeds one. accumulate_nsecs_to_secs() keeps xtime_nsec below one scaled second, and the offset added to it is a normalised timespec64 fraction, so the dividend stays below twice the divisor. That bound holds on every architecture, which matters more here than the cost of a division on any particular one.
Add __iter_div64_u64_rem(), the u64-divisor counterpart of __iter_div_u64_rem(), and use it at both sites. Return the quotient as a u32 for consistency with the u32-divisor variant; the bound above leaves no use for a wider type.
Store the remainder directly into the basetime, as the coarse clocks already do. The CLOCK_BOOTTIME copy of the CLOCK_MONOTONIC values then takes both fields from the same place.
Folding the two open-coded loops into one inlined helper removes 16 bytes of vsyscall.o text on x86-64 with gcc 13.
No functional change.
Stable-dep-of: 8d17190fae2c ("vdso/vsyscall: Keep the CLOCK_AUX base scaled")
--- include/vdso/math64.h | 20 ++++++++++++++++++++ kernel/time/vsyscall.c | 16 +++++----------- 2 files changed, 25 insertions(+), 11 deletions(-)
include/vdso/math64.h +20 -0
@@ -21,6 +21,26 @@ __iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)return ret; } +static __always_inline u32 __iter_div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) +{ +u32 ret =0 ; + +while (dividend >= divisor) { +/* +* Prevent the compiler from optimising this loop into a +* modulo operation. +*/ +OPTIMIZER_HIDE_VAR (dividend); + + dividend -= divisor; + ret++; + } + + *remainder = dividend; + +return ret; +} +#if defined(CONFIG_ARCH_SUPPORTS_INT128 ) && defined(__SIZEOF_INT128__)#ifndef mul_u64_u32_add_u64_shr
kernel/time/vsyscall.c +5 -11
@@ -41,14 +41,12 @@ static inline void update_vdso_time_data(struct vdso_time_data *vdata, struct ti nsec = tk->tkr_mono.xtime_nsec; nsec += ((u64 )tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift); -while (nsec >= (((u64 )NSEC_PER_SEC ) << tk->tkr_mono.shift)) { - nsec -= (((u64 )NSEC_PER_SEC ) << tk->tkr_mono.shift); - vdso_ts->sec++; - } - vdso_ts->nsec = nsec; + vdso_ts->sec +=__iter_div64_u64_rem (nsec, (u64 )NSEC_PER_SEC << tk->tkr_mono.shift, + &vdso_ts->nsec);/* Copy MONOTONIC time for BOOTTIME */ sec = vdso_ts->sec; + nsec = vdso_ts->nsec;/* Add the boot offset */ sec += tk->monotonic_to_boot.tv_sec; nsec += (u64 )tk->monotonic_to_boot.tv_nsec << tk->tkr_mono.shift;
@@ -56,12 +54,8 @@ static inline void update_vdso_time_data(struct vdso_time_data *vdata, struct ti/* CLOCK_BOOTTIME */ vdso_ts = &vc[CS_HRES_COARSE ].basetime[CLOCK_BOOTTIME ]; vdso_ts->sec = sec; - -while (nsec >= (((u64 )NSEC_PER_SEC ) << tk->tkr_mono.shift)) { - nsec -= (((u64 )NSEC_PER_SEC ) << tk->tkr_mono.shift); - vdso_ts->sec++; - } - vdso_ts->nsec = nsec; + vdso_ts->sec +=__iter_div64_u64_rem (nsec, (u64 )NSEC_PER_SEC << tk->tkr_mono.shift, + &vdso_ts->nsec);/* CLOCK_MONOTONIC_RAW */ vdso_ts = &vc[CS_RAW ].basetime[CLOCK_MONOTONIC_RAW ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1609/2151 vdso/vsyscall: Keep the CLOCK_AUX base scaled
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 8d17190fae2caab89cd5df19257ed9dac0739e3b ]
The vDSO basetime of a clock is stored in the scaled nanoseconds of tkr_mono, so that the reader can floor the base and the cycle delta together in vdso_calc_ns().
vdso_time_update_aux() instead shifts the base down to nanoseconds, adds the offset, and shifts it back up, which zeroes the fractional nanoseconds of xtime_nsec. The reader then floors the base and the delta separately:
ktime_get_aux(): base + ((delta * mult + xtime_nsec) >> shift)
vdso: base + (xtime_nsec >> shift)
+ ((delta * mult) >> shift)
Since floor(a) + floor(b) <= floor(a + b), the vDSO reports 0 or 1 ns below the syscall for the same clock. It is not a monotonicity problem:
across an update the step is floor(a + d) - floor(a) - floor(d), which is 0 or 1, never negative.
Add the offset in scaled nanoseconds as the other high resolution clocks do, and normalise with __iter_div64_u64_rem() so that the stored base stays below one second and the userspace fast-path does not iterate more in __iter_div_u64_rem().
Only the sub-second field changes. (a + (b << shift)) >> shift is exactly (a >> shift) + b, so the seconds carried out of the normalisation are the same as before; what the old form dropped was the low shift bits of the remainder.
monotonic_to_aux.tv_nsec is a normalised timespec64 fraction, so it stays below NSEC_PER_SEC even for a negative offset, and the sum stays below 2 * (NSEC_PER_SEC << shift). The largest shift clocks_calc_mult_shift() can pick is 32, which makes that 8.6e18 against a u64 limit of 1.8e19.
--- kernel/time/vsyscall.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/time/vsyscall.c +5 -5
@@ -155,11 +155,11 @@ void vdso_time_update_aux(struct timekeeper *tk) vdso_ts->sec = tk->xtime_sec + tk->monotonic_to_aux.tv_sec; - nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift; - nsec += tk->monotonic_to_aux.tv_nsec; - vdso_ts->sec +=__iter_div_u64_rem (nsec,NSEC_PER_SEC , &nsec); - nsec = nsec << tk->tkr_mono.shift; - vdso_ts->nsec = nsec; + nsec = tk->tkr_mono.xtime_nsec; + nsec += (u64 )tk->monotonic_to_aux.tv_nsec << tk->tkr_mono.shift; + vdso_ts->sec +=__iter_div64_u64_rem (nsec, + (u64 )NSEC_PER_SEC << tk->tkr_mono.shift, + &vdso_ts->nsec); }__arch_update_vdso_clock (vc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1610/2151 selftests/bpf: Create the vxlan devices of test_tunnel with their MAC
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 33cbc5c2cadfe3b43f024e89880dd8fe2efb3a2e ]
The vxlan tests of test_tunnel create a tunnel device in the initial netns with "ip link add", and then give it the MAC address that the static neighbor entry at the other end points to with "ip link set".
systemd-udevd assigns new devices of the initial netns a MAC address of its own, following its MACAddressPolicy, when it handles their uevent. When it gets to that after the test set the address, the replies sent to the configured MAC are dropped as meant for another host, and the ping of vxlan_tunnel fails after 10 seconds.
Pass the address to "ip link add". udevd leaves alone the address of a device that was created with one.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +6 -7
@@ -161,9 +161,9 @@ static int add_vxlan_tunnel(void) IP4_ADDR2_VETH1, MAC_VETH1);/* root namespace */ -SYS (fail,"ip link add dev %s type vxlan external gbp dstport 4789" , -VXLAN_TUNL_DEV1 ); -SYS (fail,"ip link set dev %s address %s up" ,VXLAN_TUNL_DEV1 ,MAC_TUNL_DEV1 ); +SYS (fail,"ip link add dev %s address %s type vxlan external gbp dstport 4789" , +VXLAN_TUNL_DEV1 ,MAC_TUNL_DEV1 ); +SYS (fail,"ip link set dev %s up" ,VXLAN_TUNL_DEV1 );SYS (fail,"ip addr add dev %s %s/24" ,VXLAN_TUNL_DEV1 ,IP4_ADDR_TUNL_DEV1 );SYS (fail,"ip neigh add %s lladdr %s dev %s" ,IP4_ADDR_TUNL_DEV0 ,MAC_TUNL_DEV0 ,VXLAN_TUNL_DEV1 );
@@ -198,11 +198,10 @@ static int add_ip6vxlan_tunnel(void) IP6VXLAN_TUNL_DEV0, MAC_TUNL_DEV0);/* root namespace */ -SYS (fail,"ip link add dev %s type vxlan external dstport 4789" , -IP6VXLAN_TUNL_DEV1 ); -SYS (fail,"ip addr add dev %s %s/24" ,IP6VXLAN_TUNL_DEV1 ,IP4_ADDR_TUNL_DEV1 ); -SYS (fail,"ip link set dev %s address %s up" , +SYS (fail,"ip link add dev %s address %s type vxlan external dstport 4789" ,IP6VXLAN_TUNL_DEV1 ,MAC_TUNL_DEV1 ); +SYS (fail,"ip addr add dev %s %s/24" ,IP6VXLAN_TUNL_DEV1 ,IP4_ADDR_TUNL_DEV1 ); +SYS (fail,"ip link set dev %s up" ,IP6VXLAN_TUNL_DEV1 );return 0 ; fail:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1611/2151 ALSA: core: Serialize snd_refcount put and sync
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 6904743ab77e0684dff319f3806ef982e5eea6cf ]
When a thread tries to sync-and-destroy the resource with snd_refcount_sync(), it might lead to a UAF in a very slight time window. Namely, snd_refount_put() calls wake_up() after atomic_dec_and_test(), but wait_event() in snd_refcount_sync() checks the condition via atomic_test() without serialization, hence the thread that called snd_refcount_sync() can continue immediately to release the resource before another thread calls wake_up().
For avoiding the race above, introduce the spinlock and take it at snd_refcount_put() and snd_refcount_sync() in order to serialize the operations.
--- include/sound/core.h | 1 + sound/core/misc.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
include/sound/core.h +1 -0
@@ -84,6 +84,7 @@ struct snd_device {struct snd_refcount {atomic_t count;wait_queue_head_t waiter; +spinlock_t lock; };void snd_refcount_init (struct snd_refcount *ref);
sound/core/misc.c +4 -1
@@ -183,11 +183,13 @@ void snd_refcount_init(struct snd_refcount *ref) {atomic_set (&ref->count,0 );init_waitqueue_head (&ref->waiter); +spin_lock_init (&ref->lock); }EXPORT_SYMBOL_GPL (snd_refcount_init);void snd_refcount_put (struct snd_refcount *ref) { +guard (spinlock_irqsave)(&ref->lock);if (atomic_dec_and_test (&ref->count))wake_up (&ref->waiter); }
@@ -195,6 +197,7 @@ EXPORT_SYMBOL_GPL(snd_refcount_put);void snd_refcount_sync (struct snd_refcount *ref) { -wait_event (ref->waiter, !atomic_read (&ref->count)); +guard (spinlock_irq)(&ref->lock); +wait_event_lock_irq (ref->waiter, !atomic_read (&ref->count), ref->lock); }EXPORT_SYMBOL_GPL (snd_refcount_sync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1612/2151 selftests/bpf: Accept unnamed dma-bufs in the dmabuf_iter default test
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 653b8f14fdda385bd7c5b786f8dfdcc3e5599e27 ]
The dmabuf_collector iterator prints the inode, size, name and exporter of every dma-buf in the system on separate lines, with an empty name for the buffers that have none. The default_iter subtest parses that output and looks for the two buffers it created.
It requires a name for every buffer, and sscanf() finds none on the empty line of an unnamed one. On a system that has such a buffer, like one exported by udmabuf without a name, the subtest fails before it gets to its own buffers.
Take an empty name for a buffer without one.
--- tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c +3 -2
@@ -188,8 +188,9 @@ static void subtest_dmabuf_iter_check_default_iter(struct dmabuf_iter *skel)ASSERT_EQ (sscanf (line,"%ld" , &bufinfo.size),1 ,"read size" ); }else if (f %FIELD_COUNT ==NAME ) { -ASSERT_EQ (sscanf (line,"%s" , bufinfo.name),1 , -"read name" ); +/* Keep an empty name for a buffer without one */ +if (sscanf (line,"%s" , bufinfo.name) !=1 ) + bufinfo.name[0 ] ='\0' ; }else if (f %FIELD_COUNT ==EXPORTER ) {ASSERT_EQ (sscanf (line,"%31s" , bufinfo.exporter),1 ,"read exporter" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1613/2151 kselftest/arm64: signal: copy each test binary only once
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 7b3b147c4104f8211ad356a78cff9a2dcd966312 ]
The signal tests are built in testcases/ and then copied to the output directory. The copy rule lists every generated program as a target and copies all of them in each recipe:
$(TEST_GEN_PROGS): $(PROGS)
cp $(PROGS) $(OUTPUT)/In a parallel build make runs that recipe once for each program, so several cp processes write the same destination files at the same time. cp then fails with "cannot create regular file ...: File exists", which fails the arm64 build even though every test compiled. A cross build of the arm64 signal tests at -j8 hit this in all of 8 runs.
Use a static pattern rule so that each output depends on, and copies, only its own binary.
--- tools/testing/selftests/arm64/signal/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/arm64/signal/Makefile +2 -2
@@ -17,8 +17,8 @@ TEST_GEN_PROGS := $(notdir $(PROGS)) # the toplevel makefile include ../../lib.mk -$(TEST_GEN_PROGS): $(PROGS) - cp $(PROGS) $(OUTPUT)/ +$(TEST_GEN_PROGS): $(OUTPUT)/%: testcases/% + cp $< $@ # Common test-unit targets to build common-layout test-cases executables # Needs secondary expansion to properly include the testcase c-file in pre-reqs
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1614/2151 IB/rdmavt: Fix error unwind path for qp_priv_init() in rvt_create_qp()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit dd36137b218ad6f18ed15e6279412d7fc160980c ]
If driver_f.qp_priv_init() fails, execution jumps to bail_rq_wq, which bypasses bail_qpn. Because alloc_qpn() has already succeeded at this point, the allocated QP number is left unreleased.
Jump to bail_qpn instead to ensure the QPN is properly freed via rvt_free_qpn().
--- drivers/infiniband/sw/rdmavt/qp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/qp.c +1 -1
@@ -1173,7 +1173,7 @@ int rvt_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr,if (rdi->driver_f.qp_priv_init) { ret = rdi->driver_f.qp_priv_init (rdi, qp, init_attr);if (ret) - goto bail_rq_wq; + goto bail_qpn; }break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1615/2151 RDMA/irdma: Fix FRWR IRDMAQPSQ_PBLADDR field population
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Moroni <[email protected]>
[ Upstream commit 59df57262e6fa9e6f4aa76d6d324134777c702a0 ]
Previously, the IRDMAQPSQ_PBLADDR FRWR WQE field was being populated using a mask that was right-shifted, whereas it should have been the address being right-shifted.
This ended up working fine in many cases because the lowermost 12 bits are always zero (the addresses are page aligned) and the uppermost 12 bits are usually zero too, but it could break for DMA addresses that are wider than 52 bits.
Fix this by right-shifting the address instead of the mask, similar to how it was done in the original i40iw driver.
Tested with NFS over RDMA with some added debug logs to ensure it was hitting both the direct (single page) path as well as multi page (< 512).
--- drivers/infiniband/hw/irdma/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/irdma/ctrl.c +1 -1
@@ -1729,7 +1729,7 @@ int irdma_sc_mr_fast_register(struct irdma_sc_qp *qp, info->first_pm_pbl_index >> 16);set_64bit_val (wqe,8 ,FIELD_PREP (IRDMAQPSQ_FIRSTPMPBLIDXHI , temp) | -FIELD_PREP (IRDMAQPSQ_PBLADDR >>IRDMA_HW_PAGE_SHIFT , info->reg_addr_pa)); +FIELD_PREP (IRDMAQPSQ_PBLADDR , info->reg_addr_pa >>IRDMA_HW_PAGE_SHIFT ));set_64bit_val (wqe,16 , info->total_len |FIELD_PREP (IRDMAQPSQ_FIRSTPMPBLIDXLO , info->first_pm_pbl_index));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1616/2151 ASoC: Intel: avs: Unprepare a stream when recovery occurs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 85bc213f96ac03d74a3e531968c68861e5598281 ]
Recovery on alsa-lib side is handled with either:
1) snd_pcm_prepare(state=XRUN)
2) snd_pcm_drop/drain() -> snd_pcm_prepare(state=SETUP)
before starting the PCM anew. Relying solely on state=XRUN leaves 2) unaccounted for. sound/core/pcm_native.c ensures correctness of the state machine so plain state!=PREPARED check suffices.
This is the BE equivalent of job done previously for FE side only with commit cfca1637bc2b ("ASoC: Intel: avs: Unprepare a stream when XRUN occurs") and its follow up titled: ("ASoC: Intel: avs: Reset the stream unless it is already prepared").
--- sound/soc/intel/avs/pcm.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/intel/avs/pcm.c +2 -0
@@ -461,6 +461,8 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct sn link_stream = data->link_stream; p = &be->dpcm[substream->stream].hw_params; +if (substream->runtime->state !=SNDRV_PCM_STATE_PREPARED ) + link_stream->link_prepared = false;if (link_stream->link_prepared)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1617/2151 ASoC: Intel: avs: Prevent module info underflow
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 05c2975b4267246219e7aead0467626107e204e9 ]
Typically modules information is first initialized when loading the base AudioDSP base firmware and then expanded when loadable DSP modules are requested by platform-components, see avs_component_load_libraries().
While theoretically not possible in a production scenario, there is no reason to continue the IDAs preparation if an event caused the newly obtained module information to be smaller or equal than the existing information.
--- sound/soc/intel/avs/utils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/intel/avs/utils.c +4 -2
@@ -118,9 +118,11 @@ avs_module_ida_alloc(struct avs_dev *adev, struct avs_mods_info *newinfo, bool pint i;if (!purge && oldinfo) { -if (oldinfo->count >= newinfo->count) -dev_warn (adev->dev,"refreshing %d modules info with %d\n" , +if (oldinfo->count >= newinfo->count) { +dev_warn (adev->dev,"modules info underflow, old: %d, new: %d\n" , oldinfo->count, newinfo->count); +return -EPROTO ; + } tocopy_count = oldinfo->count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1618/2151 ASoC: qcom: sdm845: set quaternary MI2S codec DAI to I2S format
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robert Oscilowski <[email protected]>
[ Upstream commit 20c734cb678332883d317b17bf8fe7361648e170 ]
We configure the codec DAI format for primary and secondary but not the quaternery MI2S path. Add the missing configuration to enable speaker codecs on the quaternary MI2S like the MAX9827 found on the OnePlus 6.
Stable-dep-of: cef5d087d681 ("ASoC: qcom: sdm845: Disable the quaternary MI2S bit clock on shutdown")
--- sound/soc/qcom/sdm845.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/qcom/sdm845.c +2 -0
@@ -373,10 +373,12 @@ static int sdm845_snd_startup(struct snd_pcm_substream *substream)snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ;case QUATERNARY_MI2S_RX : + codec_dai_fmt |=SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_I2S ;snd_soc_dai_set_sysclk (cpu_dai,Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT ,MI2S_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK );snd_soc_dai_set_fmt (cpu_dai, fmt); +snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ;case QUATERNARY_TDM_RX_0 :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1619/2151 ASoC: qcom: sdm845: Disable the quaternary MI2S bit clock on shutdown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Auer <[email protected]>
[ Upstream commit cef5d087d6813d4c15847d0b71ecbd6c47c5f1d4 ]
sdm845_snd_startup() enables the quaternary MI2S bit clock in the ADSP, but sdm845_snd_shutdown() never disables it. After the first stream on this port the clock stays on.
On the OnePlus 6 the speaker amplifier is on this port. After the first playback the ADSP no longer power collapses: it slept under 9 s in 5 hours. With this change it sleeps again when audio is idle (about 40 s of 45 s).
Refcount the clock like the other MI2S and TDM ports and disable it when the last user is gone.
--- sound/soc/qcom/sdm845.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
sound/soc/qcom/sdm845.c +15 -4
@@ -39,6 +39,7 @@ struct sdm845_snd_data {struct snd_soc_card *card;uint32_t pri_mi2s_clk_count;uint32_t sec_mi2s_clk_count; +uint32_t quat_mi2s_clk_count;uint32_t quat_tdm_clk_count;struct sdw_stream_runtime *sruntime[AFE_PORT_MAX ]; };
@@ -374,9 +375,11 @@ static int sdm845_snd_startup(struct snd_pcm_substream *substream)break ;case QUATERNARY_MI2S_RX : codec_dai_fmt |=SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_I2S ; -snd_soc_dai_set_sysclk (cpu_dai, -Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , -MI2S_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); +if (++(data->quat_mi2s_clk_count) ==1 ) { +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , +MI2S_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + }snd_soc_dai_set_fmt (cpu_dai, fmt);snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ;
@@ -464,8 +467,16 @@ static void sdm845_snd_shutdown(struct snd_pcm_substream *substream) 0, SNDRV_PCM_STREAM_PLAYBACK); }break ; - case SLIMBUS_0_RX...SLIMBUS_6_TX: +case QUATERNARY_MI2S_RX : +if (--(data->quat_mi2s_clk_count) ==0 ) { +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , +0 ,SNDRV_PCM_STREAM_PLAYBACK ); + } +break ; + + case SLIMBUS_0_RX...SLIMBUS_6_TX:break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1620/2151 selftests: keep the build status from wrapping to success
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 907d138279ee3747efedc9f7403d8b0edb52aca2 ]
The top-level all and install rules return failure only when every selected target fails, which commit cad6f32665cb ("selftests: Deescalate error reporting") deliberately kept as the default. They implement this by multiplying the exit statuses of the targets:
ret=$$((ret * $$?))
A failing recursive make exits with status 2, so eight failing targets produce 256, and "exit 256" reports success. Building eight or more targets that all fail therefore succeeds, and install goes on to package an empty installation.
Record a successful target instead of multiplying statuses. The rules still fail only when no target succeeds, and FORCE_TARGETS still stops at the first failure.
--- tools/testing/selftests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/Makefile +2 -2
@@ -214,7 +214,7 @@ all: $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ - ret=$$((ret * $$?)); \ + [ $$? -eq 0 ] && ret=0; \ done; exit $$ret; run_tests: all
@@ -281,7 +281,7 @@ ifdef INSTALL_PATH OBJ_PATH=$(INSTALL_PATH) \ O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ - ret=$$((ret * $$?)); \ + [ $$? -eq 0 ] && ret=0; \ done; exit $$ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1621/2151 ASoC: rockchip: rk3288_hdmi_analog: Drop redundant probe error messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 931f4a1223e154fdea63071074cbaa633ebf394b ]
Remove the probe error messages to avoid duplicate error reporting, since the error is already reported by the called functions.
Stable-dep-of: f15b2df0b940 ("ASoC: rockchip: fix device node reference leak in rk3288_hdmi_analog")
--- sound/soc/rockchip/rk3288_hdmi_analog.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
sound/soc/rockchip/rk3288_hdmi_analog.c +2 -7
@@ -184,10 +184,8 @@ static int snd_rk_mc_probe(struct platform_device *pdev)gpiod_set_consumer_name (machine->gpio_hp_en,"hp_en" ); ret =snd_soc_of_parse_card_name (card,"rockchip,model" ); -if (ret) { -dev_err (card->dev,"SoC parse card name failed %d\n" , ret); +if (ret)return ret; - } rk_dailink.codecs[0].of_node = of_parse_phandle(np, "rockchip,audio-codec",
@@ -222,11 +220,8 @@ static int snd_rk_mc_probe(struct platform_device *pdev) rk_dailink.platforms->of_node = rk_dailink.cpus->of_node; ret =snd_soc_of_parse_audio_routing (card,"rockchip,routing" ); -if (ret) { -dev_err (&pdev->dev, -"Unable to parse 'rockchip,routing' property\n" ); +if (ret)return ret; - }snd_soc_card_set_drvdata (card, machine);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1622/2151 ASoC: rockchip: rk3288_hdmi_analog: Use dev_err_probe() for error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 06f5854050f56775977f9972b78a21806de001f0 ]
Replace dev_err() with dev_err_probe() to prevent log spam when probe returns -EPROBE_DEFER.
Stable-dep-of: f15b2df0b940 ("ASoC: rockchip: fix device node reference leak in rk3288_hdmi_analog")
--- sound/soc/rockchip/rk3288_hdmi_analog.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sound/soc/rockchip/rk3288_hdmi_analog.c +3 -4
@@ -204,10 +204,9 @@ static int snd_rk_mc_probe(struct platform_device *pdev) } ret =snd_soc_get_dai_name (&args, &rk_dailink.codecs[0 ].dai_name); -if (ret) { -dev_err (&pdev->dev,"Unable to get codec_dai_name\n" ); -return ret; - } +if (ret) +return dev_err_probe (&pdev->dev, ret, +"Unable to get codec_dai_name\n" ); rk_dailink.cpus->of_node =of_parse_phandle (np,"rockchip,i2s-controller" ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1623/2151 ASoC: rockchip: fix device node reference leak in rk3288_hdmi_analog
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haotian Zhang <[email protected]>
[ Upstream commit f15b2df0b940cb2c01797f78791de3279d514086 ]
snd_rk_mc_probe() acquires references to the codec and CPU device nodes with of_parse_phandle() and stores them in the static rk_dailink, but the driver never calls of_node_put() on them. All error paths and the success path simply return, and the driver has no remove callback, so the references are leaked for the whole lifetime of the card and each failed or repeated probe leaks another pair. The same pattern was fixed for the sibling rockchip_rt5645.c driver.
Release the codec and CPU device nodes on every probe error path and in a new remove callback, and also drop the extra reference placed in args.np by of_parse_phandle_with_fixed_args().
--- sound/soc/rockchip/rk3288_hdmi_analog.c | 42 +++++++++++++++++++------ 1 file changed, 33 insertions(+), 9 deletions(-)
sound/soc/rockchip/rk3288_hdmi_analog.c +33 -9
@@ -200,36 +200,59 @@ static int snd_rk_mc_probe(struct platform_device *pdev)if (ret) {dev_err (&pdev->dev,"Unable to parse property 'rockchip,audio-codec'\n" ); -return ret; + goto put_codec_of_node; } ret =snd_soc_get_dai_name (&args, &rk_dailink.codecs[0 ].dai_name); -if (ret) -return dev_err_probe (&pdev->dev, ret, -"Unable to get codec_dai_name\n" ); +of_node_put (args.np); +if (ret) { +dev_err_probe (&pdev->dev, ret, +"Unable to get codec_dai_name\n" ); + goto put_codec_of_node; + } rk_dailink.cpus->of_node =of_parse_phandle (np,"rockchip,i2s-controller" ,0 );if (!rk_dailink.cpus->of_node) {dev_err (&pdev->dev,"Property 'rockchip,i2s-controller' missing or invalid\n" ); -return -EINVAL ; + ret = -EINVAL ; + goto put_codec_of_node; } rk_dailink.platforms->of_node = rk_dailink.cpus->of_node; ret =snd_soc_of_parse_audio_routing (card,"rockchip,routing" );if (ret) -return ret; + goto put_cpu_of_node;snd_soc_card_set_drvdata (card, machine); ret =devm_snd_soc_register_card (&pdev->dev, card); -if (ret) -return dev_err_probe (&pdev->dev, ret, -"Soc register card failed\n" ); +if (ret) { +dev_err_probe (&pdev->dev, ret, +"Soc register card failed\n" ); + goto put_cpu_of_node; + }return 0 ; + +put_cpu_of_node: +of_node_put (rk_dailink.cpus->of_node); + rk_dailink.cpus->of_node =NULL ; +put_codec_of_node: +of_node_put (rk_dailink.codecs[0 ].of_node); + rk_dailink.codecs[0 ].of_node =NULL ; + +return ret; +} + +static void snd_rk_mc_remove (struct platform_device *pdev) +{ +of_node_put (rk_dailink.cpus->of_node); + rk_dailink.cpus->of_node =NULL ; +of_node_put (rk_dailink.codecs[0 ].of_node); + rk_dailink.codecs[0 ].of_node =NULL ; }static const struct of_device_id rockchip_sound_of_match[] = {
@@ -241,6 +264,7 @@ MODULE_DEVICE_TABLE(of, rockchip_sound_of_match);static struct platform_driver rockchip_sound_driver = { .probe = snd_rk_mc_probe, + .remove = snd_rk_mc_remove, .driver = { .name =DRV_NAME , .pm = &snd_soc_pm_ops,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1624/2151 spi: tegra114: initialize native chip selects inactive
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abraham Zukor <[email protected]>
[ Upstream commit f8334fdfd858c27f090ce597806794e4a08c9f4f ]
tegra_spi_probe() initializes SPI_COMMAND1 with only SPI_M_S, leaving CS_POL_INACTIVE clear for every chip select. This drives every native active-low chip select low until tegra_spi_setup() runs for that device.
SPI children are registered and probed one at a time. A synchronous probe of an earlier child can therefore transfer while a later child's chip select is still asserted. On a Tegra234 system with active-low devices on CS0 and CS1, this caused both devices to be selected when the CS1 device probed first. Its initialization then intermittently failed. A logic analyzer showed CS0 remained low throughout the CS1 transfer and went high only after the CS1 probe failed.
Walk the controller's device tree children before SPI_COMMAND1 is written and set CS_POL_INACTIVE for each valid chip select without spi-cs-high. That way the line is already deasserted when the first child transfers and does not change level when setup runs.
Disabled children are walked too. The core only registers available children, so tegra_spi_setup() never runs for a disabled one and probe is the only chance to park its chip select at the level its hardware needs.
If an enabled child shares a chip select with disabled ones, its polarity takes priority. If only disabled children use a chip select and they disagree, warn and leave the line inactive high.
--- drivers/spi/spi-tegra114.c | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/spi/spi-tegra114.c +49 -0
@@ -1308,6 +1308,9 @@ static int tegra_spi_probe(struct platform_device *pdev)struct resource *r;int ret, spi_irq;int bus_num; +u32 conflicting_cs; +u32 enabled_child_cs_polarity =0 , disabled_child_cs_low =0 , disabled_child_cs_high =0 ; +u32 enabled_cs_mask =0 ; host =spi_alloc_host (&pdev->dev,sizeof (*tspi));if (!host) {
@@ -1407,6 +1410,52 @@ static int tegra_spi_probe(struct platform_device *pdev)udelay (2 );reset_control_deassert (tspi->rst); tspi->def_command1_reg =SPI_M_S ; + +/* +* SPI_COMMAND1 is written before any child is registered, so a chip +* select with CS_POL_INACTIVE clear stays asserted until +* tegra_spi_setup() runs for that device. Program the level the +* device tree asks for up front instead. +* +* Disabled children are included deliberately. The core never +* registers them, so this is the only chance to park their chip +* select at the level their hardware needs. An enabled child on the +* same CS takes priority. +*/ +for_each_child_of_node_scoped (pdev->dev.of_node, np) { +u32 cs; +u32 polarity_bitmask; +u32 cs_polarity =0 ; + +if (of_property_read_u32 (np,"reg" , &cs)) +continue ; + +if (cs >=MAX_CHIP_SELECT ) +continue ; + + polarity_bitmask =SPI_CS_POL_INACTIVE (cs); +if (!of_property_read_bool (np,"spi-cs-high" )) + cs_polarity = polarity_bitmask; + +if (of_device_is_available (np)) { + enabled_cs_mask |= polarity_bitmask; + enabled_child_cs_polarity |= cs_polarity; + }else { +if (cs_polarity) + disabled_child_cs_low |= polarity_bitmask; +else + disabled_child_cs_high |= polarity_bitmask; + } + } + conflicting_cs = disabled_child_cs_low & disabled_child_cs_high & ~enabled_cs_mask; +for (u32 cs =0 ; cs <MAX_CHIP_SELECT ; cs++) { +if (SPI_CS_POL_INACTIVE (cs) & conflicting_cs) +dev_warn (&pdev->dev, +"Conflicting CS polarity on disabled nodes at cs %u\n" , cs); + } + + tspi->def_command1_reg |= enabled_child_cs_polarity | + (disabled_child_cs_low & ~enabled_cs_mask);tegra_spi_writel (tspi, tspi->def_command1_reg,SPI_COMMAND1 ); tspi->spi_cs_timing1 =tegra_spi_readl (tspi,SPI_CS_TIMING1 ); tspi->spi_cs_timing2 =tegra_spi_readl (tspi,SPI_CS_TIMING2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1625/2151 ASoC: soc-link: Correct stream stop operations in snd_soc_link_trigger
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 7ef99fcfbbac20ebec10d21a37aeaf8321de7829 ]
When snd_soc_link_trigger() is called to stop, pause push or suspend stream it should call soc_link_mark_pop() on proper target to reverse operation from trigger start, pause release or resume.
--- sound/soc/soc-link.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/soc-link.c +1 -1
@@ -161,7 +161,7 @@ int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd,break ; ret =soc_link_trigger (substream, cmd); -soc_link_mark_pop (rtd, startup); +soc_link_mark_pop (rtd, trigger); }return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1626/2151 ASoC: ops: Fix return value in snd_soc_limit_volume()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 223ec2a93bec6c5ee859094c826fec78516a0bb3 ]
As documented snd_soc_limit_volume() should return 0 on success, however at some point in time this promise was broken when snd_soc_clip_to_platform_max() was refactored, refactor it once again using __free() to automatically free struct snd_ctl_elem_value and return proper value.
--- sound/soc/soc-ops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/soc-ops.c +5 -5
@@ -448,7 +448,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);static int snd_soc_clip_to_platform_max (struct snd_kcontrol *kctl) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; -struct snd_ctl_elem_value *uctl; + struct snd_ctl_elem_value *uctl __free(kfree) = NULL;int ret;if (!mc->platform_max)
@@ -460,7 +460,7 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl) ret = kctl->get (kctl, uctl);if (ret <0 ) - goto out; +return ret;if (uctl->value.integer.value[0 ] > mc->platform_max) uctl->value.integer.value[0 ] = mc->platform_max;
@@ -470,10 +470,10 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl) uctl->value.integer.value[1 ] = mc->platform_max; ret = kctl->put (kctl, uctl); +if (ret <0 ) +return ret; -out: -kfree (uctl); -return ret; +return 0 ; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1627/2151 ASoC: soc-topology-test: Check return value of kunit_device_register()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 1641c1ba27abcd3ea3bba1232d9d817092f1b757 ]
Call to kunit_device_register() can fail. Check return result of register call. While at it introduce helper variable so that if it fails put_device is called on properly initialized variable.
--- sound/soc/soc-topology-test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
sound/soc/soc-topology-test.c +6 -2
@@ -24,8 +24,12 @@ static struct device *test_dev;static int snd_soc_tplg_test_init (struct kunit *test) { - test_dev =kunit_device_register (test,"sound-soc-topology-test" ); - test_dev =get_device (test_dev); +struct device *dev; + + dev =kunit_device_register (test,"sound-soc-topology-test" ); +if (IS_ERR (dev)) +return PTR_ERR (dev); + test_dev =get_device (dev);if (!test_dev)return -ENODEV ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1628/2151 ASoC: soc-card-test: Check return value of kunit_device_register()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 77dfd98b1642b9bc6c2312bd8b805c321fb878b0 ]
Call to kunit_device_register() can fail. Check return result of register call. While at it introduce helper variable so that if it fails put_device is called on properly initialized variable.
--- sound/soc/soc-card-test.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
sound/soc/soc-card-test.c +5 -2
@@ -70,6 +70,7 @@ static void test_snd_soc_card_get_kcontrol(struct kunit *test)static int soc_card_test_case_init (struct kunit *test) {struct soc_card_test_priv *priv; +struct device *dev;int ret; priv =kunit_kzalloc (test,sizeof (*priv),GFP_KERNEL );
@@ -82,8 +83,10 @@ static int soc_card_test_case_init(struct kunit *test)if (!priv->card)return -ENOMEM ; - priv->card_dev =kunit_device_register (test,"sound-soc-card-test" ); - priv->card_dev =get_device (priv->card_dev); + dev =kunit_device_register (test,"sound-soc-card-test" ); +if (IS_ERR (dev)) +return PTR_ERR (dev); + priv->card_dev =get_device (dev);if (!priv->card_dev)return -ENODEV ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1629/2151 ASoC: soc-ac97: Fix error handling in snd_soc_new_ac97_component()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit fc081cdfc6b370f6b6853cdeb4313f92561770d1 ]
If call to snd_soc_ac97_init_gpio() fails, proper removal procedure should mirror snd_soc_free_ac97_component() behaviour and call device_del() before put_device().
--- sound/soc/soc-ac97.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/soc-ac97.c +3 -1
@@ -241,10 +241,12 @@ struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component, ret =snd_soc_ac97_init_gpio (ac97, component);if (ret) - goto err_put_device; + goto err_del_device;return ac97; +err_del_device: +device_del (&ac97->dev); err_put_device:put_device (&ac97->dev);return ERR_PTR (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1630/2151 ASoC: soc-component: Fix return type of snd_soc_pcm_component_pointer()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 9df30adce80dd6b0646e58c12a4cf7c6c88d0778 ]
Both caller and pointer callback expect the return value to be snd_pcm_uframes_t, however it was defined incorrectly leading to potential truncation of returned value.
--- include/sound/soc-component.h | 2 +- sound/soc/soc-component.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/sound/soc-component.h +1 -1
@@ -435,7 +435,7 @@ int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,int snd_soc_component_compr_get_metadata (struct snd_compr_stream *cstream,struct snd_compr_metadata *metadata); -int snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream); +snd_pcm_uframes_t snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream);int snd_soc_pcm_component_ioctl (struct snd_pcm_substream *substream,unsigned int cmd,void *arg);int snd_soc_pcm_component_sync_stop (struct snd_pcm_substream *substream);
sound/soc/soc-component.c +1 -1
@@ -963,7 +963,7 @@ int snd_soc_component_test_bits(struct snd_soc_component *component, }EXPORT_SYMBOL_GPL (snd_soc_component_test_bits); -int snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream) +snd_pcm_uframes_t snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_soc_component *component;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1631/2151 ASoC: mediatek: mt8195: Fix tuner clock error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 8e5a2eabb0d7cbd6db0b94f7f30e1ca2c0a8994f ]
Check and propagate errors from mt8195_afe_enable_clk(). If enabling the tuner clock fails, disable the previously enabled APLL clock.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +19 -5
@@ -241,21 +241,35 @@ static int mt8195_afe_enable_tuner_clk(struct mtk_base_afe *afe, unsigned int id) {struct mt8195_afe_private *afe_priv = afe->platform_priv; +int ret;switch (id) {case MT8195_AUD_PLL1 : -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER ]); + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); +if (ret) +return ret; + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER ]); +if (ret) { +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); +return ret; + }break ;case MT8195_AUD_PLL2 : -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER ]); + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); +if (ret) +return ret; + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER ]); +if (ret) { +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); +return ret; + }break ;default : + ret =0 ;break ; } -return 0 ; +return ret; } static int mt8195_afe_disable_tuner_clk(struct mtk_base_afe *afe,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1632/2151 ASoC: mediatek: mt8195: Fix register access clock error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit c23390ecf5c068976f25d9c8bfa8e298fa12ea3d ]
Check the return value of mt8195_afe_enable_clk() when enabling the register access clocks.
If enabling a clock fails, disable the clocks that were already enabled and propagate the error to the caller
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +12 -3
@@ -608,7 +608,7 @@ static int mt8195_afe_disable_top_cg(struct mtk_base_afe *afe, unsigned int cg_tint mt8195_afe_enable_reg_rw_clk (struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv; -int i; +int i, ret;static const unsigned int clk_array[] = {MT8195_CLK_SCP_ADSP_AUDIODSP ,/* bus clock for infra */ MT8195_CLK_TOP_AUDIO_H_SEL ,/* clock for ADSP bus */
@@ -620,10 +620,19 @@ int mt8195_afe_enable_reg_rw_clk(struct mtk_base_afe *afe) MT8195_CLK_AUD_A1SYS, /* AFE HW clock */ }; -for (i =0 ; i <ARRAY_SIZE (clk_array); i++) -mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +for (i =0 ; i <ARRAY_SIZE (clk_array); i++) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +if (ret) + goto err_disable_clk; + }return 0 ; + +err_disable_clk: +while (--i >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[clk_array[i]]); + +return ret; }int mt8195_afe_disable_reg_rw_clk (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1633/2151 ASoC: mediatek: mt8195: Fix timing system clock error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit f18c0a8e528eb8844ee362324220ab8df3664afe ]
Check the return value of mt8195_afe_enable_clk() when enabling the timing system clocks.
If enabling a clock fails, disable the clocks that were already enabled and propagate the error to the caller. In mt8195_afe_enable_main_clock(), return the error instead of continuing with AFE clock enable.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +12 -3
@@ -671,7 +671,7 @@ static int mt8195_afe_disable_afe_on(struct mtk_base_afe *afe)static int mt8195_afe_enable_timing_sys (struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv; -int i; +int i, ret;static const unsigned int clk_array[] = {MT8195_CLK_AUD_A1SYS ,MT8195_CLK_AUD_A2SYS ,
@@ -682,13 +682,22 @@ static int mt8195_afe_enable_timing_sys(struct mtk_base_afe *afe) MT8195_TOP_CG_26M_TIMING, }; -for (i =0 ; i <ARRAY_SIZE (clk_array); i++) -mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +for (i =0 ; i <ARRAY_SIZE (clk_array); i++) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +if (ret) + goto err_disable_clk; + }for (i =0 ; i <ARRAY_SIZE (cg_array); i++)mt8195_afe_enable_top_cg (afe, cg_array[i]);return 0 ; + +err_disable_clk: +while (--i >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[clk_array[i]]); + +return ret; }static int mt8195_afe_disable_timing_sys (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1634/2151 ASoC: mediatek: mt8195: Fix main clock error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 9f1b48c658ac38be81c04fbc29ed1522f89fb0c9 ]
Check the return values of clock enable functions and propagate errors to the caller.
Disable previously enabled clocks on failure to match the main clock disable sequence.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +20 -3
@@ -725,14 +725,31 @@ static int mt8195_afe_disable_timing_sys(struct mtk_base_afe *afe)int mt8195_afe_enable_main_clock (struct mtk_base_afe *afe) { -mt8195_afe_enable_timing_sys (afe); +int ret; + + ret =mt8195_afe_enable_timing_sys (afe); +if (ret) +return ret;mt8195_afe_enable_afe_on (afe); -mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL1 ); -mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL2 ); + ret =mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL1 ); +if (ret) + goto err_disable_afe_on; + + ret =mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL2 ); +if (ret) + goto err_disable_apll1_tuner;return 0 ; + +err_disable_apll1_tuner: +mt8195_afe_disable_apll_tuner (afe,MT8195_AUD_PLL1 ); +err_disable_afe_on: +mt8195_afe_disable_afe_on (afe); +mt8195_afe_disable_timing_sys (afe); + +return ret; }int mt8195_afe_disable_main_clock (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1635/2151 ASoC: mediatek: mt8195: Fix paired memif clock error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit c0ec135cf3fd7c7c7cdefd234111e5d4f069a7e6 ]
Check and propagate errors when preparing and enabling the paired DL8/DL10 memif clocks.
If enabling the second clock fails, undo the clock that was already prepared or enabled to keep the clock state balanced.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +20 -4
@@ -286,15 +286,23 @@ mt8195_afe_paired_memif_clk_prepare(struct snd_pcm_substream *substream,struct mt8195_afe_private *afe_priv = afe->platform_priv;int id =snd_soc_rtd_to_cpu (rtd,0 )->id;int clk_id; +int ret;if (id !=MT8195_AFE_MEMIF_DL8 && id !=MT8195_AFE_MEMIF_DL10 )return 0 ;if (enable) { clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; -mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); +if (ret) +return ret; clk_id =MT8195_CLK_AUD_MEMIF_DL8 ; -mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); +if (ret) { + clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; +mt8195_afe_unprepare_clk (afe, afe_priv->clk[clk_id]); +return ret; + } }else { clk_id =MT8195_CLK_AUD_MEMIF_DL8 ;mt8195_afe_unprepare_clk (afe, afe_priv->clk[clk_id]);
@@ -315,6 +323,7 @@ mt8195_afe_paired_memif_clk_enable(struct snd_pcm_substream *substream,struct mt8195_afe_private *afe_priv = afe->platform_priv;int id =snd_soc_rtd_to_cpu (rtd,0 )->id;int clk_id; +int ret;if (id !=MT8195_AFE_MEMIF_DL8 && id !=MT8195_AFE_MEMIF_DL10 )return 0 ;
@@ -322,11 +331,18 @@ mt8195_afe_paired_memif_clk_enable(struct snd_pcm_substream *substream,if (enable) {/* DL8_DL10_MEM */ clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; -mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); +if (ret) +return ret;udelay (1 );/* DL8_DL10_AGENT */ clk_id =MT8195_CLK_AUD_MEMIF_DL8 ; -mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); +if (ret) { + clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; +mt8195_afe_disable_clk_atomic (afe, afe_priv->clk[clk_id]); +return ret; + } }else {/* DL8_DL10_AGENT */ clk_id =MT8195_CLK_AUD_MEMIF_DL8 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1636/2151 ASoC: mediatek: mt8195: Fix FE startup error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit b1db7408c8e0761d17b49b74f8f2d60c0c1929e8 ]
Check and propagate errors from paired memif clock preparation and PCM hardware constraints during FE startup.
Unprepare the paired memif clocks and shut down the FE when a later startup step fails to avoid leaving resources enabled on error.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +27 -13
@@ -364,24 +364,38 @@ static int mt8195_afe_fe_startup(struct snd_pcm_substream *substream,int id =snd_soc_rtd_to_cpu (rtd,0 )->id;int ret =0 ; -mt8195_afe_paired_memif_clk_prepare (substream, dai,1 ); + ret =mt8195_afe_paired_memif_clk_prepare (substream, dai,1 ); +if (ret) +return ret; ret =mtk_afe_fe_startup (substream, dai); +if (ret <0 ) + goto err_clk_unprepare; -snd_pcm_hw_constraint_step (runtime,0 , -SNDRV_PCM_HW_PARAM_BUFFER_BYTES , -MT8195_MEMIF_BUFFER_BYTES_ALIGN ); + ret =snd_pcm_hw_constraint_step (runtime,0 , +SNDRV_PCM_HW_PARAM_BUFFER_BYTES , +MT8195_MEMIF_BUFFER_BYTES_ALIGN ); +if (ret) + goto err_fe_shutdow; + +if (id ==MT8195_AFE_MEMIF_DL7 ) { + ret =snd_pcm_hw_constraint_minmax (runtime, +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +1 , +MT8195_MEMIF_DL7_MAX_PERIOD_SIZE ); +if (ret <0 ) { +dev_dbg (afe->dev,"hw_constraint_minmax failed\n" ); + goto err_fe_shutdow; + } + } -if (id !=MT8195_AFE_MEMIF_DL7 ) - goto out; +return 0 ; + +err_fe_shutdow: +mtk_afe_fe_shutdown (substream, dai); +err_clk_unprepare: +mt8195_afe_paired_memif_clk_prepare (substream, dai,0 ); - ret =snd_pcm_hw_constraint_minmax (runtime, -SNDRV_PCM_HW_PARAM_PERIOD_SIZE , -1 , -MT8195_MEMIF_DL7_MAX_PERIOD_SIZE ); -if (ret <0 ) -dev_dbg (afe->dev,"hw_constraint_minmax failed\n" ); -out:return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1637/2151 ASoC: mediatek: mt8195: Check paired MEMIF clock enable in FE trigger
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit a2ae972c75a18ecbdcbf331ddaab21e1a08333fb ]
Check the return value of mt8195_afe_paired_memif_clk_enable() on START/RESUME. On failure, stop the MEMIF and disable the channel merge before returning the error.
Also skip enabling the paired clock if mtk_afe_fe_trigger() fails.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +8 -1
@@ -466,7 +466,14 @@ static int mt8195_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME : -mt8195_afe_paired_memif_clk_enable (substream, dai,1 ); +if (ret) +break ; + + ret =mt8195_afe_paired_memif_clk_enable (substream, dai,1 ); +if (ret) { +mtk_afe_fe_trigger (substream,SNDRV_PCM_TRIGGER_STOP , dai); +mt8195_afe_enable_cm (afe, cm, false); + }break ;case SNDRV_PCM_TRIGGER_STOP :case SNDRV_PCM_TRIGGER_SUSPEND :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1638/2151 ASoC: mediatek: mt8195: Fix runtime resume error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 933fbfb6648850e003a1fc47b7bcc08fe3687961 ]
Check and propagate errors when enabling the register access and main clocks during runtime resume.
If regcache_sync() or main clock enable fails, restore regmap cache-only mode and disable the register access clocks before returning the error.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +18 -5
@@ -2967,18 +2967,31 @@ static int mt8195_afe_runtime_resume(struct device *dev) {struct mtk_base_afe *afe =dev_get_drvdata (dev);struct mt8195_afe_private *afe_priv = afe->platform_priv; +int ret; -mt8195_afe_enable_reg_rw_clk (afe); + ret =mt8195_afe_enable_reg_rw_clk (afe); +if (ret) +return ret;if (!afe->regmap || afe_priv->pm_runtime_bypass_reg_ctl) - goto skip_regmap; +return 0 ;regcache_cache_only (afe->regmap, false); -regcache_sync (afe->regmap); + ret =regcache_sync (afe->regmap); +if (ret) + goto err_restore_cache; + + ret =mt8195_afe_enable_main_clock (afe); +if (ret) + goto err_restore_cache; -mt8195_afe_enable_main_clock (afe); -skip_regmap:return 0 ; + +err_restore_cache: +regcache_cache_only (afe->regmap, true); +mt8195_afe_disable_reg_rw_clk (afe); + +return ret; }static int init_memif_priv_data (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1639/2151 ASoC: mediatek: mt8195: Propagate IRQ lookup errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 9d5dedb285fb61a40e04f337d9e06fc59c065857 ]
Propagate the error returned by platform_get_irq() instead of replacing it with -ENXIO.
This preserves errors such as -EPROBE_DEFER for proper handling by the caller.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +1 -1
@@ -3134,7 +3134,7 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev)/* request irq */ irq_id =platform_get_irq (pdev,0 );if (irq_id <0 ) -return -ENXIO ; +return irq_id; ret =devm_request_irq (dev, irq_id, mt8195_afe_irq_handler,IRQF_TRIGGER_NONE ,"asys-isr" , (void *)afe);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1640/2151 ASoC: mediatek: mt8195: Fix ETDM MCLK error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 91dce9c7eec25e95b5ca32e17e60e2c27333d411 ]
Propagate errors from mt8195_afe_enable_clk() when enabling the ETDM MCLK instead of always returning success.
This allows callers to properly handle failures when enabling the MCLK.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +1 -3
@@ -1554,9 +1554,7 @@ static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id)if (clkdiv_id <0 )return -EINVAL ; -mt8195_afe_enable_clk (afe, afe_priv->clk[clkdiv_id]); - -return 0 ; +return mt8195_afe_enable_clk (afe, afe_priv->clk[clkdiv_id]); }static int mtk_dai_etdm_disable_mclk (struct mtk_base_afe *afe,int dai_id)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1641/2151 ASoC: mediatek: mt8195: Fix ETDM startup error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 8e67c67f3fd2505b8b7a9dd38d8dabe47273490d ]
Check and propagate errors when enabling the ETDM MCLK and clock gates during startup.
If enabling a clock fails, disable the clocks that were already enabled to keep the clock state balanced.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 50 ++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +40 -10
@@ -1580,36 +1580,66 @@ static int mtk_dai_etdm_startup(struct snd_pcm_substream *substream,int cg_id;int mst_dai_id;int slv_dai_id; -int i; +int i, ret;if (is_cowork_mode (dai)) { mst_dai_id =get_etdm_cowork_master_id (dai);if (!mt8195_afe_etdm_is_valid (mst_dai_id))return -EINVAL ; -mtk_dai_etdm_enable_mclk (afe, mst_dai_id); + ret =mtk_dai_etdm_enable_mclk (afe, mst_dai_id); +if (ret) +return ret; cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (mst_dai_id); -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (ret) + goto err_disable_mclk; + } mst_etdm_data = afe_priv->dai_priv[mst_dai_id];for (i =0 ; i < mst_etdm_data->cowork_slv_count; i++) { slv_dai_id = mst_etdm_data->cowork_slv_id[i]; cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (slv_dai_id); -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, - afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, + afe_priv->clk[cg_id]); +if (ret) + goto err_disable_slv_clk; + } } }else { -mtk_dai_etdm_enable_mclk (afe, dai->id); + ret =mtk_dai_etdm_enable_mclk (afe, dai->id); +if (ret) +return ret; cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (dai->id); -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (ret) + goto err_disable_mclk; + } }return 0 ; + +err_disable_slv_clk: +while (--i >=0 ) { + slv_dai_id = mst_etdm_data->cowork_slv_id[i]; + cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (slv_dai_id); +if (cg_id >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[cg_id]); + } + + cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (mst_dai_id); +if (cg_id >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[cg_id]); + +err_disable_mclk: +mtk_dai_etdm_disable_mclk (afe,is_cowork_mode (dai) ? mst_dai_id : dai->id); + +return ret; } static void mtk_dai_etdm_shutdown(struct snd_pcm_substream *substream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1642/2151 ASoC: mediatek: mt8195: Fix HDMI TX startup error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 1d6f1785d90334b66809a57ebfc40a5b1cfa80ec ]
Check and propagate errors when enabling the clock gate and MCLK during HDMI TX/DP TX startup.
If MCLK enabling fails, disable the clock gate that was already enabled before returning the error.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +15 -3
@@ -2326,13 +2326,25 @@ static int mtk_dai_hdmitx_dptx_startup(struct snd_pcm_substream *substream,struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv;int cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (dai->id); +int ret; -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (ret) +return ret; + } -mtk_dai_etdm_enable_mclk (afe, dai->id); + ret =mtk_dai_etdm_enable_mclk (afe, dai->id); +if (ret) + goto err_disable_cg_clk;return 0 ; + +err_disable_cg_clk: +if (cg_id >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[cg_id]); + +return ret; } static void mtk_dai_hdmitx_dptx_shutdown(struct snd_pcm_substream *substream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1643/2151 ASoC: mediatek: mt8195: Fix ETDM probe error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit ca3ac9a7eec1884bfff2d2dd92caf30f86a9eea7 ]
Use pm_runtime_resume_and_get() to properly handle runtime PM errors during ETDM probe.
Propagate errors from MCLK configuration and enabling instead of ignoring them.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +18 -9
@@ -2508,6 +2508,7 @@ static int mtk_dai_etdm_probe(struct snd_soc_dai *dai)struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv;struct mtk_dai_etdm_priv *etdm_data; +int ret;dev_dbg (dai->dev,"%s id %d\n" , __func__, dai->id);
@@ -2515,15 +2516,23 @@ static int mtk_dai_etdm_probe(struct snd_soc_dai *dai)return -EINVAL ; etdm_data = afe_priv->dai_priv[dai->id]; -if (etdm_data->mclk_freq) { -dev_dbg (afe->dev,"MCLK always on, rate %d\n" , - etdm_data->mclk_freq); -pm_runtime_get_sync (afe->dev); -mtk_dai_etdm_mclk_configure (afe, dai->id); -mtk_dai_etdm_enable_mclk (afe, dai->id); -pm_runtime_put_sync (afe->dev); - } -return 0 ; +if (!etdm_data->mclk_freq) +return 0 ; + +dev_dbg (afe->dev,"MCLK always on, rate %d\n" , + etdm_data->mclk_freq); + ret =pm_runtime_resume_and_get (afe->dev); +if (ret) +return ret; + ret =mtk_dai_etdm_mclk_configure (afe, dai->id); +if (ret) + goto err_put_pm; + ret =mtk_dai_etdm_enable_mclk (afe, dai->id); + +err_put_pm: +pm_runtime_put_sync (afe->dev); + +return ret; }static const struct snd_soc_dai_ops mtk_dai_hdmitx_dptx_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1644/2151 tracing: Print the bucket size as unsigned
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 387945e8d2f29fa8a28d219af5416e6d3bedc314 ]
A key's bucket size reads back negative once it exceeds LONG_MAX:
# echo 'hist:keys=next_pid.buckets=18446744073709551615' > trigger # cat trigger hist:keys=next_pid.buckets=-1:vals=hitcount:...
parse_field() takes the size with kstrtoul() and rejects only zero, so the whole unsigned long range is accepted and stored, but hist_field_print() renders it with %ld.
Print it with %lu.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -6211,7 +6211,7 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) } }if (hist_field->buckets) -seq_printf (m,"=%ld" , hist_field->buckets); +seq_printf (m,"=%lu" , hist_field->buckets); } static int event_hist_trigger_print(struct seq_file *m,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1645/2151 tracing: Only report the stacktrace modifier on a real field
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 18bb005845b78e0c0eb44b7f231c29d138552438 ]
get_hist_field_flags() returns "stacktrace" for any field carrying HIST_FIELD_FL_STACKTRACE, including the common_stacktrace pseudo-field, which has no ftrace_event_field behind it. parse_field() no longer takes the modifier there:
if (stack_modifier &&
(!field || field->filter_type != FILTER_STACKTRACE)) {
hist_err(tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str));so expr_field_str() renders "common_stacktrace.stacktrace", a spelling that cannot be parsed back.
Report the modifier only when there is a field to report it for.
hist_field_print(), the other caller of get_hist_field_flags(), excludes HIST_FIELD_FL_STACKTRACE before it calls, so this is confined to expr_field_str(), whose only key renderer arrives in the next patch.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -1728,7 +1728,7 @@ static const char *get_hist_field_flags(struct hist_field *hist_field) flags_str ="percent" ; else if (hist_field->flags & HIST_FIELD_FL_GRAPH) flags_str ="graph" ; - else if (hist_field->flags & HIST_FIELD_FL_STACKTRACE) + else if (hist_field->flags & HIST_FIELD_FL_STACKTRACE && hist_field->field) flags_str ="stacktrace" ;return flags_str;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1646/2151 tracing: Clamp the printed end of a histogram bucket at U64_MAX
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 289e2a775de434ccab2d107076bc78362ce288bd ]
A key with the ".buckets=N" modifier is stored as the start of its bucket, and hist_trigger_print_key() prints the range it covers as start to start + N - 1. That addition overflows once the start is within N of U64_MAX:
# echo 'hist:keys=offset.buckets=10' >> \
events/syscalls/sys_enter_lseek/trigger
# ./seeker 5 -1 # lseek(0, 5) and lseek(0, -1)
# cat events/syscalls/sys_enter_lseek/hist
...
{ offset: ~ 18446744073709551610-3 } hitcount: 1
{ offset: ~ 0-9 } hitcount: 1
...18446744073709551610 + 10 - 1 does not fit in 64 bits, so the range ends below where it starts.
The bucket does end at U64_MAX: it holds every value hist_field_bucket() maps onto its start, and there is no value above U64_MAX. Clamp the printed end there. Printed honestly the group is shorter than the size asked for, which histogram.rst does not mention, so say it there.
--- Documentation/trace/histogram.rst | 3 +++ kernel/trace/trace_events_hist.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
Documentation/trace/histogram.rst +3 -0
@@ -1943,6 +1943,9 @@ the ".buckets" modifier and specify a size (in this case groups of 10):: Entries: 16 Dropped: 0 +Keys are 64-bit, so the group holding the largest values is truncated where +that range ends and can be smaller than the size asked for. + To save stacktraces, create a synthetic event with a field of type "unsigned long[]" or even just "long[]". For example, to see how long a task is blocked in an uninterruptible state::
kernel/trace/trace_events_hist.c +6 -1
@@ -5573,9 +5573,14 @@ static void hist_trigger_print_key(struct seq_file *m, *(u64 *)(key + key_field->offset)); }else if (key_field->flags &HIST_FIELD_FL_BUCKET ) {unsigned long buckets = key_field->buckets; +u64 end; + uval = *(u64 *)(key + key_field->offset); + end = uval + buckets -1 ; +if (end < uval) + end =U64_MAX ;seq_printf (m,"%s: ~ %llu-%llu" , field_name, - uval, uval + buckets -1 ); + uval, end); }else if (key_field->flags &HIST_FIELD_FL_STRING ) {seq_printf (m,"%s: %-50s" , field_name, (char *)(key + key_field->offset));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1647/2151 tracing: Avoid BTF lookup in atomic context
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: pengdonglin <[email protected]>
[ Upstream commit 42643ba35deb8ad1821acfc0577b445ee7ad7548 ]
The function graph trace formatter can be called from ftrace_dump_one() with interrupts disabled. When ftrace_dump_on_oops is enabled, the trace panic notifier can reach ftrace_dump() from the panic path, including the nmi_panic() path used by the hard lockup detector.
btf_find_func_proto() calls bpf_find_btf_id(), which may initialize vmlinux BTF under a mutex. Skip the BTF lookup when running in an atomic context or with interrupts disabled, and fall back to the existing return value formatting.
--- kernel/trace/trace_btf.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_btf.c +3 -0
@@ -15,6 +15,9 @@ const struct btf_type *btf_find_func_proto(const char *func_name, struct btf **bconst struct btf_type *t;s32 id; +if (unlikely (in_atomic () ||irqs_disabled ())) +return NULL ; + id =bpf_find_btf_id (func_name,BTF_KIND_FUNC , btf_p);if (id <0 )return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1648/2151 f2fs: quota: fix quota flush failure during filesystem freeze
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianan Huang <[email protected]>
[ Upstream commit f6f8f34480c78eade6542faea6386c47c9b4c6b3 ]
Quota flush retries can be exhausted during filesystem freeze.
freeze_super() and the quota checkpoint may race as below.
freeze_super() f2fs_ckpt
- down_write(&sb->s_umount)
- sb->s_writers.frozen = SB_FREEZE_PAGEFAULT
- sync_filesystem()
- f2fs_sync_fs()
- f2fs_issue_checkpoint()
- queue CP_SYNC -----------------> - block_operations()
- down_read_trylock(s_umount) : fails; freeze holds write lock
- quota flush retries exhausted
- set CP_QUOTA_NEED_FSCK_FLAG
During the PAGEFAULT sync pass, freeze_super() holds s_umount for write, but umount_lock_holder is not set until f2fs_freeze(). Thus quota writeback tries to acquire s_umount again and can exhaust retries.
With checkpoint merge enabled, f2fs_issue_checkpoint() may dispatch CP_SYNC to f2fs_ckpt. That thread also cannot acquire the freeze lock.
Record current as umount_lock_holder around the VFS PAGEFAULT sync so checkpoint runs in the freeze caller and quota flush uses its existing s_umount write lock.
--- fs/f2fs/super.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
fs/f2fs/super.c +20 -1
@@ -2070,6 +2070,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs_super (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ; +int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);
@@ -3649,7 +3668,7 @@ static const struct super_operations f2fs_sops = {#endif .evict_inode = f2fs_evict_inode, .put_super = f2fs_put_super, - .sync_fs = f2fs_sync_fs, + .sync_fs = f2fs_sync_fs_super, .freeze_fs = f2fs_freeze, .unfreeze_fs = f2fs_unfreeze, .statfs = f2fs_statfs,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1649/2151 net/smc: hold a reference on net_device returned by pnet_find_base_ndev()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Atharva Vartak <[email protected]>
[ Upstream commit e6435b2cc5fdf008cdb67ad9a811a266e8ac9c1e ]
pnet_find_base_ndev() resolves the base net_device for stacked devices under RTNL, then drops the lock and returns the raw pointer without taking a reference. All three callers dereference the pointer after RTNL has been released, creating a use-after-free window if the device is concurrently unregistered.
Take a reference with netdev_hold() before dropping RTNL and add the matching netdev_put() in every return path of the three callers:
- smc_pnet_add_eth()
- smc_pnet_find_roce_by_pnetid()
- smc_pnet_find_ism_by_pnetid()
Found by code analysis, confirmed with a proof-of-concept that triggers a KASAN slab-use-after-free report.
--- net/smc/smc_pnet.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
net/smc/smc_pnet.c +22 -7
@@ -30,7 +30,8 @@#include "smc_core.h" static struct net_device *__pnet_find_base_ndev (struct net_device *ndev); -static struct net_device *pnet_find_base_ndev (struct net_device *ndev); +static struct net_device *pnet_find_base_ndev (struct net_device *ndev, +netdevice_tracker *tracker);static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX +1 ] = { [SMC_PNETID_NAME ] = {
@@ -351,6 +352,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,struct smc_pnetentry *tmp_pe, *new_pe;struct net_device *ndev, *base_ndev;u8 ndev_pnetid[SMC_MAX_PNETID_LEN ]; +netdevice_tracker base_tracker;bool new_netdev;int rc;
@@ -360,10 +362,13 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net, rc = -EEXIST ; ndev =dev_get_by_name (net, eth_name);/* dev_hold() */ if (ndev) { - base_ndev =pnet_find_base_ndev (ndev); + base_ndev =pnet_find_base_ndev (ndev, &base_tracker);if (!smc_pnetid_by_dev_port (base_ndev->dev.parent, - base_ndev->dev_port, ndev_pnetid)) + base_ndev->dev_port, ndev_pnetid)) { +netdev_put (base_ndev, &base_tracker); goto out_put; + } +netdev_put (base_ndev, &base_tracker); }/* add a new netdev entry to the pnet table if there isn't one */
@@ -940,10 +945,13 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)* (for instance with bonding slaves), just the first device * is used to reach a base device. */ -static struct net_device *pnet_find_base_ndev (struct net_device *ndev) +static struct net_device *pnet_find_base_ndev (struct net_device *ndev, +netdevice_tracker *tracker) {rtnl_lock (); ndev =__pnet_find_base_ndev (ndev); +/* keep ndev alive after dropping RTNL, callers must netdev_put() */ +netdev_hold (ndev, tracker,GFP_KERNEL );rtnl_unlock ();return ndev; }
@@ -1080,17 +1088,20 @@ static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev, {u8 ndev_pnetid[SMC_MAX_PNETID_LEN ];struct net_device *base_ndev; +netdevice_tracker base_tracker;struct net *net; - base_ndev =pnet_find_base_ndev (ndev); + base_ndev =pnet_find_base_ndev (ndev, &base_tracker); net =dev_net (ndev);if (smc_pnetid_by_dev_port (base_ndev->dev.parent, base_ndev->dev_port, ndev_pnetid) &&smc_pnet_find_ndev_pnetid_by_table (base_ndev, ndev_pnetid) &&smc_pnet_find_ndev_pnetid_by_table (ndev, ndev_pnetid)) {smc_pnet_find_rdma_dev (base_ndev, ini); +netdev_put (base_ndev, &base_tracker);return ;/* pnetid could not be determined */ } +netdev_put (base_ndev, &base_tracker);_smc_pnet_find_roce_by_pnetid (ndev_pnetid, ini,NULL , net); }
@@ -1098,13 +1109,16 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, struct smc_init_info *ini) {u8 ndev_pnetid[SMC_MAX_PNETID_LEN ]; +netdevice_tracker base_tracker;struct smcd_dev *ismdev; - ndev =pnet_find_base_ndev (ndev); + ndev =pnet_find_base_ndev (ndev, &base_tracker);if (smc_pnetid_by_dev_port (ndev->dev.parent, ndev->dev_port, ndev_pnetid) && -smc_pnet_find_ndev_pnetid_by_table (ndev, ndev_pnetid)) +smc_pnet_find_ndev_pnetid_by_table (ndev, ndev_pnetid)) { +netdev_put (ndev, &base_tracker);return ;/* pnetid could not be determined */ + }mutex_lock (&smcd_dev_list.mutex);list_for_each_entry (ismdev, &smcd_dev_list.list, list) {
@@ -1118,6 +1132,7 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, } }mutex_unlock (&smcd_dev_list.mutex); +netdev_put (ndev, &base_tracker); }/* PNET table analysis for a given sock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1650/2151 tracing: Print a signed histogram key as signed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit d3e0dfc1ba49a0ab6aeddbb4bcde4bfc0e171a02 ]
A histogram sorts its rows by the key named in sort=, and for a key over a signed event field it sorts them signed: create_tracing_map_fields() picks the comparison function with
else cmp_fn = tracing_map_cmp_num(field->size, field->is_signed);
hist_trigger_print_key() does not look at is_signed at all. Every numeric key is printed with %llu, so a sorted histogram over a signed field comes out looking unsorted. syscalls/sys_exit_lseek carries "long ret", which SYSCALL_FIELD() marks signed and which is negative on every error:
# echo 'hist:keys=ret:sort=ret' > events/syscalls/sys_exit_lseek/trigger # echo 1 > events/syscalls/sys_exit_lseek/enable # (five lseek(2) calls returning -ESPIPE, -EINVAL, -EBADF, 0 and 100) # cat events/syscalls/sys_exit_lseek/hist
{ ret: 18446744073709551587 } hitcount: 1
{ ret: 18446744073709551594 } hitcount: 1
{ ret: 18446744073709551607 } hitcount: 1 { ret: 0 } hitcount: 1
{ ret: 100 } hitcount: 1
The rows are in ascending order and the numbers are not, because the three leading ones are -29, -22 and -9 rendered as their two's complement.
Take the rendering from the same place the sort order comes from: the event field when the key has one, and the hist_field itself when it does not. The same histogram then reads
{ ret: -29 } hitcount: 1
{ ret: -22 } hitcount: 1
{ ret: -9 } hitcount: 1
{ ret: 0 } hitcount: 1
{ ret: 100 } hitcount: 1A ".buckets" key stays unsigned here, and not because it is right. hist_field_bucket() divides as unsigned, so the group holding S64_MAX also holds S64_MIN, reported at
https://lore.kernel.org/all/[email protected]/
Printing that group signed would name a range that does not contain S64_MIN, so the grouping has to be fixed with it, in a patch of its own.
--- kernel/trace/trace_events_hist.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +13 -1
@@ -273,6 +273,14 @@ static u64 hist_field_pstring(struct hist_field *hist_field,return (u64 )(unsigned long )*addr; } +static bool hist_field_is_signed (struct hist_field *hist_field) +{ +if (hist_field->field) +return hist_field->field->is_signed; + +return hist_field->is_signed; +} + static u64 hist_field_log2(struct hist_field *hist_field, struct tracing_map_elt *elt, struct trace_buffer *buffer,
@@ -5586,7 +5594,11 @@ static void hist_trigger_print_key(struct seq_file *m, (char *)(key + key_field->offset)); }else { uval = *(u64 *)(key + key_field->offset); -seq_printf (m,"%s: %10llu" , field_name, uval); +if (hist_field_is_signed (key_field)) +seq_printf (m,"%s: %10lld" , field_name, + (s64 )uval); +else +seq_printf (m,"%s: %10llu" , field_name, uval); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1651/2151 ublk: allow a NULL io->cmd in the cancel callback
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit 4915dc0a1834457520ef0592bfd454b26901614f ]
A cancel from the control path, like STOP_DEV's ublk_cancel_dev() after dropping ub->mutex, takes the command and clears io->cmd under cancel_lock, then completes it with io_uring_cmd_done(), which takes uring_lock to remove it from the cancelable list. The server's io_uring cancel runs ublk_uring_cmd_cancel_fn() under uring_lock in between:
control path cancel io_uring cancel (uring_lock)
io->cmd = NULL, CANCELED
io_uring_cmd_done()
waits for uring_lock cmd still on the list
ublk_uring_cmd_cancel_fn(cmd)
io->cmd == NULL: WARN
ublk_cancel_cmd() then sees CANCELED and leaves the command alone, so nothing is wrong; only warn if io->cmd holds another command.
--- drivers/block/ublk_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/block/ublk_drv.c +4 -1
@@ -2029,6 +2029,7 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd, {struct ublk_uring_cmd_pdu *pdu =ublk_get_uring_cmd_pdu (cmd);struct ublk_queue *ubq = pdu->ubq; +struct io_uring_cmd *cur;struct task_struct *task;struct ublk_io *io;
@@ -2045,7 +2046,9 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd,ublk_start_cancel (ubq->dev); -WARN_ON_ONCE (io->cmd != cmd); +/* NULL if a cancel from the control path took it meanwhile */ + cur =READ_ONCE (io->cmd); +WARN_ON_ONCE (cur && cur != cmd);ublk_cancel_cmd (ubq, pdu->tag, issue_flags); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1652/2151 block: cleanup blkdev_report_zones()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
[ Upstream commit e8ecb21f081fe0cab33dc20cbe65ccbbfe615c15 ]
The variable capacity is used only in one place and so can be removed and get_capacity(disk) used directly instead.
Stable-dep-of: 80897c7e5ae5 ("ublk: use global index for reported zones")
--- block/blk-zoned.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-zoned.c +1 -2
@@ -161,7 +161,6 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data) { struct gendisk *disk = bdev->bd_disk; -sector_t capacity =get_capacity (disk); struct disk_report_zones_cb_args args = { .disk = disk, .user_cb = cb,
@@ -171,7 +170,7 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,if (!bdev_is_zoned (bdev) ||WARN_ON_ONCE (!disk->fops->report_zones))return -EOPNOTSUPP ; -if (!nr_zones || sector >= capacity) +if (!nr_zones || sector >=get_capacity (disk))return 0 ; return disk->fops->report_zones(disk, sector, nr_zones,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1653/2151 block: introduce disk_report_zone()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
[ Upstream commit fdb9aed869f34d776298b3a8197909eb820e4d0d ]
Commit b76b840fd933 ("dm: Fix dm-zoned-reclaim zone write pointer alignment") introduced an indirect call for the callback function of a report zones executed with blkdev_report_zones(). This is necessary so that the function disk_zone_wplug_sync_wp_offset() can be called to refresh a zone write plug zone write pointer offset after a write error. However, this solution makes following the path of a zone information harder to understand.
Clean this up by introducing the new blk_report_zones_args structure to define a zone report callback and its private data and introduce the helper function disk_report_zone() which calls both disk_zone_wplug_sync_wp_offset() and the zone report user callback function for all zones of a zone report. This helper function must be called by all block device drivers that implement the report zones block operation in order to correctly report a zone information.
All block device drivers supporting the report_zones block operation are updated to use this new scheme.
Stable-dep-of: 80897c7e5ae5 ("ublk: use global index for reported zones")
--- block/blk-zoned.c | 79 ++++++++++++++++--------------- drivers/block/null_blk/null_blk.h | 3 +- drivers/block/null_blk/zoned.c | 4 +- drivers/block/ublk_drv.c | 4 +- drivers/block/virtio_blk.c | 11 +++-- drivers/block/zloop.c | 4 +- drivers/md/dm-zone.c | 54 +++++++++++---------- drivers/md/dm.h | 3 +- drivers/nvme/host/core.c | 5 +- drivers/nvme/host/multipath.c | 4 +- drivers/nvme/host/nvme.h | 2 +- drivers/nvme/host/zns.c | 10 ++-- drivers/scsi/sd.h | 2 +- drivers/scsi/sd_zbc.c | 20 +++----- include/linux/blkdev.h | 7 ++- include/linux/device-mapper.h | 10 +++- 16 files changed, 120 insertions(+), 102 deletions(-)
block/blk-zoned.c +42 -37
@@ -114,30 +114,16 @@ const char *blk_zone_cond_str(enum blk_zone_cond zone_cond) }EXPORT_SYMBOL_GPL (blk_zone_cond_str); -struct disk_report_zones_cb_args { -struct gendisk *disk; -report_zones_cb user_cb; -void *user_data; +/* +* Zone report arguments for block device drivers report_zones operation. +* @cb: report_zones_cb callback for each reported zone. +* @data: Private data passed to report_zones_cb. +*/ +struct blk_report_zones_args { +report_zones_cb cb; +void *data; }; -static void disk_zone_wplug_sync_wp_offset (struct gendisk *disk, -struct blk_zone *zone); - -static int disk_report_zones_cb (struct blk_zone *zone,unsigned int idx, -void *data) -{ -struct disk_report_zones_cb_args *args = data; -struct gendisk *disk = args->disk; - -if (disk->zone_wplugs_hash) -disk_zone_wplug_sync_wp_offset (disk, zone); - -if (!args->user_cb) -return 0 ; - -return args->user_cb (zone, idx, args->user_data); -} -/** * blkdev_report_zones - Get zones information * @bdev: Target block device
@@ -161,10 +147,9 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data) { struct gendisk *disk = bdev->bd_disk; -struct disk_report_zones_cb_args args = { - .disk = disk, - .user_cb = cb, - .user_data = data, +struct blk_report_zones_args args = { + .cb = cb, + .data = data, };if (!bdev_is_zoned (bdev) ||WARN_ON_ONCE (!disk->fops->report_zones))
@@ -173,8 +158,7 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,if (!nr_zones || sector >=get_capacity (disk))return 0 ; -return disk->fops->report_zones (disk, sector, nr_zones, - disk_report_zones_cb, &args); +return disk->fops->report_zones (disk, sector, nr_zones, &args); }EXPORT_SYMBOL_GPL (blkdev_report_zones);
@@ -676,15 +660,32 @@ static void disk_zone_wplug_sync_wp_offset(struct gendisk *disk,disk_put_zone_wplug (zwplug); } -static int disk_zone_sync_wp_offset (struct gendisk *disk,sector_t sector) +/** +* disk_report_zone - Report one zone +* @disk: Target disk +* @zone: The zone to report +* @idx: The index of the zone in the overall zone report +* @args: report zones callback and data +* +* Description: +* Helper function for block device drivers to report one zone of a zone +* report initiated with blkdev_report_zones(). The zone being reported is +* specified by @zone and used to update, if necessary, the zone write plug +* information for the zone. If @args specifies a user callback function, +* this callback is executed. +*/ +int disk_report_zone (struct gendisk *disk,struct blk_zone *zone, +unsigned int idx,struct blk_report_zones_args *args) { -struct disk_report_zones_cb_args args = { - .disk = disk, - }; +if (disk->zone_wplugs_hash) +disk_zone_wplug_sync_wp_offset (disk, zone); + +if (args && args->cb) +return args->cb (zone, idx, args->data); -return disk->fops->report_zones (disk, sector,1 , - disk_report_zones_cb, &args); +return 0 ; } +EXPORT_SYMBOL_GPL (disk_report_zone);static void blk_zone_reset_bio_endio (struct bio *bio) {
@@ -1801,6 +1802,10 @@ int blk_revalidate_disk_zones(struct gendisk *disk)sector_t capacity =get_capacity (disk);struct blk_revalidate_zone_args args = { };unsigned int memflags, noio_flag; +struct blk_report_zones_args rep_args = { + .cb = blk_revalidate_zone_cb, + .data = &args, + };int ret = -ENOMEM ;if (WARN_ON_ONCE (!blk_queue_is_zoned (q)))
@@ -1832,8 +1837,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)return ret; } - ret = disk->fops->report_zones (disk,0 ,UINT_MAX , - blk_revalidate_zone_cb, &args); + ret = disk->fops->report_zones (disk,0 ,UINT_MAX , &rep_args);if (!ret) {pr_warn ("%s: No zones reported\n" , disk->disk_name); ret = -ENODEV ;
@@ -1878,6 +1882,7 @@ EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones);int blk_zone_issue_zeroout (struct block_device *bdev,sector_t sector,sector_t nr_sects,gfp_t gfp_mask) { +struct gendisk *disk = bdev->bd_disk;int ret;if (WARN_ON_ONCE (!bdev_is_zoned (bdev)))
@@ -1893,7 +1898,7 @@ int blk_zone_issue_zeroout(struct block_device *bdev, sector_t sector,* pointer. Undo this using a report zone to update the zone write * pointer to the correct current value. */ - ret =disk_zone_sync_wp_offset (bdev->bd_disk, sector); + ret = disk->fops->report_zones (disk, sector,1 ,NULL );if (ret !=1 )return ret <0 ? ret : -EIO ;
drivers/block/null_blk/null_blk.h +2 -1
@@ -143,7 +143,8 @@ int null_init_zoned_dev(struct nullb_device *dev, struct queue_limits *lim);int null_register_zoned_dev (struct nullb *nullb);void null_free_zoned_dev (struct nullb_device *dev);int null_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data); +unsigned int nr_zones, +struct blk_report_zones_args *args);blk_status_t null_process_zoned_cmd (struct nullb_cmd *cmd,enum req_op op,sector_t sector,sector_t nr_sectors); size_t null_zone_valid_read_len(struct nullb *nullb,
drivers/block/null_blk/zoned.c +2 -2
@@ -197,7 +197,7 @@ void null_free_zoned_dev(struct nullb_device *dev) }int null_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones,struct blk_report_zones_args *args) {struct nullb *nullb = disk->private_data;struct nullb_device *dev = nullb->dev;
@@ -231,7 +231,7 @@ int null_report_zones(struct gendisk *disk, sector_t sector, blkz.capacity = zone->capacity;null_unlock_zone (dev, zone); - error =cb (&blkz, i, data); + error =disk_report_zone (disk, &blkz, i, args);if (error)return error; }
drivers/block/ublk_drv.c +2 -2
@@ -373,7 +373,7 @@ static void *ublk_alloc_report_buffer(struct ublk_device *ublk, }static int ublk_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones,struct blk_report_zones_args *args) {struct ublk_device *ub = disk->private_data;unsigned int zone_size_sectors = disk->queue->limits.chunk_sectors;
@@ -436,7 +436,7 @@ static int ublk_report_zones(struct gendisk *disk, sector_t sector,if (!zone->len)break ; - ret =cb (zone, i, data); + ret =disk_report_zone (disk, zone, i, args);if (ret) goto out;
drivers/block/virtio_blk.c +6 -5
@@ -584,7 +584,8 @@ static int virtblk_submit_zone_report(struct virtio_blk *vblk,static int virtblk_parse_zone (struct virtio_blk *vblk,struct virtio_blk_zone_descriptor *entry, -unsigned int idx,report_zones_cb cb,void *data) +unsigned int idx, +struct blk_report_zones_args *args) {struct blk_zone zone = { };
@@ -650,12 +651,12 @@ static int virtblk_parse_zone(struct virtio_blk *vblk,* The callback below checks the validity of the reported * entry data, no need to further validate it here. */ -return cb (&zone, idx, data); +return disk_report_zone (vblk->disk, &zone, idx, args); }static int virtblk_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb, -void *data) +unsigned int nr_zones, +struct blk_report_zones_args *args) {struct virtio_blk *vblk = disk->private_data;struct virtio_blk_zone_report *report;
@@ -693,7 +694,7 @@ static int virtblk_report_zones(struct gendisk *disk, sector_t sector,for (i =0 ; i < nz && zone_idx < nr_zones; i++) { ret =virtblk_parse_zone (vblk, &report->zones[i], - zone_idx, cb, data); + zone_idx, args);if (ret) goto fail_report;
drivers/block/zloop.c +2 -2
@@ -682,7 +682,7 @@ static int zloop_open(struct gendisk *disk, blk_mode_t mode) }static int zloop_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones,struct blk_report_zones_args *args) {struct zloop_device *zlo = disk->private_data;struct blk_zone blkz = {};
@@ -722,7 +722,7 @@ static int zloop_report_zones(struct gendisk *disk, sector_t sector,mutex_unlock (&zone->lock); - ret =cb (&blkz, i, data); + ret =disk_report_zone (disk, &blkz, i, args);if (ret)return ret; }
drivers/md/dm-zone.c +30 -24
96 lines not on this page · raw message
drivers/md/dm.h +2 -1
@@ -109,7 +109,8 @@ void dm_finalize_zone_settings(struct dm_table *t, struct queue_limits *lim);void dm_zone_endio (struct dm_io *io,struct bio *clone);#ifdef CONFIG_BLK_DEV_ZONED int dm_blk_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data); +unsigned int nr_zones, +struct blk_report_zones_args *args);bool dm_is_zone_write (struct mapped_device *md,struct bio *bio); int dm_zone_get_reset_bitmap(struct mapped_device *md, struct dm_table *t, sector_t sector, unsigned int nr_zones,
drivers/nvme/host/core.c +2 -3
@@ -2633,10 +2633,9 @@ static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended)#ifdef CONFIG_BLK_DEV_ZONED static int nvme_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones,struct blk_report_zones_args *args) { -return nvme_ns_report_zones (disk->private_data, sector, nr_zones, cb, - data); +return nvme_ns_report_zones (disk->private_data, sector, nr_zones, args); }#else #define nvme_report_zones NULL
drivers/nvme/host/multipath.c +2 -2
@@ -582,7 +582,7 @@ static int nvme_ns_head_get_unique_id(struct gendisk *disk, u8 id[16],#ifdef CONFIG_BLK_DEV_ZONED static int nvme_ns_head_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones,struct blk_report_zones_args *args) {struct nvme_ns_head *head = disk->private_data;struct nvme_ns *ns;
@@ -591,7 +591,7 @@ static int nvme_ns_head_report_zones(struct gendisk *disk, sector_t sector, srcu_idx =srcu_read_lock (&head->srcu); ns =nvme_find_path (head);if (ns) - ret =nvme_ns_report_zones (ns, sector, nr_zones, cb, data); + ret =nvme_ns_report_zones (ns, sector, nr_zones, args);srcu_read_unlock (&head->srcu, srcu_idx);return ret; }
drivers/nvme/host/nvme.h +1 -1
@@ -1176,7 +1176,7 @@ struct nvme_zone_info { };int nvme_ns_report_zones (struct nvme_ns *ns,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data); +unsigned int nr_zones,struct blk_report_zones_args *args);int nvme_query_zone_info (struct nvme_ns *ns,unsigned lbaf,struct nvme_zone_info *zi); void nvme_update_zone_info(struct nvme_ns *ns, struct queue_limits *lim,
drivers/nvme/host/zns.c +5 -5
@@ -148,8 +148,8 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns,static int nvme_zone_parse_entry (struct nvme_ns *ns,struct nvme_zone_descriptor *entry, -unsigned int idx,report_zones_cb cb, -void *data) +unsigned int idx, +struct blk_report_zones_args *args) {struct nvme_ns_head *head = ns->head;struct blk_zone zone = { };
@@ -169,11 +169,11 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns,else zone.wp =nvme_lba_to_sect (head,le64_to_cpu (entry->wp)); -return cb (&zone, idx, data); +return disk_report_zone (ns->disk, &zone, idx, args); }int nvme_ns_report_zones (struct nvme_ns *ns,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones,struct blk_report_zones_args *args) {struct nvme_zone_report *report;struct nvme_command c = { };
@@ -217,7 +217,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,for (i =0 ; i < nz && zone_idx < nr_zones; i++) { ret =nvme_zone_parse_entry (ns, &report->entries[i], - zone_idx, cb, data); + zone_idx, args);if (ret) goto out_free; zone_idx++;
drivers/scsi/sd.h +1 -1
@@ -240,7 +240,7 @@ blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,unsigned int sd_zbc_complete (struct scsi_cmnd *cmd,unsigned int good_bytes,struct scsi_sense_hdr *sshdr);int sd_zbc_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data); +unsigned int nr_zones,struct blk_report_zones_args *args);#else /* CONFIG_BLK_DEV_ZONED */
drivers/scsi/sd_zbc.c +7 -13
@@ -35,8 +35,7 @@ static bool sd_zbc_is_gap_zone(const u8 buf[64])* @buf: SCSI zone descriptor. * @idx: Index of the zone relative to the first zone reported by the current * sd_zbc_report_zones() call. -* @cb: Callback function pointer. -* @data: Second argument passed to @cb. +* @args: report zones arguments (callback, etc) * * Return: Value returned by @cb. *
@@ -44,12 +43,11 @@ static bool sd_zbc_is_gap_zone(const u8 buf[64])* call @cb(blk_zone, @data). */ static int sd_zbc_parse_report (struct scsi_disk *sdkp,const u8 buf[64 ], -unsigned int idx,report_zones_cb cb,void *data) +unsigned int idx,struct blk_report_zones_args *args) {struct scsi_device *sdp = sdkp->device;struct blk_zone zone = {0 };sector_t start_lba, gran; -int ret;if (WARN_ON_ONCE (sd_zbc_is_gap_zone (buf)))return -EINVAL ;
@@ -87,11 +85,7 @@ static int sd_zbc_parse_report(struct scsi_disk *sdkp, const u8 buf[64],else zone.wp =logical_to_sectors (sdp,get_unaligned_be64 (&buf[24 ])); - ret =cb (&zone, idx, data); -if (ret) -return ret; - -return 0 ; +return disk_report_zone (sdkp->disk, &zone, idx, args); }/**
@@ -217,14 +211,14 @@ static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp)* @disk: Disk to report zones for. * @sector: Start sector. * @nr_zones: Maximum number of zones to report. -* @cb: Callback function called to report zone information. -* @data: Second argument passed to @cb. +* @args: Callback arguments. * * Called by the block layer to iterate over zone information. See also the * disk->fops->report_zones() calls in block/blk-zoned.c. */ int sd_zbc_report_zones (struct gendisk *disk,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data) +unsigned int nr_zones, +struct blk_report_zones_args *args) {struct scsi_disk *sdkp =scsi_disk (disk);sector_t lba =sectors_to_logical (sdkp->device, sector);
@@ -283,7 +277,7 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, } ret =sd_zbc_parse_report (sdkp, buf + offset, zone_idx, - cb, data); + args);if (ret) goto out;
include/linux/blkdev.h +6 -1
@@ -38,6 +38,7 @@ struct blk_flush_queue;struct kiocb ;struct pr_ops ;struct rq_qos ; +struct blk_report_zones_args ;struct blk_queue_stats ;struct blk_stat_callback ;struct blk_crypto_profile ;
@@ -432,6 +433,9 @@ struct queue_limits {typedef int (*report_zones_cb )(struct blk_zone *zone,unsigned int idx,void *data); +int disk_report_zone (struct gendisk *disk,struct blk_zone *zone, +unsigned int idx,struct blk_report_zones_args *args); +#define BLK_ALL_ZONES ((unsigned int)-1)int blkdev_report_zones (struct block_device *bdev,sector_t sector,unsigned int nr_zones,report_zones_cb cb,void *data);
@@ -1658,7 +1662,8 @@ struct block_device_operations {/* this callback is with swap_lock and sometimes page table lock held */ void (*swap_slot_free_notify) (struct block_device *,unsigned long );int (*report_zones)(struct gendisk *,sector_t sector, -unsigned int nr_zones,report_zones_cb cb,void *data); +unsigned int nr_zones, +struct blk_report_zones_args *args);char *(*devnode)(struct gendisk *disk,umode_t *mode);/* returns the length of the identifier or a negative errno: */ int (*get_unique_id)(struct gendisk *disk, u8 id[16],
include/linux/device-mapper.h +8 -2
@@ -538,12 +538,18 @@ void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone);#ifdef CONFIG_BLK_DEV_ZONED struct dm_report_zones_args {struct dm_target *tgt; +struct gendisk *disk;sector_t next_sector; -void *orig_data; -report_zones_cb orig_cb;unsigned int zone_idx; +/* for block layer ->report_zones */ +struct blk_report_zones_args *rep_args; + +/* for internal users */ +report_zones_cb cb; +void *data; +/* must be filled by ->report_zones before calling dm_report_zones_cb */ sector_t start; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1654/2151 ublk: use global index for reported zones
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 80897c7e5ae5c56f37a2eb004328edcb4da7cdd1 ]
ublk_report_zones() may split a zone report into multiple requests when the number of zones exceeds the temporary buffer capacity. The index passed to disk_report_zone() must refer to the zone position in the whole report, rather than the position within the current request.
Currently, the per-request loop index is used as the callback index, causing each chunk after the first one to restart from zero. This can make userspace callbacks receive duplicate zone indices and may result in blk_revalidate_disk_zones() updating incorrect entries in its zone state array.
Use the number of zones already reported as the base index for each request so that zone indices remain continuous across all chunks.
--- drivers/block/ublk_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/ublk_drv.c +1 -1
@@ -436,7 +436,7 @@ static int ublk_report_zones(struct gendisk *disk, sector_t sector,if (!zone->len)break ; - ret =disk_report_zone (disk, zone, i, args); + ret =disk_report_zone (disk, zone, done_zones, args);if (ret) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1655/2151 selftests/bpf: Fix prog_tests framework subtest count checks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: KaFai Wan <[email protected]>
[ Upstream commit c87652656a55e5e8cf994364314a75fa95fb2d69 ]
The hardcoded expected skip_cnt/error_cnt in test_prog_tests_framework() mismatch the real count when the binary is run with -t or -n filters, since some subtests are not selected. Count the executed subtests and compare against that value instead.
--- .../selftests/bpf/prog_tests/prog_tests_framework.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c +8 -2
@@ -13,6 +13,7 @@ static void clear_test_state(struct test_state *state)void test_prog_tests_framework (void ) {struct test_state *state = env.test_state; +int subtest_cnt;/* in all the ASSERT calls below we need to return on the first * error due to the fact that we are cleaning the test state after
@@ -30,25 +31,30 @@ void test_prog_tests_framework(void)return ;clear_test_state (state); + subtest_cnt =0 ;if (test__start_subtest ("test_skip_subtest" )) {test__skip ();test__end_subtest (); + subtest_cnt++; }if (test__start_subtest ("test_skip_subtest" )) {test__skip ();test__end_subtest (); + subtest_cnt++; } -if (!ASSERT_EQ (state->skip_cnt,2 ,"skip_cnt_check" )) +if (!ASSERT_EQ (state->skip_cnt, subtest_cnt,"skip_cnt_check" ))return ;if (!ASSERT_EQ (state->subtest_num,3 ,"subtest_num_check" ))return ;clear_test_state (state); + subtest_cnt =0 ;if (test__start_subtest ("test_fail_subtest" )) {test__fail ();test__end_subtest (); + subtest_cnt++; } -if (!ASSERT_EQ (state->error_cnt,1 ,"error_cnt_check" )) +if (!ASSERT_EQ (state->error_cnt, subtest_cnt,"error_cnt_check" ))return ;if (!ASSERT_EQ (state->subtest_num,4 ,"subtest_num_check" ))return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1656/2151 selftests/bpf: Skip expected_msgs subtests when stdout is not saved
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: KaFai Wan <[email protected]>
[ Upstream commit cc4b1c161d92992544cc571a2475baa5b072e120 ]
stdio_hijack_init() does not set subtest_state->stdout_saved when running with -v in non-parallel mode, since output goes straight to stdout. In that case subtest_state->log_buf is left NULL, so the expected-messages subtests crash when inspecting it. Skip them when stdout was not saved.
--- .../testing/selftests/bpf/prog_tests/prog_tests_framework.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c +6 -0
@@ -169,6 +169,12 @@ void test_prog_tests_framework_expected_msgs(void)for (i =0 ; i <ARRAY_SIZE (cases); i++) {if (test__start_subtest (cases[i].name)) { +if (!env.subtest_state->stdout_saved) { +test__skip (); +test__end_subtest (); +continue ; + } + error_cnt = env.subtest_state->error_cnt; msgs.patterns = cases[i].pats; msgs.cnt =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1657/2151 bpf: Migrate bpf_task_work to kmalloc_nolock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mykyta Yatsenko <[email protected]>
[ Upstream commit 90f51ebff242e9446a9bbd3ce1a04d50c30e8b96 ]
Replace bpf_mem_alloc/bpf_mem_free with
kmalloc_nolock/kfree_rcu for bpf_task_work_ctx.
Replace guard(rcu_tasks_trace)() with guard(rcu)() in bpf_task_work_irq(). The function only accesses ctx struct members (not map values), so tasks trace protection is not needed - regular RCU is sufficient since ctx is freed via kfree_rcu. The guard in bpf_task_work_callback() remains as tasks trace since it accesses map values from process context.
Sleepable BPF programs hold rcu_read_lock_trace but not regular rcu_read_lock. Since kfree_rcu
waits for a regular RCU grace period, the ctx memory can be freed while a sleepable program is still running. Add scoped_guard(rcu) around the pointer read and refcount tryget in bpf_task_work_acquire_ctx to close this race window.
Since kfree_rcu uses call_rcu internally which is not safe from NMI context, defer destruction via irq_work when irqs are disabled.
For the lost-cmpxchg path the ctx was never published, so kfree_nolock is safe.
Stable-dep-of: c961f7b41a10 ("bpf: Fix NULL task dereference in task work cancellation")
--- kernel/bpf/helpers.c | 56 +++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 19 deletions(-)
kernel/bpf/helpers.c +37 -19
@@ -3986,17 +3986,25 @@ static bool bpf_task_work_ctx_tryget(struct bpf_task_work_ctx *ctx)return refcount_inc_not_zero (&ctx->refcnt); } +static void bpf_task_work_destroy (struct irq_work *irq_work) +{ + struct bpf_task_work_ctx *ctx = container_of(irq_work, struct bpf_task_work_ctx, irq_work); + +bpf_task_work_ctx_reset (ctx); +kfree_rcu (ctx, rcu); +} +static void bpf_task_work_ctx_put (struct bpf_task_work_ctx *ctx) {if (!refcount_dec_and_test (&ctx->refcnt))return ; -bpf_task_work_ctx_reset (ctx); - -/* bpf_mem_free expects migration to be disabled */ -migrate_disable (); -bpf_mem_free (&bpf_global_ma, ctx); -migrate_enable (); +if (irqs_disabled ()) { + ctx->irq_work =IRQ_WORK_INIT (bpf_task_work_destroy); +irq_work_queue (&ctx->irq_work); + }else { +bpf_task_work_destroy (&ctx->irq_work); + } }static void bpf_task_work_cancel (struct bpf_task_work_ctx *ctx)
@@ -4051,7 +4059,7 @@ static void bpf_task_work_irq(struct irq_work *irq_work)enum bpf_task_work_state state;int err; -guard (rcu_tasks_trace)(); +guard (rcu)();if (cmpxchg (&ctx->state,BPF_TW_PENDING ,BPF_TW_SCHEDULING ) !=BPF_TW_PENDING ) {bpf_task_work_ctx_put (ctx);
@@ -4073,9 +4081,9 @@ static void bpf_task_work_irq(struct irq_work *irq_work)/* * It's technically possible for just scheduled task_work callback to * complete running by now, going SCHEDULING -> RUNNING and then -* dropping its ctx refcount. Instead of capturing extra ref just to -* protected below ctx->state access, we rely on RCU protection to -* perform below SCHEDULING -> SCHEDULED attempt. +* dropping its ctx refcount. Instead of capturing an extra ref just +* to protect below ctx->state access, we rely on rcu_read_lock +* above to prevent kfree_rcu from freeing ctx before we return. */ state =cmpxchg (&ctx->state,BPF_TW_SCHEDULING ,BPF_TW_SCHEDULED );if (state ==BPF_TW_FREED )
@@ -4092,7 +4100,7 @@ static struct bpf_task_work_ctx *bpf_task_work_fetch_ctx(struct bpf_task_work *tif (ctx)return ctx; - ctx =bpf_mem_alloc (&bpf_global_ma,sizeof (struct bpf_task_work_ctx )); + ctx =bpf_map_kmalloc_nolock (map,sizeof (*ctx),0 ,NUMA_NO_NODE );if (!ctx)return ERR_PTR (-ENOMEM );
@@ -4106,7 +4114,7 @@ static struct bpf_task_work_ctx *bpf_task_work_fetch_ctx(struct bpf_task_work *t* tw->ctx is set by concurrent BPF program, release allocated * memory and try to reuse already set context. */ -bpf_mem_free (&bpf_global_ma, ctx); +kfree_nolock (ctx);return old_ctx; }
@@ -4118,13 +4126,23 @@ static struct bpf_task_work_ctx *bpf_task_work_acquire_ctx(struct bpf_task_work {struct bpf_task_work_ctx *ctx; - ctx =bpf_task_work_fetch_ctx (tw, map); -if (IS_ERR (ctx)) -return ctx; - -/* try to get ref for task_work callback to hold */ -if (!bpf_task_work_ctx_tryget (ctx)) -return ERR_PTR (-EBUSY ); +/* +* Sleepable BPF programs hold rcu_read_lock_trace but not +* regular rcu_read_lock. Since kfree_rcu waits for regular +* RCU GP, the ctx can be freed while we're between reading +* the pointer and incrementing the refcount. Take regular +* rcu_read_lock to prevent kfree_rcu from freeing the ctx +* before we can tryget it. +*/ +scoped_guard (rcu) { + ctx =bpf_task_work_fetch_ctx (tw, map); +if (IS_ERR (ctx)) +return ctx; + +/* try to get ref for task_work callback to hold */ +if (!bpf_task_work_ctx_tryget (ctx)) +return ERR_PTR (-EBUSY ); + }if (cmpxchg (&ctx->state,BPF_TW_STANDBY ,BPF_TW_PENDING ) !=BPF_TW_STANDBY ) {/* lost acquiring race or map_release_uref() stole it from us, put ref and bail */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1658/2151 bpf: Fix NULL task dereference in task work cancellation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Lu <[email protected]>
[ Upstream commit c961f7b41a108313a4705baac7b27d2174cc8035 ]
bpf_task_work_irq() publishes ctx->work with task_work_add() before changing the context from SCHEDULING to SCHEDULED. The target task can run the callback on another CPU before the handler reaches its final state transition.
The handler then reloads ctx->task for cancellation if its final cmpxchg observes FREED. By that point the callback or context destruction may already have cleared ctx->task, causing task_work_cancel() to dereference a NULL task pointer.
One concrete interleaving is:
1. CPU 0 changes PENDING to SCHEDULING and successfully queues
ctx->work with task_work_add(), but has not attempted the final
state cmpxchg. 2. The target task on CPU 1 runs the callback. It changes SCHEDULING to RUNNING, executes the BPF subprogram, resets ctx->task, publishes STANDBY and drops the callback's context reference.
3. CPU 2 deletes the map value. It changes STANDBY to FREED and drops the map's context reference without queuing asynchronous cancellation.
4. CPU 0 resumes. Its SCHEDULING-to-SCHEDULED cmpxchg observes FREED, and the cancellation attempt passes NULL to task_work_cancel().
If deletion publishes FREED before the callback claims RUNNING, the callback takes its FREED exit and drops its context reference. Context destruction can then clear ctx->task before CPU 0 attempts cancellation.
A controlled reproducer with a delay before the final cmpxchg triggered the following fault on a v7.3-rc3 based x86-64 KVM guest:
BUG: kernel NULL pointer dereference, address: 0000000000000890 RIP: 0010:task_work_cancel+0xd/0xa0 RDI: 0000000000000000 CR2: 0000000000000890 Call Trace: <IRQ> bpf_task_work_irq+0x95/0x100 irq_work_run_list+0x4f/0x90 irq_work_run+0x18/0x50 </IRQ>
0x890 is the task_struct::task_works offset in that build, read through the NULL task argument.
Capture ctx->task before task_work_add() publishes the callback and use that pointer for the handler's cancellation attempt. The round still holds its task reference when the pointer is captured. Releasing that reference uses bpf_task_release(), which calls put_task_struct_rcu_user(), so the handler's existing RCU read-side section keeps the captured task alive even if ctx->task is subsequently cleared.
The asynchronous cancellation path reads ctx->task directly, which is safe there: queuing it requires deletion to observe SCHEDULED, and that xchg wins against the callback's transition to RUNNING, so the callback takes its FREED exit without resetting ctx->task, while the map reference transferred to the cancellation handler prevents context destruction until cancellation completes.
The handler-tail and asynchronous cancellation attempts are mutually
exclusive: asynchronous cancellation is queued only if deletion observes SCHEDULED after the scheduling handler's final cmpxchg has succeeded. If that cmpxchg instead observes FREED, the scheduling handler attempts cancellation with the captured pointer.
--- kernel/bpf/helpers.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
kernel/bpf/helpers.c +31 -9
@@ -4007,15 +4007,21 @@ static void bpf_task_work_ctx_put(struct bpf_task_work_ctx *ctx) } } -static void bpf_task_work_cancel (struct bpf_task_work_ctx *ctx) +static void bpf_task_work_cancel (struct bpf_task_work_ctx *ctx, +struct task_struct *task) {/* * Scheduled task_work callback holds ctx ref, so if we successfully * cancelled, we put that ref on callback's behalf. If we couldn't * cancel, callback will inevitably run or has already completed * running, and it would have taken care of its ctx ref itself. +* +* The caller passes the task explicitly: the scheduling handler must +* not read ctx->task after the work is published (the callback may +* have reset it), while in the asynchronous cancellation path +* ctx->task is stable, see bpf_task_work_cancel_scheduled(). */ -if (task_work_cancel (ctx->task, &ctx->work)) +if (task_work_cancel (task, &ctx->work))bpf_task_work_ctx_put (ctx); }
@@ -4056,6 +4062,7 @@ static void bpf_task_work_callback(struct callback_head *cb)static void bpf_task_work_irq (struct irq_work *irq_work) { struct bpf_task_work_ctx *ctx = container_of(irq_work, struct bpf_task_work_ctx, irq_work); +struct task_struct *task;enum bpf_task_work_state state;int err;
@@ -4066,7 +4073,16 @@ static void bpf_task_work_irq(struct irq_work *irq_work)return ; } - err =task_work_add (ctx->task, &ctx->work, ctx->mode); +/* +* Capture the task pointer before the work is published: once the +* callback runs, it may reset ctx->task. The capture happens while +* this round's task reference is held, and every path that can +* release it runs after this handler entered its rcu read-side +* section. bpf_task_release() is put_task_struct_rcu_user(), so the +* task_struct itself cannot be freed before this section ends. +*/ + task = ctx->task; + err =task_work_add (task, &ctx->work, ctx->mode);if (err) {bpf_task_work_ctx_reset (ctx);/*
@@ -4080,14 +4096,14 @@ static void bpf_task_work_irq(struct irq_work *irq_work)/* * It's technically possible for just scheduled task_work callback to -* complete running by now, going SCHEDULING -> RUNNING and then -* dropping its ctx refcount. Instead of capturing an extra ref just -* to protect below ctx->state access, we rely on rcu_read_lock -* above to prevent kfree_rcu from freeing ctx before we return. +* complete running by now, going SCHEDULING -> RUNNING, resetting +* ctx->task and dropping its ctx refcount. The rcu read-side section +* above keeps both the ctx memory and the captured task pointer +* valid until this handler returns. */ state =cmpxchg (&ctx->state,BPF_TW_SCHEDULING ,BPF_TW_SCHEDULED );if (state ==BPF_TW_FREED ) -bpf_task_work_cancel (ctx);/* clean up if we switched into FREED state */ +bpf_task_work_cancel (ctx, task);/* clean up if we switched into FREED state */ } static struct bpf_task_work_ctx *bpf_task_work_fetch_ctx(struct bpf_task_work *tw,
@@ -4254,7 +4270,13 @@ static void bpf_task_work_cancel_scheduled(struct irq_work *irq_work) { struct bpf_task_work_ctx *ctx = container_of(irq_work, struct bpf_task_work_ctx, irq_work); -bpf_task_work_cancel (ctx);/* this might put task_work callback's ref */ +/* +* Deletion observed SCHEDULED and won against the callback's +* transition to RUNNING. The callback takes its FREED exit without +* resetting ctx->task, and the transferred map reference prevents +* destruction until cancellation completes. +*/ +bpf_task_work_cancel (ctx, ctx->task);/* this might put task_work callback's ref */ bpf_task_work_ctx_put (ctx);/* and here we put map's own ref that was transferred to us */ }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1659/2151 bpf: Prevent task work context reuse while irq_work is busy
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Lu <[email protected]>
[ Upstream commit a36d9afe8d923ca00dd2001409f420202ee672da ]
A bpf_task_work context can return to STANDBY before its scheduling irq_work handler returns. Both callback completion and task_work_add() failure can publish STANDBY while the irq_work is still BUSY. A new round can then reinitialize and queue the same irq_work on another CPU while the old handler is still running.
One concrete interleaving is:
1. CPU 0 successfully queues ctx->work with task_work_add() and pauses before its SCHEDULING-to-SCHEDULED cmpxchg.
2. The target task on CPU 1 completes the callback, resets ctx->task and publishes STANDBY.
3. CPU 2 starts a new round, changes STANDBY to PENDING and queues the same irq_work. The new handler changes PENDING to SCHEDULING, but task_work_add() returns -ESRCH because its target task has exited. The handler has not yet reset the context or rolled back the state.
4. CPU 0 resumes and changes the new round's SCHEDULING to SCHEDULED, even though no task work was queued for that round.
5. The new handler resets ctx->task, but its SCHEDULING-to-STANDBY cmpxchg fails. The context remains SCHEDULED with a NULL task, and subsequent attempts to acquire this context fail with -EBUSY.
6. Map-value deletion observes SCHEDULED and queues asynchronous
cancellation, which passes the NULL ctx->task to task_work_cancel().
Overlapping invocations also share one BUSY bit. An invocation can clear that bit while the other invocation is still running.
Initialize the scheduling irq_work when the context is created and stop reinitializing it for each round. After claiming the context with the STANDBY-to-PENDING cmpxchg, check BUSY and reject reuse with -EBUSY if a previous invocation is still in progress. Checking after the cmpxchg orders the BUSY read after the STANDBY publication.
No irq_work has been queued for the attempted round at this point, so the rejection can roll PENDING back to STANDBY. Use cmpxchg for that rollback to preserve FREED if a concurrent deletion has published it. Once BUSY clears, scheduling can be retried.
--- kernel/bpf/helpers.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/bpf/helpers.c +13 -1
@@ -4123,6 +4123,7 @@ static struct bpf_task_work_ctx *bpf_task_work_fetch_ctx(struct bpf_task_work *tmemset (ctx,0 ,sizeof (*ctx));refcount_set (&ctx->refcnt,1 );/* map's own ref */ ctx->state =BPF_TW_STANDBY ; +init_irq_work (&ctx->irq_work, bpf_task_work_irq); old_ctx =cmpxchg (&twk->ctx,NULL , ctx);if (old_ctx) {
@@ -4165,6 +4166,18 @@ static struct bpf_task_work_ctx *bpf_task_work_acquire_ctx(struct bpf_task_workbpf_task_work_ctx_put (ctx);return ERR_PTR (-EBUSY ); } +/* +* STANDBY can be published before the previous scheduling irq_work +* returns. Claim PENDING before checking BUSY to order the check after +* that publication. No irq_work has been queued for this attempt yet, +* so reject reuse and roll back to STANDBY while BUSY is set. Preserve +* FREED if deletion wins the rollback race. +*/ +if (unlikely (irq_work_is_busy (&ctx->irq_work))) { + (void )cmpxchg (&ctx->state,BPF_TW_PENDING ,BPF_TW_STANDBY ); +bpf_task_work_ctx_put (ctx); +return ERR_PTR (-EBUSY ); + }/* * If no process or bpffs is holding a reference to the map, no new callbacks should be
@@ -4214,7 +4227,6 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work ctx->map = map; ctx->map_val = (void *)tw - map->record->task_work_off;init_task_work (&ctx->work, bpf_task_work_callback); -init_irq_work (&ctx->irq_work, bpf_task_work_irq);irq_work_queue (&ctx->irq_work);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1660/2151 macsec: prevent AES-GCM nonce reuse after packet number wrap
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 94d51c59f0a872c57cb8daa1964ec033d77a79fb ]
After allocating the last valid packet number, MACsec wraps next_pn to zero and deactivates the transmit SA. This happens for both 32- and 64-bit types of packet numbers (at values 0xffffffff and 0xffffffffffffffff, respectively).
TX packets that were still getting processed during deactivation keep being processed and then receive packet numbers. The first gets 0 and is correctly dropped, but next_pn is incremented to 1, which makes the next packet take number 1. It then does not get dropped and may induce a reuse of the AES-GCM nonce corresponding to value 1.
This race affects TX packets that have already passed the SA activity
check: packets that observe the inactive SA are correctly dropped. Reactivating the SA after PN wrap without a packet number can also cause nonce reuse. Keep next_pn at 0 after wrap, even if the SA is reactivated, so further packet number allocations return 0 and the corresponding packets are dropped.
--- drivers/net/macsec.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/macsec.c +5 -0
@@ -482,6 +482,9 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,spin_lock_bh (&tx_sa->lock); pn = tx_sa->next_pn_halves; +if (unlikely (pn.full64 ==0 )) + goto out; +if (secy->xpn) tx_sa->next_pn++;else
@@ -489,6 +492,8 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,if (tx_sa->next_pn ==0 )__macsec_pn_wrapped (secy, tx_sa); + +out:spin_unlock_bh (&tx_sa->lock);return pn;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1661/2151 net: usb: lan78xx: reject invalid EEPROM write requests
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefano Munari <[email protected]>
[ Upstream commit 9272297df14124fe603c81e40b52ff0c5dd88652 ]
The runtime PM handling removed the -EINVAL return for invalid EEPROM/OTP write requests. These requests now return zero from a successful usb_autopm_get_interface() call, even though no data is written.
Set ret to -EINVAL for invalid requests while preserving the runtime PM reference release.
--- drivers/net/usb/lan78xx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/usb/lan78xx.c +6 -3
@@ -1712,13 +1712,16 @@ static int lan78xx_ethtool_set_eeprom(struct net_device *netdev,/* Invalid EEPROM_INDICATOR at offset zero will result in a failure * to load data from EEPROM */ -if (ee->magic ==LAN78XX_EEPROM_MAGIC ) +if (ee->magic ==LAN78XX_EEPROM_MAGIC ) { ret =lan78xx_write_raw_eeprom (dev, ee->offset, ee->len, data); -else if ((ee->magic ==LAN78XX_OTP_MAGIC ) && + }else if ((ee->magic ==LAN78XX_OTP_MAGIC ) && (ee->offset ==0 ) && (ee->len ==512 ) && - (data[0 ] ==OTP_INDICATOR_1 )) + (data[0 ] ==OTP_INDICATOR_1 )) { ret =lan78xx_write_raw_otp (dev, ee->offset, ee->len, data); + }else { + ret = -EINVAL ; + }usb_autopm_put_interface (dev->intf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1662/2151 dax/bus: Return errors for invalid mapping targets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
[ Upstream commit df6cc0a24717c38ac81b5ba1e839c35e74e667dc ]
After the DAX configuration locking was converted to rwsems, successful lock acquisition leaves rc set to zero in mapping_store(). Two error paths can return this stale value: an unbound region driver and a misaligned range size. The sysfs write therefore reports success without allocating the requested range.
Return -ENXIO when the region driver is not bound and -EINVAL when the range size is misaligned.
--- drivers/dax/bus.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/dax/bus.c +6 -2
@@ -1180,7 +1180,7 @@ static ssize_t mapping_store(struct device *dev, struct device_attribute *attr,return rc;if (!dax_region->dev->driver) {up_write (&dax_region_rwsem); -return rc; +return -ENXIO ; } rc =down_write_killable (&dax_dev_rwsem);if (rc) {
@@ -1189,8 +1189,12 @@ static ssize_t mapping_store(struct device *dev, struct device_attribute *attr, } to_alloc =range_len (&r); -if (alloc_is_aligned (dev_dax, to_alloc)) +if (!alloc_is_aligned (dev_dax, to_alloc)) { +dev_dbg (dev,"%s: size: %zu misaligned\n" , __func__, to_alloc); + rc = -EINVAL ; + }else { rc =alloc_dev_dax_range (dev_dax, r.start, to_alloc); + }up_write (&dax_dev_rwsem);up_write (&dax_region_rwsem);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1663/2151 bnx2x: fix header length calculation for encapsulated TSO
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: George Melikov <[email protected]>
[ Upstream commit 4fc1d5bb448dfab391a96f949d02ad03ad8cda5c ]
Commit 80bfab79b835 ("net: adopt skb_network_offset() and similar helpers") replaced the difference between the inner transport header and the outer network header with skb_inner_transport_offset().
The helper is relative to skb->data, so the new calculation incorrectly includes the outer Ethernet header in fw_ip_hdr_to_payload_w.
On a BCM57810 transmitting TCP over VXLAN with an outer MTU of 1500, hardware segmentation emits packets declaring an outer IPv4 total length of 1514 while the actual IP packet is only 1500 bytes long. The receiver drops these malformed packets, severely degrading TCP connectivity.
Subtract skb_network_offset() to restore the original calculation of the length from the outer network header to the inner TCP payload.
Reproduced with plain kernel VXLAN and one TCP flow on kernel 7.0.0-31-generic: 50 of 200 captured packets had an invalid outer IP length with the original driver, versus none with this fix. Disabling TSO/GSO on the test VXLAN device also eliminated the error with the original driver.
--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +2 -1
@@ -3666,7 +3666,8 @@ static void bnx2x_update_pbds_gso_enc(struct sk_buff *skb,u8 outerip_off, outerip_len =0 ;/* from outer IP to transport */ - hlen_w =skb_inner_transport_offset (skb) >>1 ; + hlen_w = (skb_inner_transport_offset (skb) - +skb_network_offset (skb)) >>1 ;/* transport len */ hlen_w +=inner_tcp_hdrlen (skb) >>1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1664/2151 ipv4: use RCU protection in inet_netconf_get_devconf()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit b2039a6dd36b5c89142bfb95bc0205be8abcc600 ]
inet_netconf_get_devconf() runs without RTNL. It uses dev_get_by_index() and in_dev_get() to pin the device and its in_device while the reply is allocated and filled.
in_dev_get() is not safe for a lockless caller. Since commit 9d40c84cf5bc ("net: devinet: Reduce refcount before grace period"), inetdev_destroy() drops the final reference before the RCU grace period. A reader can load dev->ip_ptr, then call refcount_inc() on a zero refcount after in_dev_free_rcu() has been queued, and keep using the in_device once it has been freed.
None of these references are needed. An in_device is freed after an RCU grace period, ipv4_devconf is embedded in it, and inet_netconf_fill_devconf() does not sleep.
Allocate the skb first, then perform the lookup and the fill under rcu_read_lock(), using dev_get_by_index_rcu() and __in_dev_get_rcu(), like inet_netconf_dump_devconf() already does.
--- net/ipv4/devinet.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
net/ipv4/devinet.c +17 -18
@@ -2278,8 +2278,8 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb,struct net *net =sock_net (in_skb->sk);struct nlattr *tb[NETCONFA_MAX +1 ];const struct ipv4_devconf *devconf; -struct in_device *in_dev =NULL ; -struct net_device *dev =NULL ; +struct in_device *in_dev; +struct net_device *dev;struct sk_buff *skb;int ifindex;int err;
@@ -2291,7 +2291,13 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb,if (!tb[NETCONFA_IFINDEX ])return -EINVAL ; + skb =nlmsg_new (inet_netconf_msgsize_devconf (NETCONFA_ALL ),GFP_KERNEL ); +if (!skb) +return -ENOBUFS ; + ifindex =nla_get_s32 (tb[NETCONFA_IFINDEX ]); + +rcu_read_lock ();switch (ifindex) {case NETCONFA_IFINDEX_ALL : devconf = net->ipv4.devconf_all;
@@ -2301,36 +2307,29 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb,break ;default : err = -ENODEV ; - dev =dev_get_by_index (net, ifindex); -if (dev) - in_dev =in_dev_get (dev); + dev =dev_get_by_index_rcu (net, ifindex); +if (!dev) + goto out_unlock; + in_dev =__in_dev_get_rcu (dev);if (!in_dev) - goto errout; + goto out_unlock; devconf = &in_dev->cnf;break ; } - err = -ENOBUFS ; - skb =nlmsg_new (inet_netconf_msgsize_devconf (NETCONFA_ALL ),GFP_KERNEL ); -if (!skb) - goto errout; - err =inet_netconf_fill_devconf (skb, ifindex, devconf,NETLINK_CB (in_skb).portid, nlh->nlmsg_seq,RTM_NEWNETCONF ,0 ,NETCONFA_ALL ); +out_unlock: +rcu_read_unlock ();if (err <0 ) {/* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ WARN_ON (err == -EMSGSIZE );kfree_skb (skb); - goto errout; +return err; } - err =rtnl_unicast (skb, net,NETLINK_CB (in_skb).portid); -errout: -if (in_dev) -in_dev_put (in_dev); -dev_put (dev); -return err; +return rtnl_unicast (skb, net,NETLINK_CB (in_skb).portid); } static int inet_netconf_dump_devconf(struct sk_buff *skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1665/2151 net: use the full socket in sk_mc_loop()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Theodor Arsenij Larionov Trichkine <[email protected]>
[ Upstream commit 31b564f70d8819a1c11d0fd504fe582fc0e0f0cf ]
sk_mc_loop() is called from ip_mc_output() and ip6_finish_output2() with skb->sk, which is not always a full socket:
- Since commit ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener"), a SYNACK is attached to its request socket.
- Since commit 79636038d37e ("ipv4: tcp: give socket pointer to control skbs"), an ACK or RST sent by ip_send_unicast_reply() on behalf of a TIME_WAIT socket is attached to the timewait socket.
When such a packet uses a multicast route, inet_test_bit(MC_LOOP, sk) reads inet_flags past the end of the request or timewait socket.
This happens for instance when a SYN with a multicast source address reaches a listener, after being looped back with its dst attached, so that ip_rcv_finish_core() skips the martian source check. A raw IP_HDRINCL socket sending to a local address does this, as does re-injection by nft dup or the iptables TEE target. The destination can also come from a source route option, or from a route of type multicast covering a unicast prefix.
BUG: KASAN: slab-out-of-bounds in sk_mc_loop+0x111/0x170 Read of size 8 at addr ffff88800f2b7f10 by task repro-raw/470 Call Trace: <IRQ> sk_mc_loop+0x111/0x170 ip_mc_output+0x355/0x930 ip_build_and_send_pkt+0xb87/0xc50 tcp_v4_send_synack+0x500/0x6f0 tcp_conn_request+0x2135/0x2d90 tcp_v4_conn_request+0xa5/0x210 tcp_rcv_state_process+0x136e/0x6920 tcp_v4_do_rcv+0x339/0xb10 tcp_v4_rcv+0x34ab/0x3ab0 ip_protocol_deliver_rcu+0x6e/0x3e0 ip_local_deliver_finish+0x34d/0x510 ip_local_deliver+0x1bc/0x310 ip_rcv+0x390/0x410 __netif_receive_skb_one_core+0x199/0x1e0 process_backlog+0x239/0x680 __napi_poll+0xb5/0x650 net_rx_action+0x980/0xd60 handle_softirqs+0x17f/0x590 do_softirq+0x3f/0x60 </IRQ> The buggy address belongs to the object at ffff88800f2b7d60 which belongs to the cache request_sock_TCP of size 312
The buggy address is located 120 bytes to the right of
allocated 312-byte region [ffff88800f2b7d60, ffff88800f2b7e98)
Use sk_const_to_full_sk(), which restores the behavior from before the two commits above: a request socket uses the setting of its listener, and a timewait socket gets the default (loop back), as the per-cpu control socket used before had.
--- net/core/sock.c | 1 + 1 file changed, 1 insertion(+)
net/core/sock.c +1 -0
@@ -768,6 +768,7 @@ bool sk_mc_loop(const struct sock *sk) {if (dev_recursion_level ())return false; + sk =sk_const_to_full_sk (sk);if (!sk)return true;/* IPV6_ADDRFORM can change sk->sk_family under us. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1666/2151 tcp: use the echoed source route in cookie_v4_check()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 54d574d4afd9de820c8a017665c8095f0f5fdbaa ]
When the ACK carries a source route option, cookie_v4_check() routes the new socket to opt->faddr, where opt points to the options of the received packet.
ip_options_compile() only fills faddr for options given by setsockopt() (when called without an skb), so on receive faddr is 0 and the lookup is done for daddr 0, which gives a local route.
Use the options echoed by tcp_v4_save_options() instead, as inet_csk_route_req() and inet_csk_route_child_sock() do with ireq->ireq_opt. Read them after security_inet_conn_request(), since CIPSO can replace ireq->ireq_opt there.
The route now goes to the first hop of the source route, so also refuse a strict source route through a gateway, as inet_csk_route_req() does.
Found by sashiko while reviewing the sk_mc_loop() fix.
--- net/ipv4/syncookies.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/ipv4/syncookies.c +10 -2
@@ -406,12 +406,12 @@ static struct request_sock *cookie_tcp_check(struct net *net, struct sock *sk,*/ struct sock *cookie_v4_check (struct sock *sk,struct sk_buff *skb) { -struct ip_options *opt = &TCP_SKB_CB (skb)->header.h4.opt;const struct tcphdr *th =tcp_hdr (skb);struct tcp_sock *tp =tcp_sk (sk);struct inet_request_sock *ireq;struct net *net =sock_net (sk);struct tcp_request_sock *treq; +struct ip_options_rcu *opt;struct request_sock *req;struct sock *ret = sk;struct flowi4 fl4;
@@ -451,6 +451,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)SKB_DR_SET (reason,SECURITY_HOOK ); goto out_free; } +/* Load ireq->ireq_opt after the LSM hook, which can replace it. */ + opt =rcu_dereference_protected (ireq->ireq_opt, true);tcp_ao_syncookie (sk, skb, req,AF_INET );
@@ -463,7 +465,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)flowi4_init_output (&fl4, ireq->ir_iif, ireq->ir_mark,ip_sock_rt_tos (sk),ip_sock_rt_scope (sk),IPPROTO_TCP ,inet_sk_flowi_flags (sk), - opt->srr ? opt->faddr : ireq->ir_rmt_addr, + (opt && opt->opt.srr) ? opt->opt.faddr : ireq->ir_rmt_addr, ireq->ir_loc_addr, th->source, th->dest,sk_uid (sk));security_req_classify_flow (req,flowi4_to_flowi_common (&fl4));
@@ -472,6 +474,12 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)SKB_DR_SET (reason,IP_OUTNOROUTES ); goto out_free; } +/* Same check as in inet_csk_route_req(). */ +if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway) { +ip_rt_put (rt); +SKB_DR_SET (reason,IP_OUTNOROUTES ); + goto out_free; + }/* Try to redo what tcp_v4_send_synack did. */ req->rsk_window_clamp = READ_ONCE(tp->window_clamp) ? :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1667/2151 selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 3c824dfd17e6e918e45a6a96bda0d020ddec8287 ]
setup_hierarchy() mounts a bpffs on /sys/fs/bpf with setup_bpffs(), and then sets up the cgroups with setup_cgroups(), which moves the test into a private mount namespace.
The bpffs thus lands in the mount namespace that test_progs shares with the tests running in parallel, on top of the bpffs already there, and hides what they pin. cleanup_bpffs() later runs in the private mount namespace and can't unmount it, so it stays there for good. bpftool_maps_access then fails to pin an iterator because /sys/fs/bpf/test_bpftool_map doesn't exist anymore, and bpftool_metadata can't find the program it pinned in /sys/fs/bpf/test_metadata.
Set up the cgroups first, so that the bpffs is mounted in the private mount namespace.
--- .../selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c +1 -1
@@ -151,7 +151,7 @@ static void cleanup_cgroups(void)/* Sets up cgroup hiearchary, returns 0 on success. */ static int setup_hierarchy (void ) { -return setup_bpffs () ||setup_cgroups (); +return setup_cgroups () ||setup_bpffs (); }static void destroy_hierarchy (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1668/2151 selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit e0645cfd0e1b2ae7b8ad989bef00a30016b16b5f ]
setup_bpffs() mounts a bpffs on /sys/fs/bpf and records in mounted_bpffs whether it did, so that cleanup_bpffs() unmounts only a bpffs that the test mounted itself.
cleanup_bpffs() checks the flag the other way around. As mounting on /sys/fs/bpf succeeds even when a bpffs is already there, the test never unmounts the bpffs it mounted, and every run leaves another one stacked on /sys/fs/bpf of the mount namespace that the test_progs worker keeps running later tests in.
Unmount the bpffs only when setup_bpffs() mounted it.
--- .../selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c +1 -1
@@ -110,7 +110,7 @@ static void cleanup_bpffs(void)ASSERT_OK (rmdir (BPFFS_ATTACH_COUNTERS ),"rmdir " BPFFS_ATTACH_COUNTERS );/* Unmount bpffs, if it wasn't already mounted when we started */ -if (mounted_bpffs) +if (!mounted_bpffs)return ;ASSERT_OK (umount (BPFFS_ROOT ),"unmount bpffs" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1669/2151 drm/appletbdrm: Add suspend and resume support
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasilij Markin <[email protected]>
[ Upstream commit 6f6a6b9ae0b481b97dac141ae86becdf7bd0b471 ]
The driver has no USB power management callbacks, so the USB core unbinds it before system suspend and binds it again on resume. The DRM device is unregistered and registered again on every suspend and resume cycle, userspace driving the Touch Bar through it (such as tiny-dfr) loses its device, and the Touch Bar stays dark after resume.
Implement suspend and resume with drm_mode_config_helper_suspend() and drm_mode_config_helper_resume(), so the device stays registered and the last committed state is restored on resume. If the device was reset while suspended, repeat the probe-time handshake first.
--- drivers/gpu/drm/tiny/appletbdrm.c | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/gpu/drm/tiny/appletbdrm.c +46 -0
@@ -30,6 +30,7 @@#include <drm/drm_gem_atomic_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_shmem_helper.h> +#include <drm/drm_modeset_helper.h> #include <drm/drm_plane.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h>
@@ -814,6 +815,48 @@ static void appletbdrm_shutdown(struct usb_interface *intf)drm_atomic_helper_shutdown (&adev->drm); } +static int appletbdrm_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct appletbdrm_device *adev =usb_get_intfdata (intf); + +return drm_mode_config_helper_suspend (&adev->drm); +} + +static int appletbdrm_resume (struct usb_interface *intf) +{ +struct appletbdrm_device *adev =usb_get_intfdata (intf); + +return drm_mode_config_helper_resume (&adev->drm); +} + +static int appletbdrm_reset_resume (struct usb_interface *intf) +{ +struct appletbdrm_device *adev =usb_get_intfdata (intf); +struct drm_device *drm = &adev->drm; +int ret, resume_ret; + +/* +* A reset puts the device back into its initial state, where it +* expects the same handshake as during probe. Resume the DRM side +* even if the handshake fails, so that the state saved on suspend +* is released. +*/ + ret =appletbdrm_get_information (adev); +if (ret) { +drm_err (drm,"Failed to get display information\n" ); + goto resume; + } + + ret =appletbdrm_signal_readiness (adev); +if (ret) +drm_err (drm,"Failed to signal readiness\n" ); + +resume: + resume_ret =drm_mode_config_helper_resume (drm); + +return ret ? ret : resume_ret; +} +static const struct usb_device_id appletbdrm_usb_id_table[] = { {USB_DEVICE_INTERFACE_CLASS (0x05ac ,0x8302 ,USB_CLASS_AUDIO_VIDEO ) }, {}
@@ -825,6 +868,9 @@ static struct usb_driver appletbdrm_usb_driver = { .probe = appletbdrm_probe, .disconnect = appletbdrm_disconnect, .shutdown = appletbdrm_shutdown, + .suspend = appletbdrm_suspend, + .resume = appletbdrm_resume, + .reset_resume = appletbdrm_reset_resume, .id_table = appletbdrm_usb_id_table, };module_usb_driver (appletbdrm_usb_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1670/2151 ALSA: vmaster: Protect follower lookup and setup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit db2db2dec96e24d067cc5692ac5eec35830ee8d9 ]
A control selected by snd_ctl_add_followers() must remain alive until _snd_ctl_add_follower() has copied it and installed its wrapper. The lookup returns a raw pointer without retaining the control, and neither the short-lived list lookup lock nor the fast lookup protects later use.
If a kernel client adds followers to a live virtual master while another client removes or replaces a published follower, the following order is possible, with the card and master kept alive:
Follower setup Control removal
snd_ctl_add_followers()
snd_ctl_find_id_mixer()
return follower
snd_ctl_remove()
down_write(controls_rwsem)
__snd_ctl_remove()
unlink follower
snd_ctl_free_one(follower)
up_write(controls_rwsem)
_snd_ctl_add_follower()
read follower->countRemoval completes after lookup returns and before setup reads the control. Since setup holds neither controls_rwsem nor a reference, the count read and subsequent control copies can access freed memory.
Hold controls_rwsem for writing across the lookup and follower setup. This prevents removal or replacement from freeing the selected control until wrapper installation is complete. Write ownership also excludes control callbacks while setup changes the callback and private fields.
KASAN report as below:
BUG: KASAN: slab-use-after-free in _snd_ctl_add_follower+0x452/0x520
Read of size 4 at addr ffff888107957d50 by task loadmodule/491
CPU: 3 UID: 0 PID: 491 Comm: loadmodule Tainted: G O 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy)
Tainted: [O]=OOT_MODULE
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? _snd_ctl_add_follower+0x452/0x520
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? _snd_ctl_add_follower+0x452/0x520
kasan_report+0xe0/0x110
? _snd_ctl_add_follower+0x452/0x520
_snd_ctl_add_follower+0x452/0x520
snd_ctl_add_followers+0x153/0x2b0
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_snd_ctl_add_followers+0x10/0x10
? __might_fault+0x135/0x190
? srso_alias_return_thunk+0x5/0xfbef5
? __might_fault+0x14e/0x190
? __pfx_fixture_write+0x10/0x10 [pmbd_vmaster_fixture]
fixture_write+0x174/0x1f0 [pmbd_vmaster_fixture]
? __pfx_fixture_write+0x10/0x10 [pmbd_vmaster_fixture]
? __pfx___might_resched+0x10/0x10
proc_reg_write+0x1fb/0x2d0
vfs_write+0x25a/0x1010
? __pfx_proc_reg_write+0x10/0x10
? kmem_cache_free+0x242/0x580
? __pfx_vfs_write+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? putname+0x93/0xe0
? srso_alias_return_thunk+0x5/0xfbef5
? do_sys_openat2+0x12a/0x1b0
? __pfx_do_sys_openat2+0x10/0x10
ksys_write+0x111/0x200
? __pfx_ksys_write+0x10/0x10
? irqentry_exit+0xbe/0x820
? srso_alias_return_thunk+0x5/0xfbef5
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f0b835a9687
Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffc82ea0360 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f0b83517780 RCX: 00007f0b835a9687
RDX: 0000000000000005 RSI: 0000564f8a21d074 RDI: 0000000000000003
RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
R13: 00007ffc82ea04f0 R14: 00007f0b83755000 R15: 0000564f8a21ed78
</TASK>
Allocated by task 485:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_noprof+0x2d7/0x770
snd_ctl_new+0x51/0x190
snd_ctl_new1+0x13c/0x650
0xffffffffc04011b5
do_one_initcall+0xf3/0x4e0
do_init_module+0x281/0x8e0
load_module+0x658c/0x7cc0
init_module_from_file+0x15b/0x180
idempotent_init_module+0x22d/0x770
__x64_sys_finit_module+0xd2/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 492:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
__snd_ctl_remove+0x2ac/0x3d0
snd_ctl_remove+0x46/0x70
fixture_write+0x1ae/0x1f0 [pmbd_vmaster_fixture]
proc_reg_write+0x1fb/0x2d0
vfs_write+0x25a/0x1010
ksys_write+0x111/0x200
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888107957d00
which belongs to the cache kmalloc-192 of size 192
The buggy address is located 80 bytes inside of
freed 192-byte region [ffff888107957d00, ffff888107957dc0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x107957
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000423c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888107957c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888107957c80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff888107957d00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888107957d80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888107957e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================--- sound/core/vmaster.c | 3 +++ 1 file changed, 3 insertions(+)
sound/core/vmaster.c +3 -0
@@ -288,6 +288,8 @@ EXPORT_SYMBOL(_snd_ctl_add_follower);* * Adds the multiple follower kcontrols with the given names. * Returns 0 for success or a negative error code. +* +* Note that this function takes card->controls_rwsem lock internally. */ int snd_ctl_add_followers (struct snd_card *card,struct snd_kcontrol *master,const char *const *list)
@@ -295,6 +297,7 @@ int snd_ctl_add_followers(struct snd_card *card, struct snd_kcontrol *master,struct snd_kcontrol *follower;int err; +guard (rwsem_write)(&card->controls_rwsem);for (; *list; list++) { follower =snd_ctl_find_id_mixer (card, *list);if (follower) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1671/2151 selftests/bpf: Record only the test ICMP echo in tc8 of tc_netkit_scrub
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 17f6fc3ad257b0ad7a11f276a5c0f57e0bdf3f4a ]
tc_netkit_scrub attaches tc8 to the primary netkit device, sends an ICMP echo with a mark and a priority through it, and checks the mark and the priority that tc8 saw against what the scrub mode lets through.
tc8 records the mark and priority of every packet it sees, and the device also carries what the system sends on its own once the device is up, like IPv6 neighbor discovery or the mDNS of avahi-daemon. When such a packet goes out after the echo, it overwrites what tc8 recorded, and the test finds a mark and a priority of 0. Record only IPv4 ICMP packets in tc8.
tc_netkit_scrub run 100 times on a bpf-next kernel with KASAN enabled, x86_64 VM with 32 vCPUs and avahi-daemon running, before and after this patch:
before after
outcome 2 of 100 failed (mark and priority 0) 0 of 100 failed
--- tools/testing/selftests/bpf/progs/test_tc_link.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/testing/selftests/bpf/progs/test_tc_link.c +10 -0
@@ -4,6 +4,8 @@#include <linux/bpf.h> #include <linux/if_ether.h> +#include <linux/in.h> +#include <linux/ip.h> #include <linux/stddef.h> #include <linux/if_packet.h> #include <bpf/bpf_endian.h>
@@ -119,11 +121,19 @@ SEC("tc/egress")int tc8 (struct __sk_buff *skb) {struct net_device *dev =BPF_CORE_READ ((struct sk_buff *)skb, dev); +struct iphdr iph = {}; +if (skb->protocol !=__bpf_constant_htons (ETH_P_IP )) + goto out; +if (bpf_skb_load_bytes (skb,sizeof (struct ethhdr ), &iph,sizeof (iph))) + goto out; +if (iph.protocol !=IPPROTO_ICMP ) + goto out; seen_tc8 = true; mark = skb->mark; prio = skb->priority; headroom =BPF_CORE_READ (dev, needed_headroom); tailroom =BPF_CORE_READ (dev, needed_tailroom); +out:return TCX_PASS ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1672/2151 HID: magicmouse: fix null pointer dereference in magicmouse_event()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nehuen Lian Bova <[email protected]>
[ Upstream commit 5b66b65cfd6f697b1addb6159cbece53d20db2fc ]
Add a guard clause to check if 'msc' and 'msc->input' is NULL before attempting to access its fields, preventing a general protection fault.
--- drivers/hid/hid-magicmouse.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/hid/hid-magicmouse.c +4 -0
@@ -553,6 +553,10 @@ static int magicmouse_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) {struct magicmouse_sc *msc =hid_get_drvdata (hdev); + +if (!msc || !msc->input) +return 0 ; +if ((msc->input->id.product ==USB_DEVICE_ID_APPLE_MAGICMOUSE2 || msc->input->id.product ==USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ) && field->report->id ==MOUSE2_REPORT_ID ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1673/2151 HID: logitech-hidpp: cancel reset_hi_res_work on probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitriy Geels <[email protected]>
[ Upstream commit 0be03caba6c002385e74d60be934b961aa5e88dc ]
The probe error path cancels hidpp->work before freeing the HID++ device data, but does not cancel reset_hi_res_work.
reset_hi_res_work can be scheduled while probing the device. If probe subsequently fails, the work can run after the driver data has been freed.
Cancel reset_hi_res_work in the probe error path to prevent a potential use-after-free.
--- drivers/hid/hid-logitech-hidpp.c | 1 + 1 file changed, 1 insertion(+)
drivers/hid/hid-logitech-hidpp.c +1 -0
@@ -4527,6 +4527,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_start_fail:sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group);cancel_work_sync (&hidpp->work); +cancel_work_sync (&hidpp->reset_hi_res_work);mutex_destroy (&hidpp->send_mutex);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1674/2151 HID: wacom: fix wacom_intuos_irq NULL pen_input deref
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matheus Alves de Almeida <[email protected]>
[ Upstream commit 2f985de0afbe9366af9d322ea20589712c1dc8fe ]
Currently, wacom_intuos_irq() passes the parent of wacom_wac's pen_input to the dev_dbg() in the unknown report path. However, pen_input can be NULL on interfaces without a pen, causing a NULL pointer dereference.
Get the HID device from the enclosing struct wacom and use hid_dbg() instead.
--- drivers/hid/wacom_wac.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/wacom_wac.c +7 -7
@@ -1027,10 +1027,10 @@ static int wacom_intuos_general(struct wacom_wac *wacom)return 2 ; } -static int wacom_intuos_irq (struct wacom_wac *wacom) +static int wacom_intuos_irq (struct wacom_wac *wacom_wac) { -unsigned char *data = wacom->data; -struct input_dev *input = wacom->pen_input; +unsigned char *data = wacom_wac->data; + struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);int result; if (data[0] != WACOM_REPORT_PENABLED &&
@@ -1041,23 +1041,23 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) data[0] != WACOM_REPORT_CINTIQ && data[0] != WACOM_REPORT_CINTIQPAD && data[0] != WACOM_REPORT_INTUOS5PAD) { -dev_dbg (input->dev.parent, +hid_dbg (wacom->hdev,"%s: received unknown report #%d\n" , __func__, data[0 ]);return 0 ; }/* process pad events */ - result =wacom_intuos_pad (wacom); + result =wacom_intuos_pad (wacom_wac);if (result)return result;/* process in/out prox events */ - result =wacom_intuos_inout (wacom); + result =wacom_intuos_inout (wacom_wac);if (result)return result -1 ;/* process general packets */ - result =wacom_intuos_general (wacom); + result =wacom_intuos_general (wacom_wac);if (result)return result -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1675/2151 fuse: validate folio state before pipe_buf_try_steal() in fuse_try_move_folio()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit 15c20483d91589f868fe7a72aec4b97dc68b931b ]
In fuse_try_move_folio(), check that the pipe buffer's folio is not hugetlb, swap-backed, or already mapped/anon before attempting pipe_buf_try_steal() and inserting it into the FUSE inode's page cache, preventing VM_BUG_ON_FOLIO() and page cache state corruption.
--- fs/fuse/dev.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
fs/fuse/dev.c +13 -13
@@ -1024,32 +1024,32 @@ static int fuse_try_move_folio(struct fuse_copy_state *cs, struct folio **foliopif (cs->len !=folio_size (oldfolio)) goto out_fallback; -if (!pipe_buf_try_steal (cs->pipe, buf)) - goto out_fallback; - newfolio =page_folio (buf->page); -folio_clear_uptodate (newfolio); -folio_clear_mappedtodisk (newfolio); -if (folio_test_large (newfolio)) - goto out_fallback_unlock; - -if (fuse_check_folio (newfolio) !=0 ) - goto out_fallback_unlock; + goto out_fallback;/* * This is a new and locked page, it shouldn't be mapped or * have any special flags on it */ if (WARN_ON (folio_mapped (oldfolio))) - goto out_fallback_unlock; + goto out_fallback;if (WARN_ON (folio_has_private (oldfolio))) - goto out_fallback_unlock; + goto out_fallback;if (WARN_ON (folio_test_dirty (oldfolio) ||folio_test_writeback (oldfolio))) - goto out_fallback_unlock; + goto out_fallback;if (WARN_ON (folio_test_mlocked (oldfolio))) + goto out_fallback; + +if (!pipe_buf_try_steal (cs->pipe, buf)) + goto out_fallback; + +folio_clear_uptodate (newfolio); +folio_clear_mappedtodisk (newfolio); + +if (fuse_check_folio (newfolio) !=0 ) goto out_fallback_unlock; err =lock_request (cs->req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1676/2151 drm/appletbdrm: Fix incorrect error message on encoder attach failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adam Azuddin <[email protected]>
[ Upstream commit fa6d4c16f7a0da6dce3eb36a3139bfe01d071f18 ]
drm_connector_attach_encoder() replaced an earlier call to drm_simple_display_pipe_init() during review, but the error message logged on failure was not updated to match and still refers to the old call.
--- drivers/gpu/drm/tiny/appletbdrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/appletbdrm.c +1 -1
@@ -718,7 +718,7 @@ static int appletbdrm_setup_mode_config(struct appletbdrm_device *adev) ret =drm_connector_attach_encoder (connector, encoder);if (ret) { -drm_err (drm,"Failed to initialize simple display pipe\n" ); +drm_err (drm,"Failed to attach connector to encoder\n" );return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1677/2151 selftests/bpf: Expect at least one kprobe miss in missed/perf_kprobe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 34d527e513c9a3f3a00f1ddf03fe06f493da14d0 ]
missed_kprobe attaches test1 to bpf_fentry_test1 and test2 to bpf_kfunc_common_test, which test1 calls. test_missed_perf_kprobe() expects the kprobe of test2 to miss exactly one run, the one test1 triggers, since kprobes don't nest.
The test is not serial, and the kprobe on bpf_fentry_test1 is global. Any other test that does bpf_prog_test_run() on a fentry/fexit program calls bpf_fentry_test1() and thereby fires test1, which calls bpf_kfunc_common_test() from kprobe context. The kprobe of test2 then counts an extra miss, and the test reads 2 instead of 1.
Expect at least one miss, as missed_kprobe_recursion does since commit 08a7078feacf ("selftests/bpf: Improve missed_kprobe_recursion test robustness").
--- tools/testing/selftests/bpf/prog_tests/missed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/missed.c +1 -1
@@ -36,7 +36,7 @@ static void test_missed_perf_kprobe(void)ASSERT_EQ (info.type,BPF_LINK_TYPE_PERF_EVENT ,"info.type" );ASSERT_EQ (info.perf_event.type,BPF_PERF_EVENT_KPROBE ,"info.perf_event.type" ); -ASSERT_EQ (info.perf_event.kprobe.missed,1 ,"info.perf_event.kprobe.missed" ); +ASSERT_GE (info.perf_event.kprobe.missed,1 ,"info.perf_event.kprobe.missed" ); cleanup:missed_kprobe__destroy (skel);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1678/2151 bpftool: Fix inverted tracefs validation when scanning /proc/mounts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 21c755efaab1f40c2588ae5acbfa319a6d7d3638 ]
The /proc/mounts fallback in get_tracefs_pipe() accepts only non-tracefs mount points, so a tracefs mounted outside the default locations is
ignored: bpftool prog tracelog then mounts a second tracefs, or exits silently with --nomount. Negate the condition.
--- tools/bpf/bpftool/tracelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/tracelog.c +1 -1
@@ -86,7 +86,7 @@ static bool get_tracefs_pipe(char *mnt)fclose (fp);/* The string from fscanf() might be truncated, check mnt is valid */ -if (found &&validate_tracefs_mnt (mnt,TRACEFS_MAGIC )) +if (found && !validate_tracefs_mnt (mnt,TRACEFS_MAGIC )) goto exit_found;if (block_mount)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1679/2151 selftests/bpf: Fix spelling mistakes in descr literal strings
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
[ Upstream commit 760c953525bab88f053e61f1c1a6b2a5f76911c0 ]
There are spelling mistakes in the descr literal strings. Fix them.
--- tools/testing/selftests/bpf/prog_tests/sockopt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/sockopt.c +2 -2
@@ -933,7 +933,7 @@ static struct sockopt_test {/* ==================== prog_type ==================== */ { - .descr = "can attach only BPF_CGROUP_SETSOCKOP", + .descr = "can attach only BPF_CGROUP_SETSOCKOPT", .insns = {/* return 1 */ BPF_MOV64_IMM(BPF_REG_0, 1),
@@ -947,7 +947,7 @@ static struct sockopt_test { }, { - .descr = "can attach only BPF_CGROUP_GETSOCKOP", + .descr = "can attach only BPF_CGROUP_GETSOCKOPT", .insns = {/* return 1 */ BPF_MOV64_IMM(BPF_REG_0, 1),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1680/2151 ALSA: hda/realtek: ALC269 fixup for Lenovo Yoga Pro 7 15ASH111 audio
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jackie Dong <[email protected]>
[ Upstream commit 83dca2530fb3ba63f47bad339d890bc30aa06ab5 ]
Volume control for the speakers on the Lenovo Yoga Pro 7 15ASH11 laptop doesn't work.
The DAC routing is the same as on the ThinkPad X1 Gen7 function, so reuse the alc285_fixup_thinkpad_x1_gen7 to get it working.
Stable-dep-of: 2fc28b1186d6 ("ALSA: hda/realtek: Fix hiss/crackle on Lenovo Xiaoxin 14 GT (17aa:3912)")
--- sound/hda/codecs/realtek/alc269.c | 1 + 1 file changed, 1 insertion(+)
sound/hda/codecs/realtek/alc269.c +1 -0
@@ -7663,6 +7663,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x17aa ,0x38df ,"Y990 YG DUAL" ,ALC287_FIXUP_TAS2781_I2C ),SND_PCI_QUIRK (0x17aa ,0x38f9 ,"Thinkbook 16P Gen5" ,ALC287_FIXUP_MG_RTKC_CSAMP_CS35L41_I2C_THINKPAD ),SND_PCI_QUIRK (0x17aa ,0x38fa ,"Thinkbook 16P Gen5" ,ALC287_FIXUP_MG_RTKC_CSAMP_CS35L41_I2C_THINKPAD ), +SND_PCI_QUIRK (0x17aa ,0x38fc ,"Lenovo Yoga Pro 7 15ASH11" ,ALC245_FIXUP_BASS_HP_DAC ),SND_PCI_QUIRK (0x17aa ,0x38fd ,"ThinkBook plus Gen5 Hybrid" ,ALC287_FIXUP_TAS2781_I2C ),SND_PCI_QUIRK (0x17aa ,0x3902 ,"Lenovo E50-80" ,ALC269_FIXUP_DMIC_THINKPAD_ACPI ), SND_PCI_QUIRK(0x17aa, 0x390d, "Lenovo Yoga Pro 7 14ASP10", ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1681/2151 ALSA: hda/realtek:ALC269 fixup for Yoga Pro 7 15ASH11 mic mute LED
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jackie Dong <[email protected]>
[ Upstream commit 17065203e1bc7e7f2786998d532cd93a06265156 ]
Lenovo Yoga Pro 7 15ASH11 with AMD RYZEN AI MAX+ 388 (Strix Halo, ACP 7.0) uses Realtek ALC287 series codec. The ALC269_FIXUP_LENOVO_XPAD_ACPI in alc269_fixup_vendor_tbl[] can load lenovo_wmi_hotkey_utilities module by default in this laptop, but the driver doesn't control mic mute LED.
If users run below command and the mic mute LED can work normally.
$sudo echo 'Capture Switch' >/sys/class/sound/ctl-led/mic/card1/attach
After added the SND_PCI_QUIRK quirk special for Lenovo Yoga Pro 7 15ASH11, the mic mute LED works well.
Stable-dep-of: 2fc28b1186d6 ("ALSA: hda/realtek: Fix hiss/crackle on Lenovo Xiaoxin 14 GT (17aa:3912)")
--- sound/hda/codecs/realtek/alc269.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +9 -1
@@ -3941,6 +3941,7 @@ enum {ALC287_FIXUP_YOGA7_14ITL_SPEAKERS ,ALC298_FIXUP_LENOVO_C940_DUET7 ,ALC287_FIXUP_LENOVO_YOGA_BOOK_9I , +ALC287_FIXUP_LENOVO_YOGA_PRO7 ,ALC287_FIXUP_13S_GEN2_SPEAKERS ,ALC256_FIXUP_SET_COEF_DEFAULTS , ALC256_FIXUP_SYSTEM76_MIC_NO_PRESENCE,
@@ -6068,6 +6069,13 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC285_FIXUP_THINKPAD_HEADSET_JACK, }, + [ALC287_FIXUP_LENOVO_YOGA_PRO7] = { + .type = HDA_FIXUP_FUNC, +/* Reuse the DAC routing selected for ThinkPad X1 Gen7 */ + .v.func = alc285_fixup_thinkpad_x1_gen7, + .chained = true, + .chain_id = ALC269_FIXUP_LENOVO_XPAD_ACPI, + }, [ALC623_FIXUP_LENOVO_THINKSTATION_P340] = { .type = HDA_FIXUP_FUNC, .v.func = alc_fixup_no_shutup,
@@ -7663,7 +7671,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x17aa ,0x38df ,"Y990 YG DUAL" ,ALC287_FIXUP_TAS2781_I2C ),SND_PCI_QUIRK (0x17aa ,0x38f9 ,"Thinkbook 16P Gen5" ,ALC287_FIXUP_MG_RTKC_CSAMP_CS35L41_I2C_THINKPAD ),SND_PCI_QUIRK (0x17aa ,0x38fa ,"Thinkbook 16P Gen5" ,ALC287_FIXUP_MG_RTKC_CSAMP_CS35L41_I2C_THINKPAD ), -SND_PCI_QUIRK (0x17aa ,0x38fc ,"Lenovo Yoga Pro 7 15ASH11" ,ALC245_FIXUP_BASS_HP_DAC ), +SND_PCI_QUIRK (0x17aa ,0x38fc ,"Lenovo Yoga Pro 7 15ASH11" ,ALC287_FIXUP_LENOVO_YOGA_PRO7 ),SND_PCI_QUIRK (0x17aa ,0x38fd ,"ThinkBook plus Gen5 Hybrid" ,ALC287_FIXUP_TAS2781_I2C ),SND_PCI_QUIRK (0x17aa ,0x3902 ,"Lenovo E50-80" ,ALC269_FIXUP_DMIC_THINKPAD_ACPI ), SND_PCI_QUIRK(0x17aa, 0x390d, "Lenovo Yoga Pro 7 14ASP10", ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1682/2151 ALSA: hda/realtek: ALC269 fixup for Yoga/Legion Mic noise
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jackie Dong <[email protected]>
[ Upstream commit 6cd3d2c82651a9e77aa5b1b9c12aa918c0d6c0a9 ]
Lenovo Yoga Pro 7 15ASH11 and Legion 7 15ASH11 use the same audio subsystem implementation and support only analog microphone.
Limit Amp-In Vals to 0x00 and 0x01 for the internal microphone to reduce recording noise. Values 0x02 and 0x03 introduce significant noise on them.
Stable-dep-of: 2fc28b1186d6 ("ALSA: hda/realtek: Fix hiss/crackle on Lenovo Xiaoxin 14 GT (17aa:3912)")
--- sound/hda/codecs/realtek/alc269.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
sound/hda/codecs/realtek/alc269.c +11 -2
@@ -3451,6 +3451,16 @@ static void alc287_fixup_yoga9_14iap7_bass_spk_pin(struct hda_codec *codec, } } +static void alc_fixup_yoga_pro7_audio (struct hda_codec *codec, +const struct hda_fixup *fix,int action) +{ +/* Reuse the DAC routing selected for ThinkPad X1 Gen7 */ +alc285_fixup_thinkpad_x1_gen7 (codec, fix, action); + +/* Limit the internal mic boost to 0 or 1 to avoid noise */ +alc269_fixup_limit_int_mic_boost (codec, fix, action); +} +static void alc295_fixup_dell_inspiron_top_speakers (struct hda_codec *codec,const struct hda_fixup *fix,int action) {
@@ -6071,8 +6081,7 @@ static const struct hda_fixup alc269_fixups[] = { }, [ALC287_FIXUP_LENOVO_YOGA_PRO7] = { .type = HDA_FIXUP_FUNC, -/* Reuse the DAC routing selected for ThinkPad X1 Gen7 */ - .v.func = alc285_fixup_thinkpad_x1_gen7, + .v.func = alc_fixup_yoga_pro7_audio, .chained = true, .chain_id = ALC269_FIXUP_LENOVO_XPAD_ACPI, },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1683/2151 ALSA: hda/realtek: Fix hiss/crackle on Lenovo Xiaoxin 14 GT (17aa:3912)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viktor Menshin <[email protected]>
[ Upstream commit 2fc28b1186d6fce8b046e6118072cf3ca32f2960 ]
Commit 3a3e810e9108 ("ALSA: hda/realtek: Add quirk for Lenovo Xiaoxin 14 GT") added a quirk mapping SSID 17aa:3912 to ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN, chosen by analogy with neighboring SSIDs (0x390d, 0x3911, 0x391a) without being verified on hardware, as noted in that commit's own message.
I have since tested it on the actual hardware (Lenovo Xiaoxin Pro 14 ASP10, same 17aa:3912 SSID) and confirmed it does not fix the reported issue. ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN only repoints pin 0x17 and the preferred DAC pairs for the bass speaker; it does not touch the codec's vendor processing coefficients. The actual symptom - constant electrical hiss/crackle on both the headphone jack and the internal speakers, independent of volume - is unrelated to pin/DAC routing and is also present on stock Windows before the Realtek driver is installed, which points at those coefficients being left at their power-on default.
To find the correct values, I passed the physical HD Audio controller through to a Windows 10 VM (VFIO, with QEMU patched to log CORB verb traffic) and captured the coefficient writes the vendor Realtek driver performs at init. Replaying a single one of them on Linux via hda-verb reproducibly eliminates the headphone jack noise:
hda-verb /dev/snd/hwC#D0 0x20 SET_COEF_INDEX 0x36
hda-verb /dev/snd/hwC#D0 0x20 SET_PROC_COEF 0x77d7This has held up across reboots and kernel updates for several weeks (applied via a small systemd oneshot unit while testing).
Add a dedicated fixup that performs this coefficient write and chains it with the existing ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN (which may still be relevant for the bass speaker pin wiring on this board), and point the 17aa:3912 quirk entry at it instead.
Honesty note: this fixes the headphone jack. The internal speakers still have noise under certain conditions (notably worse on AC power) that I have not been able to isolate via coefficient-table replay; that part remains open. Sending what is verified to work rather than holding this back.
--- sound/hda/codecs/realtek/alc269.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +30 -1
@@ -3451,6 +3451,28 @@ static void alc287_fixup_yoga9_14iap7_bass_spk_pin(struct hda_codec *codec, } } +/* +* The Lenovo Xiaoxin 14 GT (SSID 17aa:3912) uses the same bass-speaker +* pin wiring as its 0x390d/0x3911/0x391a siblings, but on this board the +* codec's vendor processing coefficients (node 0x20) are left at their +* power-on default instead of being programmed the way the vendor +* (Windows) driver programs them. That leaves audible hiss/crackle on +* both the headphone jack and the internal speakers, independent of +* volume, regardless of which pin/DAC routing is used. +* +* This single coefficient write was captured from the vendor driver's +* own init sequence (via a VFIO pass-through of the physical codec to a +* Windows VM) and confirmed to eliminate the headphone jack noise. +*/ +static void alc287_fixup_lenovo_xiaoxin_14gt_hp_noise (struct hda_codec *codec, +const struct hda_fixup *fix,int action) +{ +if (action !=HDA_FIXUP_ACT_INIT ) +return ; + +alc_write_coef_idx (codec,0x36 ,0x77d7 ); +} +static void alc_fixup_yoga_pro7_audio (struct hda_codec *codec,const struct hda_fixup *fix,int action) {
@@ -3976,6 +3998,7 @@ enum {ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ,ALC287_FIXUP_YOGA9_14IMH9_BASS_SPK_PIN , +ALC287_FIXUP_LENOVO_XIAOXIN_14GT_HP_NOISE ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS ,ALC236_FIXUP_DELL_DUAL_CODECS , ALC287_FIXUP_CS35L41_I2C_2_THINKPAD_ACPI,
@@ -6387,6 +6410,12 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC287_FIXUP_CS35L41_I2C_2, }, + [ALC287_FIXUP_LENOVO_XIAOXIN_14GT_HP_NOISE] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc287_fixup_lenovo_xiaoxin_14gt_hp_noise, + .chained = true, + .chain_id = ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN, + }, [ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS] = { .type = HDA_FIXUP_FUNC, .v.func = alc295_fixup_dell_inspiron_top_speakers,
@@ -7685,7 +7714,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x17aa ,0x3902 ,"Lenovo E50-80" ,ALC269_FIXUP_DMIC_THINKPAD_ACPI ),SND_PCI_QUIRK (0x17aa ,0x390d ,"Lenovo Yoga Pro 7 14ASP10" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ),SND_PCI_QUIRK (0x17aa ,0x3911 ,"Lenovo Yoga Pro 7 14IAH10" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ), -SND_PCI_QUIRK (0x17aa ,0x3912 ,"Lenovo Xiaoxin 14 GT" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ), +SND_PCI_QUIRK (0x17aa ,0x3912 ,"Lenovo Xiaoxin 14 GT" ,ALC287_FIXUP_LENOVO_XIAOXIN_14GT_HP_NOISE ),SND_PCI_QUIRK (0x17aa ,0x3913 ,"Lenovo 145" ,ALC236_FIXUP_LENOVO_INV_DMIC ),SND_PCI_QUIRK (0x17aa ,0x391f ,"Yoga S990-16 pro Quad YC Quad" ,ALC287_FIXUP_TXNW2781_I2C ), SND_PCI_QUIRK(0x17aa, 0x3920, "Yoga S990-16 pro Quad VECO Quad", ALC287_FIXUP_TXNW2781_I2C),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1684/2151 blk-iocost: charge zone appends as writes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit febdbf5682fa7e8f325b07a2c115e7632c4252bd ]
Zone append is a primary write operation for zoned devices; zoned xfs and btrfs use it for data writes. It is priced at zero, so the zone append portion of zoned workloads runs outside the controller: a 1%-weight cgroup issued 16000 appends at zero cost on a zoned null_blk.
Treat REQ_OP_ZONE_APPEND the same as REQ_OP_WRITE so it goes through the existing seq/rand classification and charging.
--- block/blk-iocost.c | 1 + 1 file changed, 1 insertion(+)
block/blk-iocost.c +1 -0
@@ -2548,6 +2548,7 @@ static void calc_vtime_cost_builtin(struct bio *bio, struct ioc_gq *iocg, coef_randio = ioc->params.lcoefs[LCOEF_RRANDIO ]; coef_page = ioc->params.lcoefs[LCOEF_RPAGE ];break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : coef_seqio = ioc->params.lcoefs[LCOEF_WSEQIO ]; coef_randio = ioc->params.lcoefs[LCOEF_WRANDIO ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1685/2151 blk-iocost: account zone append completions in latency stats
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit c38975c427cc3d3f6eb66a36143893be5cdf4ebd ]
ioc_rqos_done() only accounts READ and WRITE completions, so zone append completions are excluded from the latency window: the vrate feedback loop cannot see ZA-induced latency, leaving it unable to respond to device saturation caused by zone appends. Similarly, calc_size_vtime_cost_builtin() does not classify zone append as a write operation.
Charging (the cost model) and feedback (the latency window) are separate mechanisms, so this is not covered by the previous patch that prices zone appends.
Treat zone append as WRITE for both latency accounting and cost classification.
--- block/blk-iocost.c | 2 ++ 1 file changed, 2 insertions(+)
block/blk-iocost.c +2 -0
@@ -2592,6 +2592,7 @@ static void calc_size_vtime_cost_builtin(struct request *rq, struct ioc *ioc,case REQ_OP_READ : *costp = pages * ioc->params.lcoefs[LCOEF_RPAGE ];break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : *costp = pages * ioc->params.lcoefs[LCOEF_WPAGE ];break ;
@@ -2827,6 +2828,7 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) pidx =QOS_RLAT ; rw =READ ;break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : pidx =QOS_WLAT ; rw =WRITE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1686/2151 blk-mq: share one tags_srcu instance across all tag sets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit e1c51edd6a575ba3b6fc5acb57ed2fec6951a910 ]
Freed request pages and flush queues are handed to call_srcu() so that concurrent tag iterators never see them disappear. Each tag set embeds its own srcu_struct for this, which blk_mq_free_tag_set() has to drain with srcu_barrier() before cleanup_srcu_struct(). The barrier waits for a full SRCU grace period even when the callbacks are long done, adding 1-3 ms to every tag set teardown. Drivers that free tag sets under a lock make it worse: ublk does it under the global ublk_ctl_mutex, so deleting devices from many threads serializes on that grace period.
The callbacks free memory that only blk-mq owns. They touch neither the tag set nor driver code, so they don't need a per-set domain. Replace the per-set srcu_struct with a single global one. Freeing a tag set no longer waits for a grace period, and each tag set no longer allocates per-CPU SRCU state. The read side is unchanged. The only cost is that a long-running iterator can now delay these frees for other tag sets too, which only postpones freeing memory.
On 7.3-rc5 in a 16-vCPU VM, with 1 queue and depth 16 per ublk device, median of 3 runs (5 for the 16-thread null_blk case):
before after ublk DEL_DEV p50, serial 3.45 ms 0.17 ms ublk delete 1000 devices, serial 19.5 s 14.9 s ublk delete 4000 devices, 16 thr 19.0 s 2.9 s null_blk destroy 500 devs, serial 9.97 s 9.25 s null_blk destroy 256 devs, 16 thr 5.15 s 4.30 s
--- block/blk-mq-tag.c | 17 ++++++++++++----- block/blk-mq.c | 15 ++++----------- block/blk-mq.h | 2 ++ include/linux/blk-mq.h | 3 --- 4 files changed, 18 insertions(+), 19 deletions(-)
block/blk-mq-tag.c +12 -5
@@ -17,6 +17,13 @@#include "blk-mq.h" #include "blk-mq-sched.h" +/* +* Protects tag iteration against the deferred freeing of tags->page_list and +* flush queues. The callbacks touch neither the tag set nor driver code, so +* one global instance is enough and freeing a tag set needn't wait for them. +*/ +DEFINE_SRCU (blk_mq_tags_srcu); +/* * Recalculate wakeup batch when tag is shared by hctx. */
@@ -437,7 +444,7 @@ void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,unsigned int flags = tagset->flags;int i, nr_tags, srcu_idx; - srcu_idx =srcu_read_lock (&tagset->tags_srcu); + srcu_idx =srcu_read_lock (&blk_mq_tags_srcu); nr_tags =blk_mq_is_shared_tags (flags) ?1 : tagset->nr_hw_queues;
@@ -446,7 +453,7 @@ void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,__blk_mq_all_tag_iter (tagset->tags[i], fn, priv,BT_TAG_ITER_STARTED ); } -srcu_read_unlock (&tagset->tags_srcu, srcu_idx); +srcu_read_unlock (&blk_mq_tags_srcu, srcu_idx); }EXPORT_SYMBOL (blk_mq_tagset_busy_iter);
@@ -506,7 +513,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_tag_iter_fn *fn,if (!percpu_ref_tryget (&q->q_usage_counter))return ; - srcu_idx =srcu_read_lock (&q->tag_set->tags_srcu); + srcu_idx =srcu_read_lock (&blk_mq_tags_srcu);if (blk_mq_is_shared_tags (q->tag_set->flags)) {struct blk_mq_tags *tags = q->tag_set->shared_tags;struct sbitmap_queue *bresv = &tags->breserved_tags;
@@ -536,7 +543,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_tag_iter_fn *fn,bt_for_each (hctx, q, btags, fn, priv, false); } } -srcu_read_unlock (&q->tag_set->tags_srcu, srcu_idx); +srcu_read_unlock (&blk_mq_tags_srcu, srcu_idx);blk_queue_exit (q); }
@@ -612,7 +619,7 @@ void blk_mq_free_tags(struct blk_mq_tag_set *set, struct blk_mq_tags *tags)return ; } -call_srcu (&set->tags_srcu, &tags->rcu_head, blk_mq_free_tags_callback); +call_srcu (&blk_mq_tags_srcu, &tags->rcu_head, blk_mq_free_tags_callback); }void blk_mq_tag_resize_shared_tags (struct blk_mq_tag_set *set,unsigned int size)
block/blk-mq.c +4 -11
@@ -3707,9 +3707,9 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx) };int srcu_idx; - srcu_idx =srcu_read_lock (&hctx->queue->tag_set->tags_srcu); + srcu_idx =srcu_read_lock (&blk_mq_tags_srcu);blk_mq_all_tag_iter (tags, blk_mq_has_request, &data); -srcu_read_unlock (&hctx->queue->tag_set->tags_srcu, srcu_idx); +srcu_read_unlock (&blk_mq_tags_srcu, srcu_idx);return data.has_rq; }
@@ -3981,7 +3981,7 @@ static void blk_mq_exit_hctx(struct request_queue *q,if (set->ops->exit_hctx) set->ops->exit_hctx (hctx, hctx_idx); -call_srcu (&set->tags_srcu, &hctx->fq->rcu_head, +call_srcu (&blk_mq_tags_srcu, &hctx->fq->rcu_head, blk_free_flush_queue_callback); hctx->fq =NULL ;
@@ -4884,9 +4884,6 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)if (ret) goto out_free_srcu; } - ret =init_srcu_struct (&set->tags_srcu); -if (ret) - goto out_cleanup_srcu;init_rwsem (&set->update_nr_hwq_lock);
@@ -4895,7 +4892,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)sizeof (struct blk_mq_tags *),GFP_KERNEL , set->numa_node);if (!set->tags) - goto out_cleanup_tags_srcu; + goto out_cleanup_srcu;for (i =0 ; i < set->nr_maps; i++) { set->map[i].mq_map = kcalloc_node(nr_cpu_ids,
@@ -4924,8 +4921,6 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) }kfree (set->tags); set->tags =NULL ; -out_cleanup_tags_srcu: -cleanup_srcu_struct (&set->tags_srcu); out_cleanup_srcu:if (set->flags &BLK_MQ_F_BLOCKING )cleanup_srcu_struct (set->srcu);
@@ -4972,8 +4967,6 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set)kfree (set->tags); set->tags =NULL ; -srcu_barrier (&set->tags_srcu); -cleanup_srcu_struct (&set->tags_srcu);if (set->flags &BLK_MQ_F_BLOCKING ) {cleanup_srcu_struct (set->srcu);kfree (set->srcu);
block/blk-mq.h +2 -0
@@ -178,6 +178,8 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, unsigned int flags, int node);void blk_mq_free_tags (struct blk_mq_tag_set *set,struct blk_mq_tags *tags); +extern struct srcu_struct blk_mq_tags_srcu; +unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data);unsigned long blk_mq_get_tags (struct blk_mq_alloc_data *data,int nr_tags,unsigned int *offset);
include/linux/blk-mq.h +0 -3
@@ -523,8 +523,6 @@ enum hctx_type {* request_queue.tag_set_list. * @srcu: Use as lock when type of the request queue is blocking * (BLK_MQ_F_BLOCKING). -* @tags_srcu: SRCU used to defer freeing of tags page_list to prevent -* use-after-free when iterating tags. * @update_nr_hwq_lock: * Synchronize updating nr_hw_queues with add/del disk & * switching elevator.
@@ -549,7 +547,6 @@ struct blk_mq_tag_set {struct mutex tag_list_lock;struct list_head tag_list;struct srcu_struct *srcu; -struct srcu_struct tags_srcu;struct rw_semaphore update_nr_hwq_lock; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1687/2151 ima: reject a kexec buffer whose declared size exceeds the buffer
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabrice Derepas <[email protected]>
[ Upstream commit ceb24c7052cc4649e3b52a51a7cca7dfe4896cec ]
ima_restore_measurement_list() parses the measurement list persisted across kexec. It computes the parse end directly from the blob:
bufendp = buf + khdr->buffer_size;
khdr->buffer_size is a u64 read straight from the persisted buffer. The only length checks in the function are size >= sizeof(*khdr), version == 1 and count -- none relates buffer_size to size, the actual buffer size the caller (ima_load_kexec_buffer()) obtained from the ima-kexec-buffer region. ima_parse_buf() bounds every field read to bufendp, so a blob whose internal buffer_size exceeds the real size makes the parse loop read past the end of the buffer (CWE-125).
The buffer's memory range is validated against addressable RAM by commit cbf9c4b9617b ("of: check previous kernel's ima-kexec-buffer against memory bounds") and commit c5489d04337b ("x86/kexec: add a sanity check on previous kernel's ima kexec buffer"), but the blob's own declared size is never clamped to it. Reject a buffer_size larger than size before the loop.
This is on the boot-time kexec-restore path (__init) and the buffer comes from the previous kernel, so triggering it requires control of the persisted buffer; it is an out-of-bounds read only.
--- security/integrity/ima/ima_template.c | 5 +++++ 1 file changed, 5 insertions(+)
security/integrity/ima/ima_template.c +5 -0
@@ -449,6 +449,11 @@ int ima_restore_measurement_list(loff_t size, void *buf)return -EINVAL ; } +if (khdr->buffer_size > size) { +pr_err ("attempting to restore a corrupted measurement list" ); +return -EINVAL ; + } +bitmap_zero (hdr_mask,HDR__LAST );bitmap_set (hdr_mask,HDR_PCR ,1 );bitmap_set (hdr_mask,HDR_DIGEST ,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1688/2151 net: phy: qcom: at803x: Apply IPQ5018 analog settings at probe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongzhao Chen <[email protected]>
[ Upstream commit 17baf30a0e64cde0e8a30723b7c6d06417152514 ]
ipq5018_probe() pulses the PHY reset, after which the IPQ5018 internal GE PHY starts autonegotiating with its reset-default analog settings. ipq5018_config_init() writes the analog settings only when the MAC attaches the PHY, usually when the interface is opened. On a board where the PHY connects to a QCA8337 PHY without a cable, 1000BASE-T does not come up in the meantime, SmartSpeed downshifts both PHYs, and only the IPQ5018 side restores its 1000BASE-T advertisement at attach, so the link stays down.
Apply the analog settings in probe right after the reset and restart autonegotiation. Move the settings into a helper shared with config_init() and return MDIO errors from it instead of ignoring them. The values written do not change, only the time of the write.
--- drivers/net/phy/qcom/at803x.c | 98 +++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 28 deletions(-)
drivers/net/phy/qcom/at803x.c +70 -28
@@ -1032,10 +1032,10 @@ static int ipq5018_cable_test_start(struct phy_device *phydev)return 0 ; } -static int ipq5018_config_init (struct phy_device *phydev) +static int ipq5018_analog_init (struct phy_device *phydev) {struct ipq5018_priv *priv = phydev->priv; -u16 val; +int val, ret;/* * set LDO efuse: first temporarily store ANA_DAC_FILTER value from
@@ -1043,39 +1043,66 @@ static int ipq5018_config_init(struct phy_device *phydev)* is written to */ val =at803x_debug_reg_read (phydev,IPQ5018_PHY_DEBUG_ANA_DAC_FILTER ); -at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE , -IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_MASK , -IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_DEFAULT ); -at803x_debug_reg_write (phydev,IPQ5018_PHY_DEBUG_ANA_DAC_FILTER , val); +if (val <0 ) +return val; + + ret =at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE , +IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_MASK , +IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_DEFAULT ); +if (ret) +return ret; + + ret =at803x_debug_reg_write (phydev,IPQ5018_PHY_DEBUG_ANA_DAC_FILTER , + val); +if (ret) +return ret;/* set 8023AZ EEE TX and RX timer values */ -phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_TX_TIMER , -IPQ5018_PHY_PCS_EEE_TX_TIMER_VAL ); -phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_RX_TIMER , -IPQ5018_PHY_PCS_EEE_RX_TIMER_VAL ); + ret =phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_TX_TIMER , +IPQ5018_PHY_PCS_EEE_TX_TIMER_VAL ); +if (ret) +return ret; + + ret =phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_RX_TIMER , +IPQ5018_PHY_PCS_EEE_RX_TIMER_VAL ); +if (ret) +return ret;/* set MSE threshold values */ -phy_write_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MSE_THRESH1 , -IPQ5018_PHY_MMD1_MSE_THRESH1_VAL ); -phy_write_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MSE_THRESH2 , -IPQ5018_PHY_MMD1_MSE_THRESH2_VAL ); + ret =phy_write_mmd (phydev,MDIO_MMD_PMAPMD , +IPQ5018_PHY_MMD1_MSE_THRESH1 , +IPQ5018_PHY_MMD1_MSE_THRESH1_VAL ); +if (ret) +return ret; + + ret =phy_write_mmd (phydev,MDIO_MMD_PMAPMD , +IPQ5018_PHY_MMD1_MSE_THRESH2 , +IPQ5018_PHY_MMD1_MSE_THRESH2_VAL ); +if (ret) +return ret;/* PHY DAC values are optional and only set in a PHY to PHY link architecture */ -if (priv->set_short_cable_dac) { -/* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */ -phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MDAC , -IPQ5018_PHY_DAC_MASK , -FIELD_PREP (IPQ5018_PHY_DAC_MASK , -IPQ5018_PHY_MMD1_MDAC_VAL )); - -/* setting EDAC (Error-detection and Correction) in debug register */ -at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_EDAC , -IPQ5018_PHY_DAC_MASK , -FIELD_PREP (IPQ5018_PHY_DAC_MASK , -IPQ5018_PHY_DEBUG_EDAC_VAL )); - } +if (!priv->set_short_cable_dac) +return 0 ; -return 0 ; +/* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */ + ret =phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MDAC , +IPQ5018_PHY_DAC_MASK , +FIELD_PREP (IPQ5018_PHY_DAC_MASK , +IPQ5018_PHY_MMD1_MDAC_VAL )); +if (ret) +return ret; + +/* setting EDAC (Error-detection and Correction) in debug register */ +return at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_EDAC , +IPQ5018_PHY_DAC_MASK , +FIELD_PREP (IPQ5018_PHY_DAC_MASK , +IPQ5018_PHY_DEBUG_EDAC_VAL )); +} + +static int ipq5018_config_init (struct phy_device *phydev) +{ +return ipq5018_analog_init (phydev); }static void ipq5018_link_change_notify (struct phy_device *phydev)
@@ -1113,6 +1140,21 @@ static int ipq5018_probe(struct phy_device *phydev) phydev->priv = priv; +/* +* The PHY starts autonegotiation as soon as it leaves reset. Apply the +* analog settings now instead of waiting for config_init() at attach +* time, and restart autonegotiation so that it uses them. +*/ + ret =ipq5018_analog_init (phydev); +if (ret) +return dev_err_probe (dev, ret, +"failed to apply analog settings\n" ); + + ret =genphy_restart_aneg (phydev); +if (ret) +return dev_err_probe (dev, ret, +"failed to restart autonegotiation\n" ); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1689/2151 usbnet: fix smp_processor_id() use in preemptible context
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 95a5c641fc7becab441bf244baa73b0b0f8b7dea ]
tx_complete() calls this_cpu_ptr() before disabling preemption, which triggers a BUG when running with CONFIG_DEBUG_PREEMPT:
BUG: using smp_processor_id() in preemptible code in tx_complete
Fix by using get_cpu_ptr()/put_cpu_ptr() which disable preemption and return the per-CPU pointer atomically. The usbnet_skb_return() hunk is a hardening change: that path runs in softirq context so no warning fires there, but the same fix is applied for consistency.
--- drivers/net/usb/usbnet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/usb/usbnet.c +6 -2
@@ -328,7 +328,7 @@ static void __usbnet_status_stop_force(struct usbnet *dev)*/ void usbnet_skb_return (struct usbnet *dev,struct sk_buff *skb) { -struct pcpu_sw_netstats *stats64 =this_cpu_ptr (dev->net->tstats); +struct pcpu_sw_netstats *stats64;unsigned long flags;int status;
@@ -341,10 +341,12 @@ void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)if (skb->protocol ==0 ) skb->protocol =eth_type_trans (skb, dev->net); + stats64 =get_cpu_ptr (dev->net->tstats); flags =u64_stats_update_begin_irqsave (&stats64->syncp);u64_stats_inc (&stats64->rx_packets);u64_stats_add (&stats64->rx_bytes, skb->len);u64_stats_update_end_irqrestore (&stats64->syncp, flags); +put_cpu_ptr (dev->net->tstats);netif_dbg (dev, rx_status, dev->net,"< rx, len %zu, type 0x%x\n" , skb->len +sizeof (struct ethhdr ), skb->protocol);
@@ -1284,13 +1286,15 @@ static void tx_complete (struct urb *urb)struct usbnet *dev = entry->dev;if (urb->status ==0 ) { -struct pcpu_sw_netstats *stats64 =this_cpu_ptr (dev->net->tstats); +struct pcpu_sw_netstats *stats64;unsigned long flags; + stats64 =get_cpu_ptr (dev->net->tstats); flags =u64_stats_update_begin_irqsave (&stats64->syncp);u64_stats_add (&stats64->tx_packets, entry->packets);u64_stats_add (&stats64->tx_bytes, entry->length);u64_stats_update_end_irqrestore (&stats64->syncp, flags); +put_cpu_ptr (dev->net->tstats); }else { dev->net->stats.tx_errors++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1690/2151 platform: cznic: turris-omnia-mcu: stop button emulation producers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 0045cd6b8ab2319e9d8de46e5e329cdc35ce6d05 ]
The legacy MCU IRQ thread can requeue button-release emulation work after its managed cleanup has canceled it. Since the IRQ is still active at that point, the newly queued work can outlive device teardown and access freed MCU state.
Use disable_delayed_work_sync() to prevent further queueing and drain the worker before the IRQ action is released. Keep the parent IRQ active while the worker completes. devm_add_action_or_reset() also drains the work if action registration fails.
This issue was identified as part of our ongoing research while reviewing kernel code.
--- .../platform/cznic/turris-omnia-mcu-gpio.c | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/platform/cznic/turris-omnia-mcu-gpio.c +15 -16
@@ -11,7 +11,6 @@#include <linux/bug.h> #include <linux/cleanup.h> #include <linux/device.h> -#include <linux/devm-helpers.h> #include <linux/errno.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h>
@@ -841,6 +840,18 @@ static void button_release_emul_fn(struct work_struct *work)generic_handle_irq_safe (mcu->client->irq); } +static void omnia_disable_button_release_work (void *data) +{ +struct delayed_work *work = data; + +/* +* The IRQ thread may requeue this work while the IRQ remains active. +* Disable and drain it before releasing the IRQ action and the MCU +* state used by the worker. +*/ +disable_delayed_work_sync (work); +} + static void fill_int_from_sts(unsigned long *rising, unsigned long *falling, unsigned long rising_sts, unsigned long falling_sts,
@@ -1082,21 +1093,9 @@ int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu)return dev_err_probe (dev, err,"Cannot request IRQ\n" );if (!new_api) { -/* -* The button_release_emul_work has to be initialized before the -* thread is requested, and on driver remove it needs to be -* canceled before the thread is freed. Therefore we can't use -* devm_delayed_work_autocancel() directly, because the order -* devm_delayed_work_autocancel(); -* devm_request_threaded_irq(); -* would cause improper release order: -* free_irq(); -* cancel_delayed_work_sync(); -* Instead we first initialize the work above, and only now -* after IRQ is requested we add the work devm action. -*/ - err =devm_add_action (dev, devm_delayed_work_drop, - &mcu->button_release_emul_work); + err =devm_add_action_or_reset (dev, + omnia_disable_button_release_work, + &mcu->button_release_emul_work);if (err)return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1691/2151 ALSA: 6fire: take stream_mutex in the Digital Thru control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Piotr Gliźniewicz <[email protected]>
[ Upstream commit d030561d53cb272bb55ba2dd11aaa609e8240b7e ]
usb6fire_control_digital_thru_put() calls usb6fire_control_streaming_update(), which on an idle card with Digital Thru on selects altsetting 2 and writes the clock register for 96 kHz through usb6fire_control_set_rate(). usb6fire_pcm_prepare() calls both functions through usb6fire_pcm_set_rate() under rt->stream_mutex. The put does not take stream_mutex, so the two can run at the same time.
500 runs of a 0.2 s aplay at 48 kHz while a second loop toggled "Digital Thru Playback Route" with amixer (12693 on/off cycles, kernel 7.2.9): in 216 cases the two usb_set_interface() calls ran at the same time and the kernel logged "sysfs: cannot create duplicate filename '.../3-2:1.1/ep_82'" with a stack dump. 27 of the aplay runs failed, and for each of them the kernel logged "could not start pcm stream".
Take stream_mutex in the put. The pcm runtime is created before the controls and freed with the card, so chip->pcm is valid whenever the put runs. The put waits for a running prepare, which makes synchronous USB transfers under stream_mutex; on a card that responds late the wait can reach about 12 s, or 24 s with Digital Thru on, and during the wait the other controls of the card can be neither read nor written, because snd_ctl_elem_write() holds controls_rwsem around the put. Before this patch the put already made transfers of the same kind under controls_rwsem. No code that holds stream_mutex takes controls_rwsem.
The same test on kernel 7.2.10 with this patch (12863 cycles) gave no failed aplay run and no "duplicate filename" message.
--- sound/usb/6fire/control.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/usb/6fire/control.c +7 -0
@@ -20,6 +20,7 @@#include "control.h" #include "comm.h" #include "chip.h" +#include "pcm.h" static const char *const opt_coax_texts[2 ] = {"Optical" ,"Coax" };static const char *const line_phono_texts[2 ] = {"Line" ,"Phono" };
@@ -383,6 +384,12 @@ static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,struct control_runtime *rt =snd_kcontrol_chip (kcontrol);int changed =0 ; +/* +* with Digital Thru on, streaming_update() selects the altsetting and +* writes the clock register of an idle card; prepare does the same +* under stream_mutex +*/ +guard (mutex)(&rt->chip->pcm->stream_mutex);if (rt->digital_thru_switch != ucontrol->value.integer.value[0 ]) { rt->digital_thru_switch = ucontrol->value.integer.value[0 ];usb6fire_control_streaming_update (rt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1692/2151 btrfs: drop the extent maps of the written part of a failed ordered extent
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit bca2cf55a7331e6b0ff95ad47fc2a7e8ecc7dc74 ]
If a truncated ordered extent fails to complete, the extent maps for the part that was written are kept while the extent itself is freed below. A later read can follow them to blocks that have been reallocated. Drop the maps for the whole range on error.
--- fs/btrfs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +3 -1
@@ -3316,6 +3316,8 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)/* * Drop extent maps for the part of the extent we didn't write. +* On error the written part is freed below as well, so drop +* its maps too. * * We have an exception here for the free_space_inode, this is * because when we do btrfs_get_extent() on the free space inode
@@ -3331,7 +3333,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)if (!btrfs_is_free_space_inode (inode)) {u64 unwritten_start = start; -if (truncated) +if (truncated && !ret) unwritten_start += logical_len; btrfs_drop_extent_map_range(inode, unwritten_start,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1693/2151 btrfs: update the inode item when removing a free space inode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 4e89aff9ad6fcbec555c38169807c4023f93450f ]
btrfs_remove_free_space_inode() adds an orphan item for the free space inode and clears its link count in memory, but never writes the inode item. The item is only removed once the delayed iput evicts the inode, which happens in a later transaction, from the cleaner thread or a throttled transaction end.
If we crash in between, or if evict can't reserve space for the truncation and leaves the orphan item for the next mount, the on-disk inode still has a link count of 1. btrfs_orphan_cleanup() then treats it as an inode with links and only deletes the orphan item. The free space header item is already gone at that point, so nothing ever finds the inode again, and its data extents are leaked.
Write the zero link count to the inode item in the same transaction as the orphan item, so the orphan cleanup evicts the inode instead. Account for the extra tree root item update when removing a block group.
--- fs/btrfs/block-group.c | 6 ++++-- fs/btrfs/free-space-cache.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
fs/btrfs/block-group.c +4 -2
@@ -1319,12 +1319,14 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(ASSERT (map->start == chunk_offset);/* -* We need to reserve 3 + N units from the metadata space info in order +* We need to reserve 4 + N units from the metadata space info in order * to remove a block group (done at btrfs_remove_chunk() and at * btrfs_remove_block_group()), which are used for: * * 1 unit for adding the free space inode's orphan (located in the tree * of tree roots). +* 1 unit for updating the free space inode's item (located in the tree +* of tree roots). * 1 unit for deleting the block group item (located in the extent * tree). * 1 unit for deleting the free space item (located in tree of tree
@@ -1337,7 +1339,7 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(* more device items and remove one chunk item), but this is done at * btrfs_remove_chunk() through a call to check_system_chunk(). */ - num_items =3 + map->num_stripes; + num_items =4 + map->num_stripes;btrfs_free_chunk_map (map);return btrfs_start_transaction_fallback_global_rsv (root, num_items);
fs/btrfs/free-space-cache.c +10 -0
@@ -265,6 +265,16 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans,return ret; }clear_nlink (inode); +/* +* Persist the zero link count, so that if the delayed iput below +* doesn't get to evict the inode, the orphan cleanup on the next mount +* evicts it instead of only deleting the orphan item. +*/ + ret =btrfs_update_inode (trans,BTRFS_I (inode)); +if (ret) { +btrfs_add_delayed_iput (BTRFS_I (inode)); +return ret; + }/* One for the block groups ref */ spin_lock (&block_group->lock);if (test_and_clear_bit (BLOCK_GROUP_FLAG_IREF , &block_group->runtime_flags)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1694/2151 ARC: Strip libgcc debug information when generating BTF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit ca201ad6e92a1924138e83ff966f7a091e3bbe6e ]
ARC links against the compiler's libgcc archive. The ARC GNU 2023.03 toolchain ships this library with debug information, including complex floating-point types in integer arithmetic helpers such as __udivdi3. These types reach vmlinux even though the kernel does not use complex floating-point arithmetic.
When floating-point BTF encoding is enabled, pahole rejects those types:
Complex, interval and imaginary float types are not supported Error while encoding BTF.
FAILED: load BTF from .tmp_vmlinux1.BTF.1: No such file or directory
KernelCI's upgrade to pahole 1.31 exposed this long-standing problem as failed ARC builds. As of 1.32, pahole still rejects these types, and older versions will stay in use, so the kernel build has to keep them out of vmlinux. Commit f122668ddcce ("ARC: Add eBPF JIT support") documented the same failure along with a workaround of disabling floating-point BTF encoding, but that also discards supported floating-point types from kernel BTF.
For CONFIG_DEBUG_INFO_BTF, generate a debug-stripped copy of the selected libgcc archive in the output tree and link that copy. Preserve the archive structure so that only needed helpers are linked, and use the normal Kbuild objcopy rule to track input and command changes. The trade-off is that vmlinux in BTF-enabled builds no longer carries DWARF for the libgcc helpers. Debug information for kernel code, the installed toolchain and non-BTF builds stay unchanged.
Reproduced and tested with ARC GCC 12.2.1 and pahole 1.31 and 1.32 using an ARCv2 tinyconfig with BPF_SYSCALL and DWARF4/BTF enabled. Before and after vmlinux.o files are identical after stripping debug information.
--- arch/arc/Makefile | 9 ++++++++- arch/arc/lib/Makefile | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
arch/arc/Makefile +8 -1
@@ -87,7 +87,14 @@ core-$(CONFIG_ARC_PLAT_TB10X) += arch/arc/plat-tb10x/ core-$(CONFIG_ARC_PLAT_AXS10X) += arch/arc/plat-axs10x/ core-$(CONFIG_ARC_SOC_HSDK) += arch/arc/plat-hsdk/ -libs-y += arch/arc/lib/ $(LIBGCC) +libs-y += arch/arc/lib/ + +ifdef CONFIG_DEBUG_INFO_BTF +export LIBGCC := $(LIBGCC) +libs-y += arch/arc/lib/libgcc.a +else +libs-y += $(LIBGCC) +endif boot := arch/arc/boot
arch/arc/lib/Makefile +8 -0
@@ -13,3 +13,11 @@ lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs-unaligned.o else lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs.o endif + +# libgcc can contain complex floating-point debug types unsupported by BTF. +# Strip only the debug information from a local copy of the selected archive. +always-$(CONFIG_DEBUG_INFO_BTF) += libgcc.a +OBJCOPYFLAGS_libgcc.a := --strip-debug + +$(obj)/libgcc.a: $(LIBGCC) FORCE + $(call if_changed,objcopy)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1695/2151 bpf: Claim the per-CPU send_signal irq_work before filling it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 2d1f101ee619435873ed8a23fcb3bd09204a5024 ]
irq_work_is_busy() cannot see the per-CPU send_signal_work while it is being filled: the check only matches after irq_work_queue() has claimed the work. A concurrent caller therefore passes it, both callers race for the same irq_work, and the loser's signal is silently lost along with its task reference while the queued work runs with a mix of both callers' fields.
kprobe, tracepoint and perf_event programs exclude each other on the same CPU through bpf_prog_active, so for two callers to meet, one of the programs has to be a raw tracepoint or an fentry one. And since commit 87c544108b61 ("bpf: Send signals asynchronously if !preemptible") this path runs with IRQs enabled too, so a hard IRQ can interrupt the fill as well, not only an NMI. Found by code inspection and reproduced with a perf_event NMI program racing an fentry one.
Claim the work through work->task itself: cmpxchg() it from NULL to the target task before touching the other fields, and set it back to NULL once the callback has consumed them. A context finding the work claimed returns the documented -EBUSY.
--- kernel/trace/bpf_trace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/trace/bpf_trace.c +5 -2
@@ -793,6 +793,7 @@ const struct bpf_func_proto bpf_task_pt_regs_proto = {struct send_signal_irq_work {struct irq_work irq_work; +/* The claim: NULL marks the slot free for the next caller. */ struct task_struct *task;u32 sig;enum pid_type type;
@@ -812,6 +813,8 @@ static void do_bpf_send_signal(struct irq_work *entry)group_send_sig_info (work->sig, siginfo, work->task, work->type);put_task_struct (work->task); +/* Release once the fields are consumed. */ +smp_store_release (&work->task,NULL ); }static int bpf_send_signal_common (u32 sig,enum pid_type type,struct task_struct *task,u64 value)
@@ -855,14 +858,14 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type, struct task_strucreturn -EINVAL ; work =this_cpu_ptr (&send_signal_work); -if (irq_work_is_busy (&work->irq_work)) +if (cmpxchg (&work->task,NULL , task))return -EBUSY ;/* Add the current task, which is the target of sending signal, * to the irq_work. The current task may change when queued * irq works get executed. */ - work->task =get_task_struct (task); +get_task_struct (task); work->has_siginfo = siginfo == &info;if (work->has_siginfo)copy_siginfo (&work->info, &info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1696/2151 ASoC: codecs: da732x: Fix definition of ADC2 EQ Overall Volume control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit ebef9212cb469706e28002a20f9d48307d1fd867 ]
The ADC2 EQ overall volume is in DA732X_REG_ADC2_EQ5 (0x9F), not in DA732X_REG_ADC1_EQ5 (0x97), which holds the ADC1 one.
--- sound/soc/codecs/da732x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/da732x.c +1 -1
@@ -511,7 +511,7 @@ static const struct snd_kcontrol_new da732x_snd_controls[] = {SOC_SINGLE_TLV ("ACD2 EQ Band 5 Volume" ,DA732X_REG_ADC2_EQ5 ,DA732X_EQ_BAND5_SHIFT ,DA732X_EQ_VOL_VAL_MAX ,DA732X_INVERT , eq_band_pga_tlv), -SOC_SINGLE_TLV ("ADC2 EQ Overall Volume" ,DA732X_REG_ADC1_EQ5 , +SOC_SINGLE_TLV ("ADC2 EQ Overall Volume" ,DA732X_REG_ADC2_EQ5 ,DA732X_EQ_OVERALL_SHIFT ,DA732X_EQ_OVERALL_VOL_VAL_MAX , DA732X_INVERT, eq_overall_tlv),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1697/2151 ASoC: codecs: tlv320adc3xxx: Fix definition of AGC Target Level control
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 0a9efcb663b5a4d468cbb90de29c6dd3794af124 ]
The right channel AGC target level is in RIGHT_CHN_AGC_1, as on the left, not in RIGHT_CHN_AGC_2, which holds the right noise threshold and hysteresis.
--- sound/soc/codecs/tlv320adc3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tlv320adc3xxx.c +1 -1
@@ -691,7 +691,7 @@ static const struct snd_kcontrol_new adc3xxx_snd_controls[] = {SOC_DOUBLE_R ("AGC Capture Switch" ,ADC3XXX_LEFT_CHN_AGC_1 ,ADC3XXX_RIGHT_CHN_AGC_1 ,7 ,1 ,0 ),SOC_DOUBLE_R_TLV ("AGC Target Level Capture Volume" ,ADC3XXX_LEFT_CHN_AGC_1 , -ADC3XXX_RIGHT_CHN_AGC_2 ,4 ,0x07 ,1 , agc_target_tlv), +ADC3XXX_RIGHT_CHN_AGC_1 ,4 ,0x07 ,1 , agc_target_tlv),SOC_DOUBLE_R_TLV ("AGC Noise Threshold Capture Volume" ,ADC3XXX_LEFT_CHN_AGC_2 ,ADC3XXX_RIGHT_CHN_AGC_2 ,1 ,0x1f ,1 , agc_thresh_tlv), SOC_DOUBLE_R_TLV("AGC Hysteresis Capture Volume", ADC3XXX_LEFT_CHN_AGC_2,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1698/2151 ASoC: codecs: sta32x: Fix definition of Ch2 and Ch3 Volume Bypass controls
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit ea53ab9003d8655cf7e94428de3006e86fbd06a0 ]
Each channel's master volume bypass (CxVBP) is in its own configuration register, C2CFG and C3CFG, not in C1CFG, which holds the channel 1 bit.
--- sound/soc/codecs/sta32x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/sta32x.c +2 -2
@@ -494,8 +494,8 @@ SOC_SINGLE("Ch2 Tone Control Bypass Switch", STA32X_C2CFG, STA32X_CxCFG_TCB_SHIFSOC_SINGLE ("Ch1 EQ Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_EQBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch2 EQ Bypass Switch" ,STA32X_C2CFG , STA32X_CxCFG_EQBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch1 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), -SOC_SINGLE ("Ch2 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), -SOC_SINGLE ("Ch3 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), +SOC_SINGLE ("Ch2 Master Volume Bypass Switch" ,STA32X_C2CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), +SOC_SINGLE ("Ch3 Master Volume Bypass Switch" ,STA32X_C3CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ),SOC_ENUM ("Ch1 Limiter Select" , sta32x_limiter_ch1_enum),SOC_ENUM ("Ch2 Limiter Select" , sta32x_limiter_ch2_enum), SOC_ENUM("Ch3 Limiter Select", sta32x_limiter_ch3_enum),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1699/2151 ASoC: codecs: sta350: Fix definition of Ch2 and Ch3 Volume Bypass controls
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 7308ce7c8459e994a36a22607e974e3e132a9275 ]
Each channel's master volume bypass (CxVBP) is in its own configuration register, C2CFG and C3CFG, not in C1CFG, which holds the channel 1 bit.
--- sound/soc/codecs/sta350.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/sta350.c +2 -2
@@ -481,9 +481,9 @@ SOC_SINGLE("Ch2 EQ Bypass Switch",SOC_SINGLE ("Ch1 Master Volume Bypass Switch" ,STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch2 Master Volume Bypass Switch" , -STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ), +STA350_C2CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch3 Master Volume Bypass Switch" , -STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ), +STA350_C3CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_ENUM ("Ch1 Binary Output Select" , sta350_binary_output_ch1_enum),SOC_ENUM ("Ch2 Binary Output Select" , sta350_binary_output_ch2_enum), SOC_ENUM("Ch3 Binary Output Select", sta350_binary_output_ch3_enum),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1700/2151 calipso: update payload_len when removing the CALIPSO option
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit 00accbd9d5021b942a16078bd5717d7865f6971c ]
calipso_skbuff_delattr() removes the CALIPSO option from the hop-by-hop extension header, or the whole extension header if CALIPSO is its only option, and pulls the skb by the removed length. It never updates ipv6hdr->payload_len, so after a successful removal the header still claims the original length.
calipso_skbuff_setattr() already adjusts payload_len by the length it adds; the delete path was missed.
This is reached on the forward path when a packet carrying CALIPSO is sent to a destination mapped to an unlabeled NetLabel domain. The forwarded packet then has a payload_len larger than its real payload by the removed length (8 to 264 bytes), and the receiver drops it as truncated. So removing the label on the forward path has been broken for every packet that is not resegmented later (SYN, UDP, ICMPv6...).
Adjust payload_len after the header is moved. BIG TCP packets carry payload_len == 0 (see ipv6_set_payload_len()), and ipv6_payload_len() then falls back to skb->len, so leave them alone.
Tested with client, router and server network namespaces on one kernel (arm64, QEMU): SELinux permissive with a minimal mdp-generated policy (network_peer_controls=1), "netlabelctl calipso add pass doi:16", the default NetLabel mapping left unlabeled, IPv6 forwarding on the router. The client sends 5 UDP datagrams with a CALIPSO hop-by-hop option (DOI 16, set through IPV6_HOPOPTS) to the server through the router:
before: router Ip6OutForwDatagrams 5, server receives 0,
server Ip6InTruncatedPkts 5
after: router Ip6OutForwDatagrams 5, server receives 5,
server Ip6InTruncatedPkts 0
--- net/ipv6/calipso.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/calipso.c +4 -0
@@ -1429,6 +1429,10 @@ static int calipso_skbuff_delattr(struct sk_buff *skb)skb_pull (skb, delta);memmove ((char *)ip6_hdr + delta, ip6_hdr, size);skb_reset_network_header (skb); + ip6_hdr =ipv6_hdr (skb); +/* BIG TCP packets have payload_len == 0 */ +if (ip6_hdr->payload_len) +be16_add_cpu (&ip6_hdr->payload_len, -delta); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1701/2151 dpll: zl3073x: Add output pin frequency helper
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 24e4336a87f5c51263535201218889b5f324511f ]
Introduce zl3073x_dev_output_pin_freq_get() helper function to compute the output pin frequency based on synthesizer frequency, output divisor, and signal format. For N-div signal formats, the N-pin frequency is additionally divided by esync_n_period.
Add zl3073x_out_is_ndiv() helper to check if an output is configured in N-div mode (2_NDIV or 2_NDIV_INV signal formats).
Refactor zl3073x_dpll_output_pin_frequency_get() callback to use the new helper, reducing code duplication and enabling reuse of the frequency calculation logic in other contexts.
This is a preparatory change for adding current frequency to the supported frequencies list in pin properties.
Stable-dep-of: 23171065fb43 ("dpll: zl3073x: do not offer 0 Hz as a supported pin frequency")
--- drivers/dpll/zl3073x/core.h | 30 ++++++++++++++++++++++++++++ drivers/dpll/zl3073x/dpll.c | 39 +------------------------------------ drivers/dpll/zl3073x/out.h | 17 ++++++++++++++++ 3 files changed, 48 insertions(+), 38 deletions(-)
drivers/dpll/zl3073x/core.h +30 -0
@@ -406,6 +406,36 @@ u8 zl3073x_dev_out_dpll_get(struct zl3073x_dev *zldev, u8 index)return zl3073x_synth_dpll_get (synth); } +/** +* zl3073x_dev_output_pin_freq_get - get output pin frequency +* @zldev: pointer to zl3073x device +* @id: output pin id +* +* Computes the output pin frequency based on the synth frequency, output +* divisor, and signal format. For N-div formats, N-pin frequency is +* additionally divided by esync_n_period. +* +* Return: frequency of the given output pin in Hz +*/ +static inline u32 +zl3073x_dev_output_pin_freq_get (struct zl3073x_dev *zldev,u8 id) +{ +const struct zl3073x_synth *synth; +const struct zl3073x_out *out; +u8 out_id; +u32 freq; + + out_id =zl3073x_output_pin_out_get (id); + out =zl3073x_out_state_get (zldev, out_id); + synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (out)); + freq =zl3073x_synth_freq_get (synth) / out->div; + +if (zl3073x_out_is_ndiv (out) &&zl3073x_is_n_pin (id)) + freq /= out->esync_n_period; + +return freq; +} +/** * zl3073x_dev_out_is_diff - check if the given output is differential * @zldev: pointer to zl3073x device
drivers/dpll/zl3073x/dpll.c +1 -38
@@ -903,46 +903,9 @@ zl3073x_dpll_output_pin_frequency_get(const struct dpll_pin *dpll_pin, struct netlink_ext_ack *extack) {struct zl3073x_dpll *zldpll = dpll_priv; -struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -const struct zl3073x_synth *synth; -const struct zl3073x_out *out; -u32 synth_freq; -u8 out_id; - out_id =zl3073x_output_pin_out_get (pin->id); - out =zl3073x_out_state_get (zldev, out_id); - -/* Get attached synth frequency */ - synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (out)); - synth_freq =zl3073x_synth_freq_get (synth); - -switch (zl3073x_out_signal_format_get (out)) { -case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV : -case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV : -/* In case of divided format we have to distiguish between -* given output pin type. -* -* For P-pin the resulting frequency is computed as simple -* division of synth frequency and output divisor. -* -* For N-pin we have to divide additionally by divisor stored -* in esync_n_period output mailbox register that is used as -* N-pin divisor for these modes. -*/ - *frequency = synth_freq / out->div; - -if (!zl3073x_dpll_is_p_pin (pin)) - *frequency = (u32)*frequency / out->esync_n_period; - -break ; -default : -/* In other modes the resulting frequency is computed as -* division of synth frequency and output divisor. -*/ - *frequency = synth_freq / out->div; -break ; - } + *frequency =zl3073x_dev_output_pin_freq_get (zldpll->dev, pin->id);return 0 ; }
drivers/dpll/zl3073x/out.h +17 -0
@@ -79,6 +79,23 @@ static inline bool zl3073x_out_is_enabled(const struct zl3073x_out *out)return !!FIELD_GET (ZL_OUTPUT_CTRL_EN , out->ctrl); } +/** +* zl3073x_out_is_ndiv - check if the given output is in N-div mode +* @out: pointer to out state +* +* Return: true if output is in N-div mode, false otherwise +*/ +static inline bool zl3073x_out_is_ndiv (const struct zl3073x_out *out) +{ +switch (zl3073x_out_signal_format_get (out)) { +case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV : +case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV : +return true; +default : +return false; + } +} +/** * zl3073x_out_synth_get - get synth connected to given output * @out: pointer to out state
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1702/2151 dpll: zl3073x: Include current frequency in supported frequencies list
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 85a9aaac4a38a7ce68f30bd7678fca4e8c687fe2 ]
Ensure the current pin frequency is always present in the list of supported frequencies reported to userspace. Previously, if the firmware node was missing or didn't include the current operating frequency in the supported-frequencies-hz property, the pin would report a frequency that wasn't in its supported list.
Get the current frequency early in zl3073x_pin_props_get():
- For input pins: use zl3073x_dev_ref_freq_get()
- For output pins: use zl3073x_dev_output_pin_freq_get()
Place the current frequency at index 0 of the supported frequencies array, then append frequencies from the firmware node (if present), skipping any duplicate of the current frequency.
Stable-dep-of: 23171065fb43 ("dpll: zl3073x: do not offer 0 Hz as a supported pin frequency")
--- drivers/dpll/zl3073x/prop.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/dpll/zl3073x/prop.c +21 -11
@@ -193,9 +193,10 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, {struct dpll_pin_frequency *ranges;struct zl3073x_pin_props *props; -int i, j, num_freqs, rc; +int i, j, num_freqs =0 , rc; +u64 *freqs =NULL ;const char *type; -u64 *freqs; +u32 curr_freq; props =kzalloc (sizeof (*props),GFP_KERNEL );if (!props)
@@ -207,6 +208,7 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, props->dpll_props.capabilities =DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; + curr_freq =zl3073x_dev_ref_freq_get (zldev, index); }else {u8 out, synth;u32 f;
@@ -220,6 +222,7 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, synth =zl3073x_dev_out_synth_get (zldev, out); f =2 *zl3073x_dev_synth_freq_get (zldev, synth); props->dpll_props.phase_gran = f ?div_u64 (PSEC_PER_SEC , f) :1 ; + curr_freq =zl3073x_dev_output_pin_freq_get (zldev, index); } props->dpll_props.phase_range.min =S32_MIN ;
@@ -230,7 +233,7 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev,/* Get firmware node for the given pin */ rc =zl3073x_prop_pin_fwnode_get (zldev, props, dir, index);if (rc) -return props;/* Return if it does not exist */ + goto skip_fwnode_props;/* Look for label property and store the value as board label */ fwnode_property_read_string(props->fwnode, "label",
@@ -262,9 +265,10 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev,/* Read supported frequencies property if it is specified */ num_freqs =fwnode_property_count_u64 (props->fwnode,"supported-frequencies-hz" ); -if (num_freqs <=0 ) -/* Return if the property does not exist or number is 0 */ -return props; +if (num_freqs <=0 ) { + num_freqs =0 ; + goto skip_fwnode_props; + }/* The firmware node specifies list of supported frequencies while * DPLL core pin properties requires list of frequency ranges.
@@ -281,19 +285,25 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev,"supported-frequencies-hz" , freqs, num_freqs); -/* Allocate frequency ranges list and fill it */ - ranges =kcalloc (num_freqs,sizeof (*ranges),GFP_KERNEL ); +skip_fwnode_props: +/* Allocate frequency ranges list - extra slot for current frequency */ + ranges =kcalloc (num_freqs +1 ,sizeof (*ranges),GFP_KERNEL );if (!ranges) { rc = -ENOMEM ; goto err_alloc_ranges; } -/* Convert list of frequencies to list of frequency ranges but -* filter-out frequencies that are not representable by device +/* Start with current frequency at index 0 */ + ranges[0 ] = (struct dpll_pin_frequency )DPLL_PIN_FREQUENCY (curr_freq); + +/* Add frequencies from firmware node, skipping current frequency +* and filtering out frequencies not representable by device */ -for (i =0 , j =0 ; i < num_freqs; i++) { +for (i =0 , j =1 ; i < num_freqs; i++) {struct dpll_pin_frequency freq =DPLL_PIN_FREQUENCY (freqs[i]); +if (freqs[i] == curr_freq) +continue ;if (zl3073x_pin_check_freq (zldev, dir, index, freqs[i])) { ranges[j] = freq; j++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1703/2151 dpll: zl3073x: do not offer 0 Hz as a supported pin frequency
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 23171065fb436195981ca32f9e49dcf852dbd018 ]
zl3073x_pin_props_get() always adds the current pin frequency to the supported list without checking it. A sub-Hz frequency reads back as 0 Hz, so 0 Hz can then be requested and the output frequency set callback divides by zero. A 0 Hz entry in the firmware node is not rejected either: it is offered for an input pin, and for an output pin zl3073x_pin_check_freq() divides by it at probe time.
Do not add a 0 Hz current frequency and reject 0 Hz in zl3073x_pin_check_freq(). If the list ends up empty, do not publish it at all, as the DPLL core rejects an empty non-NULL list.
Found by code inspection, not triggered at runtime.
--- drivers/dpll/zl3073x/prop.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/dpll/zl3073x/prop.c +19 -4
@@ -30,7 +30,7 @@ static bool zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir, u8 id, u64 freq) { - if (freq > U32_MAX) + if (!freq || freq > U32_MAX) goto err_inv_freq;if (dir ==DPLL_PIN_DIRECTION_INPUT ) {
@@ -293,13 +293,20 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, goto err_alloc_ranges; } -/* Start with current frequency at index 0 */ - ranges[0 ] = (struct dpll_pin_frequency )DPLL_PIN_FREQUENCY (curr_freq); +/* Start with current frequency at index 0. A sub-Hz frequency is +* read back as 0 Hz and cannot be set, so it is not offered. +*/ + j =0 ; +if (curr_freq) { +struct dpll_pin_frequency freq =DPLL_PIN_FREQUENCY (curr_freq); + + ranges[j++] = freq; + }/* Add frequencies from firmware node, skipping current frequency * and filtering out frequencies not representable by device */ -for (i =0 , j =1 ; i < num_freqs; i++) { +for (i =0 ; i < num_freqs; i++) {struct dpll_pin_frequency freq =DPLL_PIN_FREQUENCY (freqs[i]);if (freqs[i] == curr_freq)
@@ -310,6 +317,14 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, } } +/* The DPLL core rejects a non-NULL list without entries, so do +* not publish the array at all when nothing is settable. +*/ +if (!j) { +kfree (ranges); + ranges =NULL ; + } +/* Save number of freq ranges and pointer to them into pin properties */ props->dpll_props.freq_supported = ranges; props->dpll_props.freq_supported_num = j;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1704/2151 dpll: zl3073x: clean up esync get/set and use zl3073x_out_is_ndiv()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 3c8c39768b10867e4f630080785b602245f01760 ]
Return -EOPNOTSUPP early in esync_get callbacks when esync is not supported instead of conditionally populating the range at the end. This simplifies the control flow by removing the finish label/goto in the output variant and the conditional range assignment in both input and output variants.
Replace open-coded N-div signal format switch statements with zl3073x_out_is_ndiv() helper in esync_get, esync_set and frequency_set callbacks.
Stable-dep-of: f8993627d310 ("dpll: zl3073x: reject inexact frequencies for N-divided outputs")
--- drivers/dpll/zl3073x/dpll.c | 64 ++++++++++++------------------------- 1 file changed, 20 insertions(+), 44 deletions(-)
drivers/dpll/zl3073x/dpll.c +20 -44
@@ -117,6 +117,12 @@ zl3073x_dpll_input_pin_esync_get(const struct dpll_pin *dpll_pin, ref_id =zl3073x_input_pin_ref_get (pin->id); ref =zl3073x_ref_state_get (zldev, ref_id); +if (!pin->esync_control ||zl3073x_ref_freq_get (ref) <=1 ) +return -EOPNOTSUPP ; + + esync->range = esync_freq_ranges; + esync->range_num =ARRAY_SIZE (esync_freq_ranges); +switch (FIELD_GET (ZL_REF_SYNC_CTRL_MODE , ref->sync_ctrl)) {case ZL_REF_SYNC_CTRL_MODE_50_50_ESYNC_25_75 : esync->freq = ref->esync_n_div ==ZL_REF_ESYNC_DIV_1HZ ?1 :0 ;
@@ -128,17 +134,6 @@ zl3073x_dpll_input_pin_esync_get(const struct dpll_pin *dpll_pin,break ; } -/* If the pin supports esync control expose its range but only -* if the current reference frequency is > 1 Hz. -*/ -if (pin->esync_control &&zl3073x_ref_freq_get (ref) >1 ) { - esync->range = esync_freq_ranges; - esync->range_num =ARRAY_SIZE (esync_freq_ranges); - }else { - esync->range =NULL ; - esync->range_num =0 ; - } -return 0 ; }
@@ -775,8 +770,8 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,struct zl3073x_dpll_pin *pin = pin_priv;const struct zl3073x_synth *synth;const struct zl3073x_out *out; +u32 synth_freq, out_freq;u8 clock_type, out_id; -u32 synth_freq; out_id =zl3073x_output_pin_out_get (pin->id); out =zl3073x_out_state_get (zldev, out_id);
@@ -785,17 +780,19 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,* for N-division is also used for the esync divider so both cannot * be used. */ -switch (zl3073x_out_signal_format_get (out)) { -case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV : -case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV : +if (zl3073x_out_is_ndiv (out))return -EOPNOTSUPP ; -default : -break ; - }/* Get attached synth frequency */ synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (out)); synth_freq =zl3073x_synth_freq_get (synth); + out_freq = synth_freq / out->div; + +if (!pin->esync_control || out_freq <=1 ) +return -EOPNOTSUPP ; + + esync->range = esync_freq_ranges; + esync->range_num =ARRAY_SIZE (esync_freq_ranges); clock_type =FIELD_GET (ZL_OUTPUT_MODE_CLOCK_TYPE , out->mode);if (clock_type !=ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ) {
@@ -803,11 +800,11 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin, esync->freq =0 ; esync->pulse =0 ; - goto finish; +return 0 ; }/* Compute esync frequency */ - esync->freq = synth_freq / out->div / out->esync_n_period; + esync->freq = out_freq / out->esync_n_period;/* By comparing the esync_pulse_width to the half of the pulse width * the esync pulse percentage can be determined.
@@ -816,18 +813,6 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,*/ esync->pulse = (50 * out->esync_n_width) / out->div; -finish: -/* Set supported esync ranges if the pin supports esync control and -* if the output frequency is > 1 Hz. -*/ -if (pin->esync_control && (synth_freq / out->div) >1 ) { - esync->range = esync_freq_ranges; - esync->range_num =ARRAY_SIZE (esync_freq_ranges); - }else { - esync->range =NULL ; - esync->range_num =0 ; - } -return 0 ; }
@@ -853,13 +838,8 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,* for N-division is also used for the esync divider so both cannot * be used. */ -switch (zl3073x_out_signal_format_get (&out)) { -case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV : -case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV : +if (zl3073x_out_is_ndiv (&out))return -EOPNOTSUPP ; -default : -break ; - }/* Select clock type */ if (freq)
@@ -921,9 +901,9 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv;const struct zl3073x_synth *synth; -u8 out_id, signal_format;u32 new_div, synth_freq;struct zl3073x_out out; +u8 out_id; out_id =zl3073x_output_pin_out_get (pin->id); out = *zl3073x_out_state_get (zldev, out_id);
@@ -933,12 +913,8 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, synth_freq =zl3073x_synth_freq_get (synth); new_div = synth_freq / (u32 )frequency; -/* Get used signal format for the given output */ - signal_format =zl3073x_out_signal_format_get (&out); -/* Check signal format */ -if (signal_format !=ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV && - signal_format !=ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV ) { +if (!zl3073x_out_is_ndiv (&out)) {/* For non N-divided signal formats the frequency is computed * as division of synth frequency and output divisor. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1705/2151 dpll: zl3073x: reject inexact frequencies for N-divided outputs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit f8993627d3101de0833022ac88083ac0147aae7d ]
For N-divided outputs the P-pin and N-pin share the output divisor and the N-pin frequency is synth_freq / (div * esync_n_period). The frequency set helper computed esync_n_period with a truncating division and only rejected a zero result, so a frequency that does not divide evenly was silently rounded. Setting the P-pin could then shift the N-pin frequency too (e.g. 600 MHz synth, div=60, period=10 gives P=10 MHz, N=1 MHz; setting P to 2.5 MHz moves N to 1.25 MHz). When setting the P-pin, the product esync_n_period * div used for the rescale was computed in 32 bits and could wrap, so a wrong N divider was stored for low N-pin frequencies.
Require esync_n_period >= 2 so the N-pin frequency stays below the P-pin one, reject a P-pin frequency for which the esync_n_period keeping the N-pin frequency does not fit into 32 bits, and check the division remainder and reject the request if it is not exact.
Found by code inspection, not triggered at runtime.
--- drivers/dpll/zl3073x/dpll.c | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-)
drivers/dpll/zl3073x/dpll.c +28 -18
@@ -903,6 +903,7 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,const struct zl3073x_synth *synth;u32 new_div, synth_freq;struct zl3073x_out out; +u64 n_period, rem;u8 out_id; out_id =zl3073x_output_pin_out_get (pin->id);
@@ -928,16 +929,11 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, }if (zl3073x_dpll_is_p_pin (pin)) { -/* We are going to change output frequency for P-pin but -* if the requested frequency is less than current N-pin -* frequency then indicate a failure as we are not able -* to compute N-pin divisor to keep its frequency unchanged. -* -* Update divisor for N-pin to keep N-pin frequency. +/* Keep the N-pin frequency: the new P-pin frequency has to be +* a multiple of it, at least twice as high. */ - out.esync_n_period = (out.esync_n_period * out.div) / new_div; -if (!out.esync_n_period) -return -EINVAL ; + n_period =mul_u32_u32 (out.esync_n_period, out.div); + n_period =div64_u64_rem (n_period, new_div, &rem);/* Update the output divisor */ out.div = new_div;
@@ -945,17 +941,31 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,/* For 50/50 duty cycle the divisor is equal to width */ out.width = out.div; }else { -/* We are going to change frequency of N-pin but if -* the requested freq is greater or equal than freq of P-pin -* in the output pair we cannot compute divisor for the N-pin. -* In this case indicate a failure. -* -* Update divisor for N-pin +/* The N-pin frequency has to divide the P-pin frequency and +* be at most half of it. */ - out.esync_n_period =div64_u64 (synth_freq, frequency * out.div); -if (!out.esync_n_period) -return -EINVAL ; + n_period = frequency * out.div; + n_period =div64_u64_rem (synth_freq, n_period, &rem); + } +if (n_period <2 ) { +NL_SET_ERR_MSG_FMT (extack, +"OUT%uN freq must be at most half of OUT%uP freq" , + out_id, out_id); +return -EINVAL ; + } +if (n_period >U32_MAX ) { +NL_SET_ERR_MSG_FMT (extack, +"OUT%uN freq is too low for OUT%uP freq" , + out_id, out_id); +return -EINVAL ; + } +if (rem !=0 ) { +NL_SET_ERR_MSG_FMT (extack, +"OUT%uN freq must divide OUT%uP freq" , + out_id, out_id); +return -EINVAL ; } + out.esync_n_period = n_period;/* For 50/50 duty cycle the divisor is equal to width */ out.esync_n_width = out.esync_n_period;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1706/2151 dpll: zl3073x: reject output frequencies with too small divisor
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 456027325c9cd2be94229687f2c412ae6f351bd8 ]
The output divisor has to be at least 2: a divisor of 1 bypasses the divider and the hardware then ignores the pulse width and eSync registers. For the N-pin of an N-divided output the N divider (>= 2) applies on top, so its effective divisor has to be at least 4.
zl3073x_pin_check_freq() only checked that the frequency divides the synth frequency. Require also the minimum divisor. For N-divided outputs this is necessary but not sufficient, the rest is checked by the frequency set callback.
Hit during development: an N-pin frequency that needs an N divider of 1 was accepted, and with esync_n_period = 1 the N-pin produced no output on an oscilloscope.
--- drivers/dpll/zl3073x/prop.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/dpll/zl3073x/prop.c +27 -6
@@ -22,7 +22,8 @@* The function checks the given frequency is valid for the device. For input * pins it checks that the frequency can be factorized using supported base * frequencies. For output pins it checks that the frequency divides connected -* synth frequency without remainder. +* synth frequency without remainder and that the resulting divisor is not +* below the minimum the driver supports. * * Return: true if the frequency is valid, false if not. */
@@ -41,18 +42,38 @@ zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir,if (rc) goto err_inv_freq; }else { -u32 synth_freq; -u8 out, synth; +u32 synth_freq, div, min_div, rem; +const struct zl3073x_out *out; +u8 out_id, synth;/* Get output pin synthesizer */ - out =zl3073x_output_pin_out_get (id); - synth =zl3073x_dev_out_synth_get (zldev, out); + out_id =zl3073x_output_pin_out_get (id); + synth =zl3073x_dev_out_synth_get (zldev, out_id);/* Get synth frequency */ synth_freq =zl3073x_dev_synth_freq_get (zldev, synth);/* Check the frequency divides synth frequency */ -if (synth_freq % (u32 )freq) + div =div_u64_rem (synth_freq, freq, &rem); +if (rem) + goto err_inv_freq; + +/* The driver requires an output divisor of at least 2 - +* below that the hardware bypasses the divider and ignores +* the pulse width and eSync registers the driver programs. +* For the N-pin of an N-divided output the effective divisor +* also includes the N divider (>= 2), so the minimum is 4. +* For N-divided outputs this is only a necessary condition - +* whether the frequency can be set also depends on the output +* divisor shared by both pins, which is checked when the +* frequency is set. +*/ + out =zl3073x_out_state_get (zldev, out_id); +if (zl3073x_out_is_ndiv (out) &&zl3073x_is_n_pin (id)) + min_div =4 ; +else + min_div =2 ; +if (div < min_div) goto err_inv_freq; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1707/2151 dpaa2-ptp: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit 86a30c4348497bcddcf2796258955bbaaf58c9a3 ]
Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP.
On an LX2160A board, linuxptp ts2phc arms the external timestamp channel of the 1588 timer with PTP_EXTTS_REQUEST2, gets -EOPNOTSUPP and exits, so the PHC cannot be disciplined from an external 1PPS.
ptp_qoriq_init() programs TMR_CTRL with ETEP1 and ETEP2 cleared, so the timer timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge.
This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c +1 -0
@@ -78,6 +78,7 @@ static const struct ptp_clock_info dpaa2_ptp_caps = { .n_per_out = 3, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1708/2151 net: enetc: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit 8e96c4d393168661704d850bcf818e46efb8ef24 ]
Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP.
The ENETC timer is the QorIQ 1588 timer, set up by ptp_qoriq_init(), which programs TMR_CTRL with ETEP1 and ETEP2 cleared, so it timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge.
This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp.
--- drivers/net/ethernet/freescale/enetc/enetc_ptp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/enetc/enetc_ptp.c +1 -0
@@ -16,6 +16,7 @@ static struct ptp_clock_info enetc_ptp_caps = { .n_per_out = 0, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1709/2151 ptp: qoriq: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit d347ab5cf809365e7b3749dc91d77e89e4b7ec3f ]
Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP, since the core always adds PTP_STRICT_FLAGS to it.
ptp_qoriq_init() programs TMR_CTRL with ETEP1 and ETEP2 cleared, so the timer timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge.
This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp.
--- drivers/ptp/ptp_qoriq.c | 1 + 1 file changed, 1 insertion(+)
drivers/ptp/ptp_qoriq.c +1 -0
@@ -355,6 +355,7 @@ static const struct ptp_clock_info ptp_qoriq_caps = { .n_per_out = 0, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1710/2151 gre: keep the UDP tunnel GSO type when completing GRO
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brad Fitzpatrick <[email protected]>
[ Upstream commit 718f364a20ecee4f25986789c25550cf4da73b4c ]
gre_gro_complete() assigns SKB_GSO_GRE to gso_type rather than OR-ing it in. When GRE is carried over UDP by FOU or GUE, udp_gro_complete() has already set SKB_GSO_UDP_TUNNEL{,_CSUM} before calling into the FOU or GUE gro_complete handler and then gre_gro_complete(), so that bit is lost.
That has broken forwarding of such packets since FOU gained GRO: if a host with a FOU or GUE socket on the tunnel's port merges transit packets and then forwards them out a device that can't segment them itself, udp4_ufo_fragment() finds neither tunnel bit and fails, and the packets are dropped. Since commit 3d010c8031e3 ("udp: do not accept non-tunnel GSO skbs landing in a tunnel"), local receive is broken too:udp_unexpected_gso() considers the merged skb, which reaches the encapsulation socket without either UDP tunnel bit, unexpected and hands it to udp_rcv_segment(). Segmenting fails, so the packet is freed and counted in UdpInErrors. Either way, only packets GRO didn't merge get through, so TCP over FOU or GUE GRE tunnels slows to about one segment per round trip whenever the receiving device has GRO enabled.
OR in SKB_GSO_GRE instead, as ipip_gro_complete() and sit_gro_complete() do for SKB_GSO_IPXIP4. For plain GRE, gso_type is still zero at this point unless the driver set it, so nothing changes there in the usual case.
The assignment dates to commit bf5a755f5e91 ("net-gre-gro: Add GRE support to the GRO stack"), but nothing set gso_type before it until FOU GRO came along, so the Fixes tag points there.
Tested under virtme-ng with bulk TCP over a GRE tunnel between two network namespaces joined by a veth, with GRO on the receiving veth and segmentation off on the sending one, so GRO sees wire-sized packets. 32 MiB took:
before after FOU over IPv4 26.0s, 9658 UDP errors 0.28s, 0 errors GUE over IPv4 26.1s, 9686 UDP errors 0.39s, 0 errors FOU over IPv6 26.4s, 9860 UDP errors 0.16s, 0 errors plain GRE 0.17s 0.15s
Forwarding the same FOU traffic through a third namespace with its own FOU socket on the port, GRO on its ingress and segmentation off on its egress, took 26.0s with 4826 egress drops before and 0.31s with none after. On v6.8, before 3d010c8031e3, local receive was fine but forwarding failed the same way (25.7s, 4764 drops).
With GRO off on the receiver, all took under 0.2s both before and after. The gre_gso.sh and fou_mcast_encap.sh selftests give the same results before and after.
--- net/ipv4/gre_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_offload.c +1 -1
@@ -242,7 +242,7 @@ static int gre_gro_complete(struct sk_buff *skb, int nhoff)__be16 type; skb->encapsulation =1 ; -skb_shinfo (skb)->gso_type =SKB_GSO_GRE ; +skb_shinfo (skb)->gso_type |=SKB_GSO_GRE ; type = greh->protocol;if (greh->flags &GRE_KEY )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1711/2151 bpf: Dont echo user-supplied map info fields back to userspace
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 458575e1f2ddea944d679fe778c92e370a9b61a4 ]
Commit ea2e6467ac36 ("bpf: Return hashes of maps in BPF_OBJ_GET_INFO_BY_FD") started copying struct bpf_map_info in from userspace in order to read the new hash and hash_size input fields. Before that, the kernel ignored the contents of the user buffer and returned a zeroed structure with only the output fields filled in.
Some output fields are only set for certain maps: btf_id, btf_key_type_id and btf_value_type_id when the map has BTF (and btf_vmlinux_id for struct_ops maps, ifindex, netns_dev and netns_ino when the map is offloaded). For all other maps, these fields now return whatever userspace passed in before.
This breaks userspace which reuses one bpf_map_info for several queries. Restore the original behavior by zeroing the structure and copying in only hash and hash_size from userspace before the output fields are filled in.
--- kernel/bpf/syscall.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +5 -1
@@ -5301,7 +5301,11 @@ static int bpf_map_get_info_by_fd(struct file *file, info_len =min_t (u32,sizeof (info), info_len);memset (&info,0 ,sizeof (info)); -if (copy_from_user (&info, uinfo, info_len)) + if (info_len >= offsetofend(struct bpf_map_info, hash) && +get_user (info.hash, &uinfo->hash)) +return -EFAULT ; + if (info_len >= offsetofend(struct bpf_map_info, hash_size) && +get_user (info.hash_size, &uinfo->hash_size))return -EFAULT ; info.type = map->map_type;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1712/2151 ALSA: jack: Protect the index scan against control removal
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit ba8c3d5fc27ac3f86962641dd3b6600906234bab ]
A control found during a jack-name index scan must remain alive until snd_ctl_find_id() finishes comparing its ID and count. However, get_available_index() calls it without holding card->controls_rwsem. With CONFIG_SND_CTL_FAST_LOOKUP enabled, the lookup loads a raw control pointer from ctl_hash and dereferences it in elem_id_matches() without any lock that excludes removal.
This can happen when a jack is created while a different jack owner on the same card removes an existing control with the same name and index. For example, probe and unbind of different HDA codecs can reach these paths on a shared card if their generated jack names match. The codec device locks do not serialize operations on different codecs. The unbind path can free the control during the index scan:
Codec A: probe Codec B: unbind
-------------- ---------------
get_available_index()
snd_ctl_find_id()
kctl = xa_load(...)
hda_codec_driver_remove()
snd_hda_codec_cleanup_for_unbind()
snd_hda_jack_tbl_clear()
snd_device_free()
__snd_device_free()
snd_jack_dev_free()
snd_ctl_remove()
snd_ctl_remove_locked()
__snd_ctl_remove()
snd_ctl_free_one()
kfree(kctl)
elem_id_matches(kctl, ...)
read freed id/count -> UAFHold controls_rwsem for read across the index scan so removal cannot free a control until the lookup has finished using it. Release the lock when get_available_index() returns, before the caller adds the new control under the write lock.
--- sound/core/ctljack.c | 1 + 1 file changed, 1 insertion(+)
sound/core/ctljack.c +1 -0
@@ -37,6 +37,7 @@ static int get_available_index(struct snd_card *card, const char *name) sid.iface =SNDRV_CTL_ELEM_IFACE_CARD ;strscpy (sid.name, name,sizeof (sid.name)); +guard (rwsem_read)(&card->controls_rwsem);while (snd_ctl_find_id (card, &sid)) { sid.index++;/* reset numid; otherwise snd_ctl_find_id() hits this again */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1713/2151 perf evsel: Mark the event as supported when retrying an open
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit cc956e0cd6a405fbc6ad3055cbbdb178562ef27d ]
Opening a group with perf record on a machine with perf_event_paranoid > 1 and no CAP_PERFMON fails the first perf_event_open() with EACCES, after which evsel__open_cpu() clears evsel->supported; evsel__fallback() then adds exclude_kernel and record__open() retries, and the retry succeeds with supported left false. get_group_fd() treats unsupported events as ungroupable, so the retry opens the group members without their leader:
sys_perf_event_open: pid 12345 cpu 0 group_fd -1 FAILED '.../test-record-group-sampling1' - group failure
which fails the group subtests of "perf test 82", the Perf attribute expectations test, when it is run as a regular user, while it passes as root or with CAP_PERFMON, where the first open doesn't fail.
commit 2cc7aa995ce9 ("perf stat: Refactor retry/skip/fatal error handling") dropped the pos->supported = true that record__open() did after a successful open and moved the resets into the stat code only, while saying "When an event is tried the supported is set to true again". Do that in evsel__open_cpu(), which every open entry point funnels through, so that a retry describes its own try instead of the previous failure.
--- tools/perf/util/evsel.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/evsel.c +6 -0
@@ -2665,6 +2665,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,enum rlimit_action set_rlimit =NO_CHANGE ;struct perf_cpu cpu; +/* +* A failed attempt being retried after evsel__fallback() would +* otherwise keep group members out of their group in get_group_fd(). +*/ + evsel->supported = true; +if (evsel__is_retire_lat (evsel)) { err =evsel__tpebs_open (evsel); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1714/2151 bpf: Fix verifier WARN on narrow read of bpf_tcp_sock u64 fields
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit af873495cbcb066ab029f7f63b94410d4db47628 ]
A BPF program can read the middle of a u64 field in struct bpf_tcp_sock:
tp = bpf_tcp_sock(listener); /* +0x54 is in the middle of the u64 bytes_received */ unsigned hi = *(unsigned *)((char *)tp + 0x54);
bpf_tcp_sock_is_valid_access() allows this 4-byte read (the default case only checks size == 4), but bpf_tcp_sock_convert_ctx_access() only knows the field starts and has no idea how to handle such an offset. It emits no instruction, cnt stays 0 and the fixup pass trips verifier_bug():
verifier bug: error during ctx access conversion (0)
Just disallow the narrower access by matching the whole u64 range of the two fields, so it is turned down at check time:
invalid tcp_sock access off=84 size=4
--- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
@@ -7302,8 +7302,8 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type,return false;switch (off) { -case offsetof(struct bpf_tcp_sock , bytes_received): -case offsetof(struct bpf_tcp_sock , bytes_acked): + case bpf_ctx_range(struct bpf_tcp_sock, bytes_received): + case bpf_ctx_range(struct bpf_tcp_sock, bytes_acked):return size ==sizeof (__u64);default :return size ==sizeof (__u32);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1715/2151 power: supply: qcom_battmgr: report the USB type from USB_ADAP_TYPE
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit a49f86cd1333c6e12fd37bc0b3234ace10072553 ]
On SM8350 and SM8550 class firmware the USB power supply reads its usb_type from the USB_TYPE property. On a Kaanapali (SM8850) tablet that property is 1 (SDP) whatever is plugged in, while USB_ADAP_TYPE reports the adapter, using the same numbering as POWER_SUPPLY_USB_TYPE_*:
PC port USB_TYPE 1 USB_ADAP_TYPE 1 (SDP) USB-C dock, 5 V PD USB_TYPE 1 USB_ADAP_TYPE 6 (PD) 65 W PPS charger USB_TYPE 1 USB_ADAP_TYPE 8 (PD_PPS)
Qualcomm's downstream qti_battery_charger driver also maps USB_ADAP_TYPE to POWER_SUPPLY_PROP_USB_TYPE.
Request USB_ADAP_TYPE for POWER_SUPPLY_PROP_USB_TYPE instead.
Tested on a Lenovo Legion Tab Y700 gen 5 (qcom,kaanapali-pmic-glink, which uses the SM8550 path). Only tested on this device; the SM8350 variant shares the property map and was not tested.
--- drivers/power/supply/qcom_battmgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/qcom_battmgr.c +2 -2
@@ -980,7 +980,7 @@ static const u8 sm8350_usb_prop_map[] = { [POWER_SUPPLY_PROP_CURRENT_NOW] = USB_CURR_NOW, [POWER_SUPPLY_PROP_CURRENT_MAX] = USB_CURR_MAX, [POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT] = USB_INPUT_CURR_LIMIT, - [POWER_SUPPLY_PROP_USB_TYPE] = USB_TYPE, + [POWER_SUPPLY_PROP_USB_TYPE] = USB_ADAP_TYPE, }; static int qcom_battmgr_usb_sm8350_update(struct qcom_battmgr *battmgr,
@@ -1538,7 +1538,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr,case USB_INPUT_CURR_LIMIT : battmgr->usb.current_limit =le32_to_cpu (resp->intval.value);break ; -case USB_TYPE : +case USB_ADAP_TYPE : battmgr->usb.usb_type =le32_to_cpu (resp->intval.value);break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1716/2151 bpf: Use the frame mem type in devmap egress XDP
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit b3ca872947ef322c475ceaa7a76a9ebb3356152e ]
A devmap egress program that removes a whole fragment of a redirected xdp_frame with bpf_xdp_adjust_tail() or bpf_xdp_pull_data() frees it with page_frag_free() whatever the frame's memory type is. For a MEM_TYPE_PAGE_POOL frame from a page_pool based driver this drops the page reference owned by the pool while the pool still accounts the fragment ("page_pool leak" bad page, leaked pp reference).
kernel/bpf/devmap.c:dev_map_bpf_prog_run() points xdp.rxq at an on-stack
struct xdp_rxq_info rxq = { .dev = rx_dev };whose mem.type is 0, i.e. MEM_TYPE_PAGE_SHARED, and net/core/filter.c:bpf_xdp_shrink_data() releases frags according to rxq->mem.type. cpumap, which runs programs on xdp_frames the same way, already copies xdpf->mem_type into its private rxq for each frame.
With 9000 byte frames from virtio_net and an egress program that cuts the fragments off:
BUG: Bad page state in process swapper/3 pfn:10660b page dumped because: page_pool leak bad_page+0xbd/0x190 __free_frozen_pages+0x5c7/0x900 bpf_xdp_adjust_tail+0x3be/0x480 bpf_prog_dad43f894a3faff7_egress+0x15c/0x1cd dev_map_bpf_prog_run+0x288/0x610
The pool waits for these pages for ever when its device is gone. That is the harmless case. A page of the pool can hold more than one fragment while its refcount is 1: the first page_frag_free() frees it under the fragment which is still in use, and the second one runs into
page dumped because: VM_BUG_ON_PAGE(page_ref_count(page) == 0) kernel BUG at include/linux/mm.h:1846!
veth is not affected. It takes references of its own on the pages and redirects the frame as MEM_TYPE_PAGE_SHARED.
Fix by setting rxq.mem.type from each frame before running the devmap program, as cpu_map_bpf_prog_run_xdp() does.
--- kernel/bpf/devmap.c | 1 + 1 file changed, 1 insertion(+)
kernel/bpf/devmap.c +1 -0
@@ -350,6 +350,7 @@ static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog,xdp_convert_frame_to_buff (xdpf, &xdp); xdp.txq = &txq; + rxq.mem.type = xdpf->mem_type; xdp.rxq = &rxq; act =bpf_prog_run_xdp (xdp_prog, &xdp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1717/2151 bpf: Reject sleepable programs for task_vma iterator
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit dfcd1765911223df60845e288ad392d5237f47a3 ]
A sleepable "iter.s/task_vma" program can be attached, but its ->show() callback runs with the mmap_lock of the iterated mm held for read. As soon as the program runs, bpf_iter_run_prog() calls might_fault(), and any bpf_copy_from_user() or bpf_copy_from_user_task() it does may really fault or take mmap_lock again. With lockdep this is reported as recursive locking of mmap_lock. Without lockdep, a fault on the reader's own mm, or access_process_vm() on the iterated mm, has to take mmap_lock for read again. If a writer queued up in the meantime that blocks behind the writer, which in turn waits for the read lock the iterator already holds, and the read() hangs:
reader (iter.s/task_vma) other thread of the same mm
task_vma_seq_get_next()
mmap_read_lock(mm)
mmap_write_lock(mm) <- waits
bpf prog: copy_from_user()
page fault
mmap_read_lock(mm) <- queued behind the writer
The reader waits killable, so the hang lasts until it gets a fatal signal.
bpf_iter_link_attach() allows sleepable programs for the targets that set BPF_ITER_RESCHED, and task_vma sets it because cond_resched() between VMAs is fine with mmap_lock held. Rescheduling between objects and running a sleepable program inside ->show() are different properties, though, and task_vma only has the first one. The open-coded task_vma iterator does not have this problem since it hands out a snapshot of the VMA and holds no lock when it returns to the program.
The vma handed to the program is only stable under mmap_lock, so the lock can't be dropped around ->show(). Add a feature flag BPF_ITER_NOSLEEP for targets which can't run sleepable programs although they can reschedule, and set it for task_vma.
The check at attach time is not enough. BPF_LINK_UPDATE replaces the program of a link, and bpf_iter_link_replace() only compares the type, the attach type and the BTF id of the two programs, which are the same for a sleepable and a non-sleepable one. Do the check there as well. That also closes this way around the existing rule: so far a sleepable program could be put on a link of a target that doesn't set BPF_ITER_RESCHED, like the hash map element iterator, which runs it under rcu_read_lock().
BPF_LINK_CREATE of a sleepable program for the task_vma target, and BPF_LINK_UPDATE to one, now fail with -EINVAL, also for programs that don't touch user memory and have been working since sleepable iterator programs exist. The programs can still be loaded. They have to be loaded as non-sleepable programs, or use the open-coded iterator.
--- include/linux/bpf.h | 3 ++- kernel/bpf/bpf_iter.c | 17 ++++++++++++++--- kernel/bpf/task_iter.c | 6 +++++- 3 files changed, 21 insertions(+), 5 deletions(-)
include/linux/bpf.h +2 -1
@@ -2665,7 +2665,8 @@ typedef const struct bpf_func_proto * const struct bpf_prog *prog);enum bpf_iter_feature { -BPF_ITER_RESCHED =BIT (0 ), +BPF_ITER_RESCHED =BIT (0 ),/* may cond_resched() between objects */ +BPF_ITER_NOSLEEP =BIT (1 ),/* ->show() can't run sleepable progs */ };#define BPF_ITER_CTX_ARG_MAX 2
kernel/bpf/bpf_iter.c +14 -3
@@ -72,6 +72,15 @@ static inline bool bpf_iter_target_support_resched(const struct bpf_iter_target_return tinfo->reg_info->feature &BPF_ITER_RESCHED ; } +/* Only allow sleepable program for resched-able iterator that can run one */ +static bool bpf_iter_target_support_prog (const struct bpf_iter_target_info *tinfo, +const struct bpf_prog *prog) +{ +return !prog->sleepable || + (bpf_iter_target_support_resched (tinfo) && + !(tinfo->reg_info->feature &BPF_ITER_NOSLEEP )); +} +static bool bpf_iter_support_resched (struct seq_file *seq) {struct bpf_iter_priv_data *iter_priv;
@@ -409,6 +418,8 @@ static int bpf_iter_link_replace(struct bpf_link *link,struct bpf_prog *new_prog, struct bpf_prog *old_prog) { + struct bpf_iter_link *iter_link = + container_of(link, struct bpf_iter_link, link);int ret =0 ;mutex_lock (&link_mutex);
@@ -419,7 +430,8 @@ static int bpf_iter_link_replace(struct bpf_link *link,if (link->prog->type != new_prog->type || link->prog->expected_attach_type != new_prog->expected_attach_type || - link->prog->aux->attach_btf_id != new_prog->aux->attach_btf_id) { + link->prog->aux->attach_btf_id != new_prog->aux->attach_btf_id || + !bpf_iter_target_support_prog (iter_link->tinfo, new_prog)) { ret = -EINVAL ; goto out_unlock; }
@@ -544,8 +556,7 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,if (!tinfo)return -ENOENT ; -/* Only allow sleepable program for resched-able iterator */ -if (prog->sleepable && !bpf_iter_target_support_resched (tinfo)) +if (!bpf_iter_target_support_prog (tinfo, prog))return -EINVAL ; link =kzalloc (sizeof (*link),GFP_USER | __GFP_NOWARN);
kernel/bpf/task_iter.c +5 -1
@@ -737,7 +737,11 @@ static const struct bpf_iter_seq_info task_vma_seq_info = {static struct bpf_iter_reg task_vma_reg_info = { .target ="task_vma" , .attach_target = bpf_iter_attach_task, - .feature =BPF_ITER_RESCHED , +/* +* ->show() runs with the mmap_lock of the iterated mm held, which a +* sleepable program takes again when it faults on user memory. +*/ + .feature =BPF_ITER_RESCHED |BPF_ITER_NOSLEEP , .ctx_arg_info_size =2 , .ctx_arg_info = { { offsetof(struct bpf_iter__task_vma , task),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1718/2151 bpf: Look at all 64 bits of a BPF_JSET mask on 32-bit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ee4f44e0e3c8125eebe9ac967b6984bc9253d489 ]
In the branch of a BPF_JSET which is taken, the verifier can learn something about the register only if the mask has a single bit: then this bit is set. regs_refine_cond_op() tests this with is_power_of_2(val) and then ORs val into var_off.
val is a u64, but is_power_of_2() takes an unsigned long. On a 32-bit kernel it only sees the lower half of the mask. For
if r1 & 0xffffffff80000000 goto l
which is a BPF_JSET | BPF_K with an immediate of 0x80000000, the lower half is a power of two. So the verifier takes all 33 bits for set at l, while the branch is taken if any of them is. A mask of 0x100000001 from a register does the same for bit 0.
The log of an i386 kernel, for r6 = bpf_get_prandom_u32() << 31:
3: (45) if r6 & 0x80000000 goto pc+2 from 3 to 6: R6=0xffffffff80000000 R10=fp0 6: (77) r6 >>= 63 ; R6=1
When the program runs, r6 >> 63 is 0.
Quoted 1 line
From then on the verifier works with known bits which the register does
not have at run time. It accepts, for example, an offset into a map value which it derives from these bits and believes to be constant, and the program can access memory outside of the map value.
Count the bits of the whole value.
Only 32-bit kernels are affected. On a 64-bit kernel unsigned long holds the whole mask, and this patch changes nothing.
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -16857,7 +16857,7 @@ static void regs_refine_cond_op(struct bpf_reg_state *reg1, struct bpf_reg_state* this restriction. I.e., !(r1 & 0x3) means neither bit 0 nor * bit 1 is set, which we can readily use in adjustments. */ -if (!is_power_of_2 (val)) +if (hweight64 (val) !=1 )break ;if (is_jmp32) { t =tnum_or (tnum_subreg (reg1->var_off),tnum_const (val));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1719/2151 net: Helper to move packet data and metadata after skb_push/pull
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Sitnicki <[email protected]>
[ Upstream commit 8989d328dfe7c7a3b9f4b9f0ef60006d277f81cc ]
Lay groundwork for fixing BPF helpers available to TC(X) programs.
When skb_push() or skb_pull() is called in a TC(X) ingress BPF program, the skb metadata must be kept in front of the MAC header. Otherwise, BPF programs using the __sk_buff->data_meta pseudo-pointer lose access to it.
Introduce a helper that moves both metadata and a specified number of packet data bytes together, suitable as a drop-in replacement for memmove().
Stable-dep-of: 12d07c38e1b0 ("bpf: Don't let bpf_skb_adjust_room() use up the MSS")
--- include/linux/skbuff.h | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
include/linux/skbuff.h +75 -0
@@ -4593,6 +4593,81 @@ static inline void skb_metadata_clear(struct sk_buff *skb)skb_metadata_set (skb,0 ); } +/** +* skb_data_move - Move packet data and metadata after skb_push() or skb_pull(). +* @skb: packet to operate on +* @len: number of bytes pushed or pulled from &sk_buff->data +* @n: number of bytes to memmove() from pre-push/pull &sk_buff->data +* +* Moves @n bytes of packet data, can be zero, and all bytes of skb metadata. +* +* Assumes metadata is located immediately before &sk_buff->data prior to the +* push/pull, and that sufficient headroom exists to hold it after an +* skb_push(). Otherwise, metadata is cleared and a one-time warning is issued. +* +* Prefer skb_postpull_data_move() or skb_postpush_data_move() to calling this +* helper directly. +*/ +static inline void skb_data_move (struct sk_buff *skb,const int len, +const unsigned int n) +{ +const u8 meta_len =skb_metadata_len (skb); +u8 *meta, *meta_end; + +if (!len || (!n && !meta_len)) +return ; + +if (!meta_len) + goto no_metadata; + + meta_end =skb_metadata_end (skb); + meta = meta_end - meta_len; + +if (WARN_ON_ONCE (meta_end + len != skb->data || + meta_len >skb_headroom (skb))) { +skb_metadata_clear (skb); + goto no_metadata; + } + +memmove (meta + len, meta, meta_len + n); +return ; + +no_metadata: +memmove (skb->data, skb->data - len, n); +} + +/** +* skb_postpull_data_move - Move packet data and metadata after skb_pull(). +* @skb: packet to operate on +* @len: number of bytes pulled from &sk_buff->data +* @n: number of bytes to memmove() from pre-pull &sk_buff->data +* +* See skb_data_move() for details. +*/ +static inline void skb_postpull_data_move (struct sk_buff *skb, +const unsigned int len, +const unsigned int n) +{ +DEBUG_NET_WARN_ON_ONCE (len >INT_MAX ); +skb_data_move (skb, len, n); +} + +/** +* skb_postpush_data_move - Move packet data and metadata after skb_push(). +* @skb: packet to operate on +* @len: number of bytes pushed onto &sk_buff->data +* @n: number of bytes to memmove() from pre-push &sk_buff->data +* +* See skb_data_move() for details. +*/ +static inline void skb_postpush_data_move (struct sk_buff *skb, +const unsigned int len, +const unsigned int n) +{ +DEBUG_NET_WARN_ON_ONCE (len >INT_MAX ); +skb_data_move (skb, -len, n); +} +struct sk_buff *skb_clone_sk (struct sk_buff *skb);#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1720/2151 bpf: Make bpf_skb_adjust_room metadata-safe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Sitnicki <[email protected]>
[ Upstream commit be83105d38ab99737ac0488600efd59ddd57b74c ]
bpf_skb_adjust_room() may push or pull bytes from skb->data. In both cases, skb metadata must be moved accordingly to stay accessible.
Replace existing memmove() calls, which only move payload, with a helper that also handles metadata. Reserve enough space for metadata to fit after skb_push.
Stable-dep-of: 12d07c38e1b0 ("bpf: Don't let bpf_skb_adjust_room() use up the MSS")
--- net/core/filter.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/core/filter.c +5 -4
@@ -3311,11 +3311,11 @@ static void bpf_skb_change_protocol(struct sk_buff *skb, u16 proto)static int bpf_skb_generic_push (struct sk_buff *skb,u32 off,u32 len) { -/* Caller already did skb_cow() with len as headroom, +/* Caller already did skb_cow() with meta_len+len as headroom, * so no need to do it here. */ skb_push (skb, len); -memmove (skb->data, skb->data + len, off); +skb_postpush_data_move (skb, len, off);memset (skb->data + off,0 , len);/* No skb_postpush_rcsum(skb, skb->data + off, len)
@@ -3339,7 +3339,7 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len) old_data = skb->data;__skb_pull (skb, len);skb_postpull_rcsum (skb, old_data + off, len); -memmove (skb->data, old_data, off); +skb_postpull_data_move (skb, len, off);return 0 ; }
@@ -3549,6 +3549,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,u8 inner_mac_len = flags >>BPF_ADJ_ROOM_ENCAP_L2_SHIFT ;bool encap = flags &BPF_F_ADJ_ROOM_ENCAP_L3_MASK ;u16 mac_len =0 , inner_net =0 , inner_trans =0 ; +const u8 meta_len =skb_metadata_len (skb);unsigned int gso_type =SKB_GSO_DODGY ;int ret;
@@ -3559,7 +3560,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,return -ENOTSUPP ; } - ret =skb_cow_head (skb, len_diff); + ret =skb_cow_head (skb, meta_len + len_diff);if (unlikely (ret <0 ))return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1721/2151 bpf: Dont let bpf_skb_adjust_room() use up the MSS
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 12d07c38e1b0f79e48a37abd7103194212f2da8c ]
When bpf_skb_adjust_room() grows a TCP GSO packet without BPF_F_ADJ_ROOM_FIXED_GSO, gso_size is lowered by the number of bytes added. Nothing looks at how large it is.
gso_size is the size of the segments the peer has sent if the packet comes out of GRO, and what the sender has written into the virtio header if it comes from a tun device or a packet socket. If it equals len_diff the result is 0, and a packet of up to 64 KB is no GSO packet any more. If it is smaller, the 16 bit value wraps around.
One less than len_diff gives GSO_BY_FRAGS. skb_segment() then takes the length of each segment from the frag_list. A packet with more than 64 KB of payload gets that far, and one from a tun device has no frag_list:
BUG: KASAN: null-ptr-deref in skb_segment+0xcf1/0x1a90 BUG: kernel NULL pointer dereference, address: 0000000000000070 tcp_gso_segment+0x1be/0x9f0 inet_gso_segment+0x288/0x740 inet_gso_segment+0x288/0x740 skb_mac_gso_segment+0x179/0x2e0
What is left must not be less than TCP_MIN_GSO_SIZE either. The stack relies on that for the number of segments to fit into gso_segs, see commit c27c449d455a ("virtio-net: Ensure that TCP packets don't overflow gso_segs").
Refuse to grow a packet that would end up with less, with the error that other packets which cannot be adjusted get.
--- net/core/filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/filter.c +8 -0
@@ -3560,6 +3560,14 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,return -ENOTSUPP ; } +/* +* The MSS is lowered by len_diff. Leave the least that the stack lets a +* TCP GSO packet have, or gso_segs can overflow. +*/ +if (skb_is_gso (skb) && !(flags &BPF_F_ADJ_ROOM_FIXED_GSO ) && +skb_shinfo (skb)->gso_size < len_diff +TCP_MIN_GSO_SIZE ) +return -ENOTSUPP ; + ret =skb_cow_head (skb, meta_len + len_diff);if (unlikely (ret <0 ))return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1722/2151 bpf: Read the probe of a perf event under event_mutex
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3ccd700543f16a2b2ab656f35dcaeb6bd7c45e22 ]
For a perf event on a kprobe or uprobe event which was made in tracefs, bpf_get_kprobe_info() and bpf_get_uprobe_info() look the probe up by name in the list of dynamic events, and hand a pointer to its symbol or file name back to the caller. None of the callers holds event_mutex.
The perf event keeps its trace event alive, nothing else. Other dynamic events are removed from the list and freed during the walk. And a probe which shares its event with other probes can be deleted while the event is in use, so even the probe which is found can be freed, together with the string, before the caller has measured and copied it. The result is a use-after-free in the walk, in strlen() and in the copy to user space, or a NULL pointer dereference.
The readers are BPF_OBJ_GET_INFO_BY_FD and fdinfo of a perf link, for whoever holds a descriptor of the link, and BPF_TASK_FD_QUERY. The other side is anybody who may write to dynamic_events, kprobe_events or uprobe_events.
Take event_mutex in bpf_get_perf_event_info() and give the caller a copy of the name, which it has to free.
--- kernel/bpf/syscall.c | 17 +++++++++++------ kernel/trace/bpf_trace.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-)
kernel/bpf/syscall.c +11 -6
@@ -3909,19 +3909,19 @@ static int bpf_perf_link_fill_common(const struct perf_event *event, *ulenp =1 ; }if (!uname) -return 0 ; + goto out;if (buf) { err =bpf_copy_to_user (uname, buf, ulen, len); -if (err) -return err; }else {char zero ='\0' ;if (put_user (zero, uname)) -return -EFAULT ; + err = -EFAULT ; } -return 0 ; +out: +kfree_const (buf); +return err; }#ifdef CONFIG_KPROBE_EVENTS
@@ -3978,6 +3978,7 @@ static void bpf_perf_link_fdinfo_kprobe(const struct perf_event *event, name, offset, missed, addr, type ==BPF_FD_TYPE_KRETPROBE ?"kretprobe" :"kprobe" , event->bpf_cookie); + kfree_const(name); }#endif
@@ -4031,6 +4032,7 @@ static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event, name, offset, ref_ctr_offset, type ==BPF_FD_TYPE_URETPROBE ?"uretprobe" :"uprobe" , event->bpf_cookie); + kfree_const(name); }#endif
@@ -4129,6 +4131,7 @@ static void bpf_tracepoint_link_show_fdinfo(const struct perf_event *event,"event_type:\t%s\n" "cookie:\t%llu\n" , name, "tracepoint", event->bpf_cookie); +kfree_const (name); } static void bpf_probe_link_show_fdinfo(const struct perf_event *event,
@@ -5623,11 +5626,13 @@ static int bpf_task_fd_query(const union bpf_attr *attr, err =bpf_get_perf_event_info (event, &prog_id, &fd_type, &buf, &probe_offset, &probe_addr,NULL ); -if (!err) +if (!err) { err =bpf_task_fd_query_copy (attr, uattr, prog_id, fd_type, buf, probe_offset, probe_addr); +kfree_const (buf); + } goto put_file; }
kernel/trace/bpf_trace.c +13 -0
@@ -2151,6 +2151,7 @@ int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_raw_tp_link *return tracepoint_probe_unregister (btp->tp, (void *)btp->bpf_func, link); } +/* On success the caller releases *buf with kfree_const() */ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id, u32 *fd_type, const char **buf, u64 *probe_offset, u64 *probe_addr,
@@ -2160,6 +2161,12 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,struct bpf_prog *prog;int flags, err =0 ; +/* +* The list of dynamic events is walked, and a probe which has siblings +* can be deleted, with its strings, while its event is in use. +*/ +guard (mutex)(&event_mutex); + prog = event->prog;if (!prog)return -ENOENT ;
@@ -2200,6 +2207,12 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,#endif } +if (!err && *buf) { + *buf =kstrdup_const (*buf,GFP_KERNEL ); +if (!*buf) + err = -ENOMEM ; + } +return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1723/2151 bpf: Validate the SRH which End.DT6 uncovers in End.BPF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit e8b084646b946cc6f7976365588035947a296184 ]
input_action_end_bpf() validates the SRH of a packet and pulls it into the head before the program runs. If the program decapsulates the packet with bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6), bpf_update_srh_state() looks for a routing header in the inner packet and takes it for the new SRH as it is.
Nobody has looked at that header, and whoever has sent the packet has written it. ipv6_find_hdr() finds it in a fragment of the skb as well, but hdrlen is then read at that offset from skb->data, past the end of the head. The header need not be an SRH, and its hdrlen need not fit into the packet, but it is marked as valid, and bpf_lwt_seg6_adjust_srh() and bpf_lwt_seg6_store_bytes() check their offsets against it.
A program which then adds a TLV at the end of the SRH, where hdrlen has it, makes bpf_lwt_seg6_adjust_srh() move and write memory behind the head of the skb, as far as the sender likes within the 2 KB that hdrlen can say:
BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x185/0x240 Read of size 2088 at addr ffff888107d6f09e by task srh/102 BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x1b5/0x240 Write of size 8 at addr ffff888107d6f8be by task srh/102
Use seg6_get_srh(), which pulls and validates the header. Without a valid SRH the state says that there is none, and the packet goes its way as before. The pull can move the head, so compute the data pointers behind it.
--- net/core/filter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/core/filter.c +5 -5
@@ -6716,15 +6716,15 @@ static void bpf_update_srh_state(struct sk_buff *skb) {struct seg6_bpf_srh_state *srh_state =this_cpu_ptr (&seg6_bpf_srh_states); -int srhoff =0 ; -if (ipv6_find_hdr (skb, &srhoff,IPPROTO_ROUTING ,NULL ,NULL ) <0 ) { - srh_state->srh =NULL ; - }else { - srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); +/* Behind a decapsulation this is a header that nobody has looked at */ + srh_state->srh =seg6_get_srh (skb,0 ); +if (srh_state->srh) { srh_state->hdrlen = srh_state->srh->hdrlen <<3 ; srh_state->valid = true; } +/* it may have been pulled into the head */ +bpf_compute_data_pointers (skb); } BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1724/2151 bpf: Pull the inner header for End.DT6 in End.BPF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 434324c611a98bc76dc850d45d67756dae5622cf ]
bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6) pulls the outer headers off the packet and hands it to seg6_lookup_nexthop(), which reads the inner IPv6 header at skb->data. Nothing says that this header is in the head of the skb, or that there is one. If the head ends with the outer headers, the route is looked up for whatever lies behind the head, and the packet is dropped or leaves by the wrong route. If the program then pushes an SRH with SEG6_LOCAL_ACTION_END_B6, seg6_do_srh_inline() pulls an IPv6 header off a head which has none, and __skb_pull() hits its BUG(): the kernel panics on a packet from the network.
GRO pulls the inner header of a plain IPv6 in IPv6 packet into the head. It takes a packet which GRO does not look into that far, one with a fragment header in front of the inner header for example, or a device without GRO, and a driver which leaves the inner header in a fragment.
Make sure of the inner header together with the outer ones. The program goes on behind an error of the helper, so do it before the packet is changed. A pull which fails can still have moved the head, so look for the SRH again.
--- net/core/filter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/core/filter.c +6 -1
@@ -6757,9 +6757,14 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,if (ipv6_find_hdr (skb, &hdroff,IPPROTO_IPV6 ,NULL ,NULL ) <0 )return -EBADMSG ; -if (!pskb_pull (skb, hdroff)) +/* As long as nothing has been changed, the program goes on */ +if (!pskb_may_pull (skb, hdroff +sizeof (struct ipv6hdr ))) { +/* but the head may have moved */ +bpf_update_srh_state (skb);return -EBADMSG ; + } +__skb_pull (skb, hdroff);skb_postpull_rcsum (skb,skb_network_header (skb), hdroff);skb_reset_network_header (skb);skb_reset_transport_header (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1725/2151 bpf: Update the SRH state if End.B6 fails late
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 427e751a231aa781441d51c42e716905ee348099 ]
For SEG6_LOCAL_ACTION_END_B6 and END_B6_ENCAP bpf_lwt_seg6_action() looks for the SRH again only if bpf_push_seg6_encap() has succeeded. That function pushes the new header, for which the head of the skb is reallocated if it has not got the room, and then looks up the route to the first segment. If there is none, it returns an error, and the pointer to the SRH in seg6_bpf_srh_states still points into the old head, which has been freed.
The program goes on behind the error. bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_adjust_srh() read the SRH through that pointer.
Look for the SRH whatever bpf_push_seg6_encap() says.
--- net/core/filter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/filter.c +4 -4
@@ -6778,8 +6778,8 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,return -EBADMSG ; err =bpf_push_seg6_encap (skb,BPF_LWT_ENCAP_SEG6_INLINE , param, param_len); -if (!err) -bpf_update_srh_state (skb); +/* The header can be in place although err says otherwise */ +bpf_update_srh_state (skb);return err;case SEG6_LOCAL_ACTION_END_B6_ENCAP :
@@ -6787,8 +6787,8 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,return -EBADMSG ; err =bpf_push_seg6_encap (skb,BPF_LWT_ENCAP_SEG6 , param, param_len); -if (!err) -bpf_update_srh_state (skb); +/* The header can be in place although err says otherwise */ +bpf_update_srh_state (skb);return err;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1726/2151 bpf: Clear sk_refcnt of a clone before its storage is linked
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 22f100bd013458836c3d0eaf8050b854d7534a66 ]
sk_clone() sets sk_refcnt of the new socket some lines behind bpf_sk_storage_clone(). But the elements which that function copies are linked to their maps at once, and an element leads to its owner: the iterator over a sk_storage map hands the owner to its program. bpf_sk_storage_get() with BPF_SK_STORAGE_GET_F_CREATE and bpf_sk_storage_delete() rely on refcount_inc_not_zero() to tell whether they may touch the socket.
sk_refcnt is in the part of struct sock which sock_copy() leaves out, and sk_prot_alloc() does not clear a clone unless init_on_alloc is on. It is zero in an object which has been a socket before, and anything in one which has not. If it is not zero, a helper gets a reference which refcount_set() wipes out, and the helper's sock_put() then drops one of the two references of the new socket, which is freed too early:
IPv4: Attempt to release TCP socket in state 1
BUG: KASAN: slab-use-after-free in __raw_spin_lock_init+0x47/0x90
In the meantime the helper changes a storage which bpf_sk_storage_clone() fills without taking its lock.
Nothing else can find the clone at this point. Say that it is not alive yet, before the first element is linked. Sockets whose parent has no storage are left alone.
--- net/core/bpf_sk_storage.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/bpf_sk_storage.c +7 -0
@@ -163,6 +163,13 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)if (!sk_storage ||hlist_empty (&sk_storage->list)) goto out; +/* +* The maps lead to newsk as soon as an element is linked, but +* sk_clone() sets sk_refcnt only later. Until then it holds whatever +* the slab object held before: no reference can be had yet. +*/ +refcount_set (&newsk->sk_refcnt,0 ); +hlist_for_each_entry_rcu (selem, &sk_storage->list, snode) {struct bpf_local_storage_elem *copy_selem;struct bpf_local_storage_map *smap;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1727/2151 bpf: Bound the nesting that the BTF show code follows
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 13ac7c05bc45d3445b580da186548dd3487fae4e ]
btf_struct_show() and btf_array_show() recurse for every nested struct and array. MAX_RESOLVE_DEPTH bounds one resolve walk when BTF is loaded, not the nesting: a member whose type is resolved already is not walked again, so BTF that defines its types from the inside out can nest them as deep as it has types.
Whoever may load BTF, with CAP_BPF or a BPF token, can give such a type to the value of a map. Reading the file of that map in bpffs then overruns the kernel stack: with a few hundred levels the stack guard page is hit and the kernel panics.
Stop at 32 levels. That is MAX_RESOLVE_DEPTH, and __btf_show_indent() has as many columns. Nothing is shown for a member that lies deeper, and the status becomes -E2BIG, which bpf_snprintf_btf() and bpf_seq_printf_btf() return. The types of an x86_64 defconfig kernel nest 14 deep.
--- kernel/bpf/btf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/bpf/btf.c +13 -1
@@ -953,6 +953,8 @@ static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, }#define BTF_SHOW_MAX_ITER 10 +/* nested structs and arrays shown; __btf_show_indent() has as many columns */ +#define BTF_SHOW_MAX_DEPTH 32#define BTF_KIND_BIT (kind) (1ULL << kind)
@@ -1346,8 +1348,18 @@ static void *btf_show_start_aggr_type(struct btf_show *show,const struct btf_type *t, u32 type_id, void *data) { - void *safe_data = btf_show_start_type(show, t, type_id, data); + void *safe_data; +/* +* Structs and arrays are shown by recursion. BTF loading bounds the +* depth of one resolve walk, not how deep resolved types may nest. +*/ +if (show->state.depth >=BTF_SHOW_MAX_DEPTH ) { + show->state.status = -E2BIG ; +return NULL ; + } + + safe_data =btf_show_start_type (show, t, type_id, data);if (!safe_data)return safe_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1728/2151 bpf: Fix stale offload->prog pointer after realloc
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 8e83d53596445fcf5b0385e5fbe8bcd971e06d06 ]
bpf_prog_realloc() moves a program that the rewrites of the verifier make outgrow its pages. It updates aux->prog, but not the offload->prog of a device-bound program. When the device is unregistered, __bpf_offload_dev_netdev_unregister() hands the stale pointer to __bpf_prog_offload_destroy(), which faults on the freed program:
BUG: unable to handle page fault for address: ffffc90000071050 RIP: 0010:__bpf_prog_offload_destroy+0x3f/0x310
It takes the right to load a device-bound XDP program, CAP_BPF and CAP_NET_ADMIN or a BPF token, and a device that can be removed.
Commit a1aa9ef47c29 ("bpf: Fix stale offload->prog pointer after constant blinding") repaired the other place that replaces a program. Do the same here.
Nothing keeps the device while a program is loaded, so it can also be unregistered at that very moment. That frees the offload, and it may have read offload->prog already when the old copy of the program is freed. In both places update the pointer under bpf_devs_lock, before the old copy goes.
--- include/linux/bpf.h | 5 +++++ kernel/bpf/core.c | 4 ++-- kernel/bpf/offload.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
include/linux/bpf.h +5 -0
@@ -3258,6 +3258,7 @@ int bpf_dev_bound_kfunc_check(struct bpf_verifier_log *log,void *bpf_dev_bound_resolve_kfunc (struct bpf_prog *prog,u32 func_id);int bpf_prog_dev_bound_init (struct bpf_prog *prog,union bpf_attr *attr);int bpf_prog_dev_bound_inherit (struct bpf_prog *new_prog,struct bpf_prog *old_prog); +void bpf_prog_dev_bound_moved (struct bpf_prog *prog);void bpf_dev_bound_netdev_unregister (struct net_device *dev);static inline bool bpf_prog_is_dev_bound (const struct bpf_prog_aux *aux)
@@ -3319,6 +3320,10 @@ static inline int bpf_prog_dev_bound_inherit(struct bpf_prog *new_prog,return -EOPNOTSUPP ; } +static inline void bpf_prog_dev_bound_moved (struct bpf_prog *prog) +{ +} +static inline void bpf_dev_bound_netdev_unregister (struct net_device *dev) { }
kernel/bpf/core.c +2 -2
@@ -269,6 +269,7 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,memcpy (fp, fp_old, fp_old->pages *PAGE_SIZE ); fp->pages = pages; fp->aux->prog = fp; +bpf_prog_dev_bound_moved (fp);/* We keep fp->aux from fp_old around in the new * reallocated structure.
@@ -1524,8 +1525,7 @@ void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other)* know whether fp here is the clone or the original. */ fp->aux->prog = fp; -if (fp->aux->offload) - fp->aux->offload->prog = fp; +bpf_prog_dev_bound_moved (fp);bpf_prog_clone_free (fp_other); }
kernel/bpf/offload.c +16 -0
@@ -106,6 +106,22 @@ static int __bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,return err; } +/* +* @prog takes the place of a copy that the caller is about to free. Nothing +* keeps the netdev while a program is loaded: once the lock is dropped, no +* unregistration is left that has got the old copy from offload->prog. +*/ +void bpf_prog_dev_bound_moved (struct bpf_prog *prog) +{ +if (!bpf_prog_is_dev_bound (prog->aux)) +return ; + +down_read (&bpf_devs_lock); +if (prog->aux->offload) + prog->aux->offload->prog = prog; +up_read (&bpf_devs_lock); +} +static void __bpf_prog_offload_destroy (struct bpf_prog *prog) {struct bpf_prog_offload *offload = prog->aux->offload;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1729/2151 bpf: Dont bind a program to a netdev that goes away
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit af929bc938e0d0ecd839e6fed9a2ce5eb5185e5c ]
bpf_prog_dev_bound_init() looks the device up, takes bpf_devs_lock and registers the device for the program. The reference it holds does not keep the device registered. If bpf_dev_bound_netdev_unregister() has run by the time the lock is taken, nobody takes the program off the device any
more: the bpf_offload_netdev and offload->netdev point to a net_device that is freed as soon as the reference is dropped. bpf_dev_bound_resolve_kfunc() dereferences it while the program is verified, and a new device at the same address finds the old entry.
unregister_netdevice_many_notify() leaves NETREG_REGISTERED before it calls bpf_dev_bound_netdev_unregister(), which takes bpf_devs_lock. Look at reg_state under that lock, and treat a device that goes like one that is not there.
--- kernel/bpf/offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +8 -1
@@ -276,7 +276,14 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) prog->aux->offload_requested = !(attr->prog_flags &BPF_F_XDP_DEV_BOUND_ONLY );down_write (&bpf_devs_lock); - err =__bpf_prog_dev_bound_init (prog, netdev); +/* +* Behind bpf_dev_bound_netdev_unregister() nobody would take the +* program off the device, which goes once the reference is dropped. +*/ +if (READ_ONCE (netdev->reg_state) ==NETREG_REGISTERED ) + err =__bpf_prog_dev_bound_init (prog, netdev); +else + err = -EINVAL ;up_write (&bpf_devs_lock); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1730/2151 bpf: Dont take an extension for an iterator program
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7cc639dc45c5d3b69acb2a2fc834e9eec51e0214 ]
An extension inherits the expected_attach_type of the program it extends. If that is BPF_TRACE_ITER, check_attach_btf_id() hands the extension to bpf_iter_prog_supported(), which goes by the name of the attach function. For an extension that is the name of the subprogram it replaces, so the load fails with -EINVAL, unless that subprogram is called like the function of a target, bpf_iter_bpf_map_elem for example.
Then the extension gets the context of that target. If the subprogram has as many arguments, it can use the key and the value as buffers, but how far it reaches is noted in the extension, where the test of the iterator link does not look: it reads and writes behind the elements of the map. And the id of the subprogram in the BTF of the program is cached as the id of the target, so that programs of that target which are loaded already cannot be attached.
Refuse all extensions here.
--- kernel/bpf/bpf_iter.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/bpf/bpf_iter.c +7 -0
@@ -351,6 +351,13 @@ int bpf_iter_prog_supported(struct bpf_prog *prog)const char *prefix =BPF_ITER_FUNC_PREFIX ;int prefix_len =strlen (prefix); +/* +* The attach function of an extension is a subprogram of the iterator +* program that it extends, whatever its name is. +*/ +if (prog->type ==BPF_PROG_TYPE_EXT ) +return -EINVAL ; +if (strncmp (attach_fname, prefix, prefix_len))return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1731/2151 bpf: Dont take an extension for a writable raw tracepoint program
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 7fe348f18b37b3f4c8beb981ef3f84564047380a ]
bpf_probe_register() compares max_tp_access of the program that is attached with the size of the buffer that the tracepoint lets programs write to. An extension of that program, or of one of its global functions, gets the same context and the same pointer to the buffer. What it accesses is noted in its own max_tp_access, which nobody looks at. So it reads and writes behind the buffer, of a tracepoint that may have none:
BUG: KASAN: stack-out-of-bounds in bpf_prog_5843f2b820eb4929_tr26_ext_far+0xf4/0x10c Write of size 4 at addr ffffc90000d8f894 by task wext/103
Refuse such extensions.
--- kernel/bpf/verifier.c | 9 +++++++++ 1 file changed, 9 insertions(+)
kernel/bpf/verifier.c +9 -0
@@ -24297,6 +24297,15 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, "Extension programs should be JITed\n");return -EINVAL ; } +/* +* How much of the buffer of the tracepoint is used +* is checked for the program that is attached to it. +*/ +if (tgt_prog->type ==BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ) { +bpf_log (log, +"Cannot extend a writable raw tracepoint program\n" ); +return -EINVAL ; + } tgt_changes_pkt_data = aux->func ? aux->func[subprog]->aux->changes_pkt_data : aux->changes_pkt_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1732/2151 power: supply: qcom_battmgr: report full batteries
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit 6c8098e04ee4d233399e40e7311715844910f8f8 ]
The SC8280XP battery-status response has no explicit full state. When a battery reaches its full capacity on external power, neither the charging nor discharging bit is set. The driver consequently reports "Not charging", which can make userspace show the system as battery powered.
Use the response's power-online bit and the reported capacity to identify a battery that is full while externally powered. Preserve "Not charging" for a battery whose charging is inhibited below its full capacity.
--- drivers/power/supply/qcom_battmgr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/power/supply/qcom_battmgr.c +11 -5
@@ -1281,6 +1281,7 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr, size_t len) {unsigned int opcode =le32_to_cpu (resp->hdr.opcode); +unsigned int power_state;unsigned int source;unsigned int state;size_t payload_len = len -sizeof (struct pmic_glink_hdr );
@@ -1331,19 +1332,24 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,return ; } + battmgr->status.capacity =le32_to_cpu (resp->status.capacity) *1000 ; + battmgr->status.power_now =le32_to_cpu (resp->status.rate) *1000 ; + battmgr->status.voltage_now =le32_to_cpu (resp->status.battery_voltage) *1000 ; + battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); + state =le32_to_cpu (resp->status.battery_state); + power_state =le32_to_cpu (resp->status.power_state);if (state &BIT (0 )) battmgr->status.status =POWER_SUPPLY_STATUS_DISCHARGING ;else if (state &BIT (1 )) battmgr->status.status =POWER_SUPPLY_STATUS_CHARGING ; +else if ((power_state &BIT (0 )) && + battmgr->info.last_full_capacity && + battmgr->status.capacity >= battmgr->info.last_full_capacity) + battmgr->status.status =POWER_SUPPLY_STATUS_FULL ;else battmgr->status.status =POWER_SUPPLY_STATUS_NOT_CHARGING ; - battmgr->status.capacity =le32_to_cpu (resp->status.capacity) *1000 ; - battmgr->status.power_now =le32_to_cpu (resp->status.rate) *1000 ; - battmgr->status.voltage_now =le32_to_cpu (resp->status.battery_voltage) *1000 ; - battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); - source =le32_to_cpu (resp->status.charging_source);qcom_battmgr_sc8280xp_set_online (battmgr->ac_psy, &battmgr->ac.online, source ==BATTMGR_CHARGING_SOURCE_AC );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1733/2151 netfilter: conntrack: fix unlikely UaF in gc worker
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 9836164821a46af07428bb2a5e14137bf0c7bd6e ]
When early-drop scan is enabled, gc_worker() reads tmp->ct_net, resolves cnet with nf_ct_pernet(), and reads cnet->count with RCU read lock held but before acquiring a reference to tmp.
Its unlikely but possible that the worker gets preempted before reading cnet->count while nf_conntrack_cleanup_net_list manages to unlink all conntracks and returns in the mean time.
This allows for the pernet memory to get free'd.
On resume, use after free would occur when the worker reads cnet->count.
This can be solved either via another synchronize_rcu() in nf_conntrack_cleanup_net_list or via cheaper flush_work(). If work wasn't running no race can happen as next call cannot observe already-unlinked conntrack objects.
This is an LLM finding with no reproducer, but it appears to be correct.
--- net/netfilter/nf_conntrack_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_conntrack_core.c +5 -0
@@ -2504,6 +2504,11 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list) goto i_see_dead_people; } +/* must wait for current scan loop, worker also looks at +* struct nf_conntrack_net, which is about to be free'd. +*/ +flush_work (&conntrack_gc_work.dwork.work); +list_for_each_entry (net, net_exit_list, exit_list) {nf_conntrack_ecache_pernet_fini (net);nf_conntrack_expect_pernet_fini (net);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1734/2151 selftests: netfilter: fix return value in zone subtest
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit a20a01ae89813ef493dc416d69f2b2ad17afb54c ]
zone subtest prints FAIL, but did not set 'ret=1', so kselftest framework reports success.
While at it, also fail when "nft -f" returns an error.
Noticed thanks to a (broken) local patch that should have caused this selftest (resp. the kselftest framework) to report a failure.
--- .../selftests/net/netfilter/conntrack_vrf.sh | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
tools/testing/selftests/net/netfilter/conntrack_vrf.sh +22 -3
@@ -84,7 +84,7 @@ busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1" # as decided by the first iteration of the ruleset. test_ct_zone_in() { -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF table testct { chain rawpre { type filter hook prerouting priority raw;
@@ -105,6 +105,12 @@ table testct { } } EOF + then + echo "FAIL: cannot load testct nft ruleset" + ret=1 + return + fi + ip netns exec "$ns1" ping -W 1 -c 1 -I veth0 "$IP0" > /dev/null # should be in zone 1, not zone 2
@@ -113,6 +119,7 @@ EOF echo "PASS: entry found in conntrack zone 1" else echo "FAIL: entry not found in conntrack zone 1" + ret=1 count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 2 2> /dev/null | wc -l) if [ "$count" -eq 1 ]; then echo "FAIL: entry found in zone 2 instead"
@@ -137,7 +144,7 @@ test_masquerade_vrf() ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain rawout {
@@ -158,6 +165,12 @@ table ip nat { } } EOF + then + echo "FAIL: cannot load ip nat nft ruleset" + ret=1 + return + fi + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on vrf device" ret=1
@@ -184,7 +197,7 @@ EOF test_masquerade_veth() { ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain postrouting {
@@ -193,6 +206,12 @@ table ip nat { } } EOF + then + echo "FAIL: cannot load ip nat postrouting ruleset" + ret=1 + return + fi + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on veth device" ret=1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1735/2151 netfilter: nft_compat: restrict raw table targets/matches
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit ac364eb4d6d747b15df17e5fc9e442c318afaaac ]
xt targets and matches declaring .table = "raw" (CT, NOTRACK) rely on only ever running in the legacy raw table's prerouting/output chains, ahead of conntrack. nft_compat_chain_validate_dependency() already enforces this kind of correspondence for "nat" by requiring the chain type to actually be NAT, but did nothing for "raw": a rule wrapping the CT target could be loaded into any hook and any priority via nft_compat, including after the real conntrack hook has already run.
The CT target attaches a conntrack template to the skb when none is set yet.
Require that a "raw" table dependency actually matches what xtables enforces via the implict/builtin table dependency.
--- net/netfilter/nft_compat.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
net/netfilter/nft_compat.c +15 -0
@@ -14,6 +14,7 @@#include <linux/netfilter/nf_tables.h> #include <linux/netfilter/nf_tables_compat.h> #include <linux/netfilter/x_tables.h> +#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv6/ip6_tables.h> #include <linux/netfilter_bridge/ebtables.h>
@@ -45,6 +46,20 @@ static int nft_compat_chain_validate_dependency(const struct nft_ctx *ctx, type =NFT_CHAIN_T_NAT ;if (basechain->type->type != type)return -EINVAL ; + }else if (strcmp (tablename,"raw" ) ==0 ) { +/* iptables-nft emulates the legacy raw table, which only +* ever has prerouting/output chains at this exact priority. +*/ +if (ctx->family !=NFPROTO_IPV4 && + ctx->family !=NFPROTO_IPV6 ) +return -EINVAL ; + +if (basechain->ops.hooknum !=NF_INET_PRE_ROUTING && + basechain->ops.hooknum !=NF_INET_LOCAL_OUT ) +return -EINVAL ; + +if (basechain->ops.priority !=NF_IP_PRI_RAW ) +return -EINVAL ; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1736/2151 bpf: Dont take a program with a target program for an iterator
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit b83bacf2161d0f8583e3f1e9c90402638992ad82 ]
bpf_iter_prog_supported() goes by the name of the attach function. Commit 7cc639dc45c5 ("bpf: Don't take an extension for an iterator program") keeps out extensions, for which that is the name of a function of another program. A tracing program with BPF_TRACE_ITER that is loaded with attach_prog_fd gets there as well: unlike for BPF_TRACE_RAW_TP, bpf_check_attach_target() does not mind the target program.
If the function is called like that of an iterator target, bpf_iter_bpf_map for example, its id in the BTF of the program is cached as the id of the target, even if the load fails later. Programs of that target which are loaded already cannot be attached any more. And the program itself can be attached as an iterator of that target, with a context that the verifier has taken from the prototype of that function:
BUG: KASAN: stack-out-of-bounds in bpf_prog_66d4234e2e50f5b6_ts26_forged+0x12a/0x20b Read of size 8 at addr ffffc90000d9fc48 by task ts26/104
Refuse every program that has a target program. That covers extensions.
--- kernel/bpf/bpf_iter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/bpf_iter.c +3 -3
@@ -352,10 +352,10 @@ int bpf_iter_prog_supported(struct bpf_prog *prog)int prefix_len =strlen (prefix);/* -* The attach function of an extension is a subprogram of the iterator -* program that it extends, whatever its name is. +* The attach function of a program that has a target program is a +* function of that program, whatever its name is. */ -if (prog->type ==BPF_PROG_TYPE_EXT ) +if (prog->aux->dst_prog)return -EINVAL ;if (strncmp (attach_fname, prefix, prefix_len))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1737/2151 bpf: Dont let an extension reach further into the context than its target
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit fcbfa99aa657627528b75e7dc1023bcb0b84e558 ]
How large the context of a raw tracepoint, tracepoint or syscall program is depends on what the program is attached to, or is run with. bpf_probe_register(), perf_event_set_bpf_prog() and the test runs compare that with max_ctx_offset of the program.
An extension of the program, or of one of its global functions, gets the same context. How far it reaches is noted in its own max_ctx_offset, which nobody looks at. On a tracepoint with one argument it reads the stack behind the arguments, in a test run the memory behind the context, or from NULL if there is none:
BUG: KASAN: stack-out-of-bounds in bpf_prog_954b5d2051843629_ts28_ext_far+0x7e/0x113 Read of size 8 at addr ffffc90000def7b8 by task ts28/104 BUG: KASAN: slab-out-of-bounds in bpf_prog_954b5d2051843629_ts28_ext_far+0x7e/0x113 Read of size 8 at addr ffff88810712c3e8 by task ts28/104
Refuse to attach an extension that reaches further than the program which it extends. A program that leaves the context to its extensions has to touch as much of it as they do.
--- kernel/bpf/syscall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/bpf/syscall.c +13 -0
@@ -3740,6 +3740,19 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, err = -EINVAL ; goto out_unlock; } +/* +* The size of these contexts depends on what the program is attached +* to, or run with. That is compared with max_ctx_offset of the program, +* and nobody looks at the one of its extensions. +*/ +if (prog->type ==BPF_PROG_TYPE_EXT && + (tgt_prog->type ==BPF_PROG_TYPE_RAW_TRACEPOINT || + tgt_prog->type ==BPF_PROG_TYPE_TRACEPOINT || + tgt_prog->type ==BPF_PROG_TYPE_SYSCALL ) && + prog->aux->max_ctx_offset > tgt_prog->aux->max_ctx_offset) { + err = -EINVAL ; + goto out_unlock; + } err =bpf_link_prime (&link->link.link, &link_primer);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1738/2151 bpf: Keep the symbols of a program until it has ended
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 4eaf4d71b91a983489227336adcab33d8eae58a5 ]
When the last reference to a program goes, __bpf_prog_put_noref() takes its symbols out of the kallsyms tree and frees its line info at once, and waits for the grace periods only with the rest. But the program may still be running: the link or the array it was called from is gone, the call is not over.
search_bpf_extables() finds the exception table of a program by its symbol. A load that faults, and that the table is there to fix up, is fatal from then on:
Oops: general protection fault, probably for non-canonical address 0xdead0000000006f8: 0000 [#1] SMP NOPTI RIP: 0010:0xffffffffc06008f6
It takes a program that is detached and closed on one CPU while it runs on another. Unwinders and bpf_prog_find_from_stack() do not know the program any more either, and the stack dump of a BPF stream reads the freed line info.
Free the line info behind the grace periods the program needs, as it is done with the BTF that its text comes from. Remove the symbols in bpf_prog_free_deferred(), which runs behind them as well. The symbols are looked up under rcu_read_lock(), so the images and the program itself are freed one more grace period later. All that the program refers to is released when it was before.
--- include/linux/bpf.h | 1 + kernel/bpf/core.c | 50 +++++++++++++++++++++++++++++++------------- kernel/bpf/syscall.c | 5 ++--- 3 files changed, 38 insertions(+), 18 deletions(-)
include/linux/bpf.h +1 -0
@@ -1698,6 +1698,7 @@ struct bpf_prog_aux {union {struct work_struct work;struct rcu_head rcu; +struct rcu_work rwork; };struct bpf_stream stream[2 ]; };
kernel/bpf/core.c +35 -15
67 lines not on this page · raw message
kernel/bpf/syscall.c +2 -3
@@ -2385,6 +2385,8 @@ static void __bpf_prog_put_rcu(struct rcu_head *rcu) struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu);btf_put (aux->btf); +kvfree (aux->jited_linfo); +kvfree (aux->linfo);kvfree (aux->func_info);kfree (aux->func_info_aux);free_uid (aux->user);
@@ -2394,10 +2396,7 @@ static void __bpf_prog_put_rcu(struct rcu_head *rcu)static void __bpf_prog_put_noref (struct bpf_prog *prog,bool deferred) { -bpf_prog_kallsyms_del_all (prog);module_put (prog->aux->mod); -kvfree (prog->aux->jited_linfo); -kvfree (prog->aux->linfo);kfree (prog->aux->kfunc_tab);kfree (prog->aux->ctx_arg_info);if (prog->aux->attach_btf)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1739/2151 bpf: Refactor cleanup of bpf_prog_test_run_skb
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
[ Upstream commit d8accf661fcf3088ef4c349ab56ecd19a5071b19 ]
This bit of refactoring aims to simplify how we free memory in bpf_prog_test_run_skb to avoid code duplication.
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
net/bpf/test_run.c +14 -12
@@ -984,10 +984,10 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,u32 size = kattr->test.data_size_in;u32 repeat = kattr->test.repeat;struct __sk_buff *ctx =NULL ; +struct sk_buff *skb =NULL ; +struct sock *sk =NULL ;u32 retval, duration;int hh_len =ETH_HLEN ; -struct sk_buff *skb; -struct sock *sk;void *data;int ret;
@@ -1006,8 +1006,9 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, ctx =bpf_ctx_init (kattr,sizeof (struct __sk_buff ));if (IS_ERR (ctx)) { -kfree (data); -return PTR_ERR (ctx); + ret =PTR_ERR (ctx); + ctx =NULL ; + goto out; }switch (prog->type) {
@@ -1027,21 +1028,20 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, sk =sk_alloc (net,AF_UNSPEC ,GFP_USER , &bpf_dummy_proto,1 );if (!sk) { -kfree (data); -kfree (ctx); -return -ENOMEM ; + ret = -ENOMEM ; + goto out; }sock_init_data (NULL , sk); skb =slab_build_skb (data);if (!skb) { -kfree (data); -kfree (ctx); -sk_free (sk); -return -ENOMEM ; + ret = -ENOMEM ; + goto out; } skb->sk = sk; + data =NULL ;/* data released via kfree_skb */ +skb_reserve (skb,NET_SKB_PAD +NET_IP_ALIGN );__skb_put (skb, size);
@@ -1161,7 +1161,9 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,if (dev && dev != net->loopback_dev)dev_put (dev);kfree_skb (skb); -sk_free (sk); +kfree (data); +if (sk) +sk_free (sk);kfree (ctx);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1740/2151 bpf: Reorder bpf_prog_test_run_skb initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
[ Upstream commit 57bb2f6717930a5e670da179c316159719b724a2 ]
This patch reorders the initialization of bpf_prog_test_run_skb to simplify the subsequent patch. Program types are checked first, followed by the ctx init, and finally the data init. With the subsequent patch, program types and the ctx init provide information that is used in the data init. Thus, we need the data init to happen last.
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
net/bpf/test_run.c +13 -13
@@ -998,19 +998,6 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,if (size <ETH_HLEN )return -EINVAL ; - data =bpf_test_init (kattr, kattr->test.data_size_in, - size,NET_SKB_PAD +NET_IP_ALIGN , -SKB_DATA_ALIGN (sizeof (struct skb_shared_info ))); -if (IS_ERR (data)) -return PTR_ERR (data); - - ctx =bpf_ctx_init (kattr,sizeof (struct __sk_buff )); -if (IS_ERR (ctx)) { - ret =PTR_ERR (ctx); - ctx =NULL ; - goto out; - } -switch (prog->type) {case BPF_PROG_TYPE_SCHED_CLS :case BPF_PROG_TYPE_SCHED_ACT :
@@ -1026,6 +1013,19 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,break ; } + ctx =bpf_ctx_init (kattr,sizeof (struct __sk_buff )); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + + data =bpf_test_init (kattr, kattr->test.data_size_in, + size,NET_SKB_PAD +NET_IP_ALIGN , +SKB_DATA_ALIGN (sizeof (struct skb_shared_info ))); +if (IS_ERR (data)) { + ret =PTR_ERR (data); + data =NULL ; + goto out; + } + sk =sk_alloc (net,AF_UNSPEC ,GFP_USER , &bpf_dummy_proto,1 );if (!sk) { ret = -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1741/2151 bpf: Craft non-linear skbs in BPF_PROG_TEST_RUN
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
[ Upstream commit 838baa351cee86526973fb3ef49c0f4c1b2f3b0c ]
This patch adds support for crafting non-linear skbs in BPF test runs for tc programs. The size of the linear area is given by ctx->data_end, with a minimum of ETH_HLEN always pulled in the linear area. If ctx or ctx->data_end are null, a linear skb is used.
This is particularly useful to test support for non-linear skbs in large codebases such as Cilium. We've had multiple bugs in the past few years where we were missing calls to bpf_skb_pull_data(). This support in BPF_PROG_TEST_RUN would allow us to automatically cover this case in our BPF tests.
LWT program types are currently excluded in this patch. Allowing non-linear skbs for these programs would require a bit more care because they are able to call helpers (ex., bpf_clone_redirect, bpf_redirect) that themselves call eth_type_trans(). eth_type_trans() assumes there are at least ETH_HLEN bytes in the linear area. That may not be true for LWT programs as we already pulled the L2 header via the eth_type_trans() call in bpf_prog_test_run_skb().
In addition to the selftests introduced later in the series, this patch was tested by enabling non-linear skbs for all tc selftests programs and checking test failures were expected.
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 103 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 21 deletions(-)
net/bpf/test_run.c +82 -21
@@ -436,7 +436,7 @@ static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,static int bpf_test_finish (const union bpf_attr *kattr,union bpf_attr __user *uattr,const void *data, -struct skb_shared_info *sinfo,u32 size, +struct skb_shared_info *sinfo,u32 size,u32 frag_size,u32 retval,u32 duration) {void __user *data_out =u64_to_user_ptr (kattr->test.data_out);
@@ -453,7 +453,7 @@ static int bpf_test_finish(const union bpf_attr *kattr, }if (data_out) { -int len = sinfo ? copy_size - sinfo->xdp_frags_size : copy_size; +int len = sinfo ? copy_size - frag_size : copy_size;if (len <0 ) { err = -ENOSPC ;
@@ -899,6 +899,12 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)/* cb is allowed */ if (!range_is_zero(__skb, offsetofend(struct __sk_buff, cb), + offsetof(struct __sk_buff , data_end))) +return -EINVAL ; + +/* data_end is allowed, but not copied to skb */ + + if (!range_is_zero(__skb, offsetofend(struct __sk_buff, data_end), offsetof(struct __sk_buff , tstamp)))return -EINVAL ;
@@ -978,34 +984,39 @@ static struct proto bpf_dummy_proto = {int bpf_prog_test_run_skb (struct bpf_prog *prog,const union bpf_attr *kattr,union bpf_attr __user *uattr) { -bool is_l2 = false, is_direct_pkt_access = false; +bool is_l2 = false, is_direct_pkt_access = false, is_lwt = false; +u32 tailroom =SKB_DATA_ALIGN (sizeof (struct skb_shared_info ));struct net *net = current->nsproxy->net_ns;struct net_device *dev = net->loopback_dev; -u32 size = kattr->test.data_size_in; +u32 headroom =NET_SKB_PAD +NET_IP_ALIGN ; +u32 linear_sz = kattr->test.data_size_in;u32 repeat = kattr->test.repeat;struct __sk_buff *ctx =NULL ;struct sk_buff *skb =NULL ;struct sock *sk =NULL ;u32 retval, duration;int hh_len =ETH_HLEN ; -void *data; +void *data =NULL ;int ret;if ((kattr->test.flags & ~BPF_F_TEST_SKB_CHECKSUM_COMPLETE ) || kattr->test.cpu || kattr->test.batch_size)return -EINVAL ; -if (size <ETH_HLEN ) +if (kattr->test.data_size_in <ETH_HLEN )return -EINVAL ;switch (prog->type) {case BPF_PROG_TYPE_SCHED_CLS :case BPF_PROG_TYPE_SCHED_ACT : + is_direct_pkt_access = true; is_l2 = true; - fallthrough; +break ;case BPF_PROG_TYPE_LWT_IN :case BPF_PROG_TYPE_LWT_OUT :case BPF_PROG_TYPE_LWT_XMIT : + is_lwt = true; + fallthrough;case BPF_PROG_TYPE_CGROUP_SKB : is_direct_pkt_access = true;break ;
@@ -1017,9 +1028,24 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,if (IS_ERR (ctx))return PTR_ERR (ctx); - data =bpf_test_init (kattr, kattr->test.data_size_in, - size,NET_SKB_PAD +NET_IP_ALIGN , -SKB_DATA_ALIGN (sizeof (struct skb_shared_info ))); +if (ctx) { +if (ctx->data_end > kattr->test.data_size_in || ctx->data || ctx->data_meta) { + ret = -EINVAL ; + goto out; + } +if (ctx->data_end) { +/* Non-linear LWT test_run is unsupported for now. */ +if (is_lwt) { + ret = -EINVAL ; + goto out; + } + linear_sz =max (ETH_HLEN , ctx->data_end); + } + } + + linear_sz =min_t (u32, linear_sz,PAGE_SIZE - headroom - tailroom); + + data =bpf_test_init (kattr, linear_sz, linear_sz, headroom, tailroom);if (IS_ERR (data)) { ret =PTR_ERR (data); data =NULL ;
@@ -1043,7 +1069,43 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, data =NULL ;/* data released via kfree_skb */ skb_reserve (skb,NET_SKB_PAD +NET_IP_ALIGN ); -__skb_put (skb, size); +__skb_put (skb, linear_sz); + +if (unlikely (kattr->test.data_size_in > linear_sz)) { +void __user *data_in =u64_to_user_ptr (kattr->test.data_in); +struct skb_shared_info *sinfo =skb_shinfo (skb); +u32 copied = linear_sz; + +while (copied < kattr->test.data_size_in) { +struct page *page; +u32 data_len; + +if (sinfo->nr_frags ==MAX_SKB_FRAGS ) { + ret = -ENOMEM ; + goto out; + } + + page =alloc_page (GFP_KERNEL ); +if (!page) { + ret = -ENOMEM ; + goto out; + } + + data_len =min_t (u32, kattr->test.data_size_in - copied, +PAGE_SIZE ); +skb_fill_page_desc (skb, sinfo->nr_frags, page,0 , data_len); + +if (copy_from_user (page_address (page), data_in + copied, + data_len)) { + ret = -EFAULT ; + goto out; + } + skb->data_len += data_len; + skb->truesize +=PAGE_SIZE ; + skb->len += data_len; + copied += data_len; + } + }if (ctx && ctx->ifindex >1 ) { dev =dev_get_by_index (net, ctx->ifindex);
@@ -1148,12 +1210,11 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,convert_skb_to___skb (skb, ctx); - size = skb->len; -/* bpf program can never convert linear skb to non-linear */ -if (WARN_ON_ONCE (skb_is_nonlinear (skb))) - size =skb_headlen (skb); - ret =bpf_test_finish (kattr, uattr, skb->data,NULL , size, retval, - duration); +if (skb_is_nonlinear (skb)) +/* bpf program can never convert linear skb to non-linear */ +WARN_ON_ONCE (linear_sz == kattr->test.data_size_in); + ret =bpf_test_finish (kattr, uattr, skb->data,skb_shinfo (skb), skb->len, + skb->data_len, retval, duration);if (!ret) ret =bpf_ctx_finish (kattr, uattr, ctx,sizeof (struct __sk_buff ));
@@ -1370,7 +1431,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, goto out; size = xdp.data_end - xdp.data_meta + sinfo->xdp_frags_size; - ret =bpf_test_finish (kattr, uattr, xdp.data_meta, sinfo, size, + ret =bpf_test_finish (kattr, uattr, xdp.data_meta, sinfo, size, sinfo->xdp_frags_size, retval, duration);if (!ret) ret = bpf_ctx_finish(kattr, uattr, ctx,
@@ -1461,7 +1522,7 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, goto out; ret =bpf_test_finish (kattr, uattr, &flow_keys,NULL , -sizeof (flow_keys), retval, duration); +sizeof (flow_keys),0 , retval, duration);if (!ret) ret =bpf_ctx_finish (kattr, uattr, user_ctx,sizeof (struct bpf_flow_keys ));
@@ -1562,7 +1623,7 @@ int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kat user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); } - ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 , retval, duration); + ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration);if (!ret) ret =bpf_ctx_finish (kattr, uattr, user_ctx,sizeof (*user_ctx));
@@ -1762,7 +1823,7 @@ int bpf_prog_test_run_nf(struct bpf_prog *prog,if (ret) goto out; - ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 , retval, duration); + ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration); out:kfree (user_ctx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1742/2151 bpf: Use the socket of a sk_lookup test run under RCU
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6aff0129f327b159c86a54e6bea64a027630ff6b ]
bpf_sk_lookup_assign() accepts only sockets which are freed by RCU, and takes no reference. bpf_prog_test_run_sk_lookup() looks at sk_reuseport of the selected socket and generates its cookie, which is a write, behind bpf_test_timer_leave(), that is outside of the RCU read side critical section in which the program ran. If the socket is closed in the meantime it may be gone.
Do both before the section ends.
--- net/bpf/test_run.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
net/bpf/test_run.c +9 -10
@@ -1608,20 +1608,19 @@ int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kat ctx.selected_sk =NULL ; retval =BPF_PROG_SK_LOOKUP_RUN_ARRAY (progs, ctx, bpf_prog_run); }while (bpf_test_timer_continue (&t,1 , repeat, &ret, &duration)); -bpf_test_timer_leave (&t); - -if (ret <0 ) - goto out; +/* Nothing but RCU keeps the selected socket */ user_ctx->cookie =0 ; -if (ctx.selected_sk) { -if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { +if (!ret && ctx.selected_sk) { +if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) ret = -EOPNOTSUPP ; - goto out; - } - - user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); +else + user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); } +bpf_test_timer_leave (&t); + +if (ret <0 ) + goto out; ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration);if (!ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1743/2151 bpf, cpumap: Hold the device of frames in the queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit f99351272933ba2e1221484a5e53b7a5d2c035f0 ]
A frame that is redirected to another CPU waits in the queue of the cpumap entry with a plain pointer to the device it came from, and an skb from generic XDP with skb->dev. Nothing keeps that device. Closing and unregistering it waits for its NAPI and for RCU, but not for the kthread of the entry. If the kthread is late by more than that, since its CPU is busy with something of a higher priority, it builds skbs for a device that has been freed and hands them to the stack:
BUG: KASAN: use-after-free in dev_gro_receive+0x1f51/0x2b30 Read of size 8 at addr ffff88800a7340b0 by task cpumap/1/map:1/54
Take a reference to the device for each entry of the queue. The kthread cannot drop it at the end of the batch, since its GRO node may keep the skb for longer. Let it note the devices and drop the references behind a full GRO flush, which it does whenever the queue is empty, and from now on also when it has noted about 2048 of them.
A device whose frames are stuck in a queue is now unregistered only when the kthread has got to them. RTNL is not held meanwhile, but if the device goes with its network namespace, the cleanup of all namespaces waits.
--- kernel/bpf/cpumap.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
kernel/bpf/cpumap.c +28 -7
@@ -45,6 +45,7 @@*/ #define CPU_MAP_BULK_SIZE 8/* 8 == one cacheline on 64-bit archs */ +#define CPU_MAP_HELD_DEVS 2048struct bpf_cpu_map_entry ;struct bpf_cpu_map ;
@@ -74,6 +75,13 @@ struct bpf_cpu_map_entry {struct completion kthread_running;struct rcu_work free_work; + +/* +* Every frame and skb in the queue holds a reference to its device. +* The kthread keeps it until nothing is left in GRO. +*/ +struct net_device *held[CPU_MAP_HELD_DEVS ]; +u32 nr_held; };struct bpf_cpu_map {
@@ -129,9 +137,11 @@ static void __cpu_map_ring_cleanup(struct ptr_ring *ring)WARN_ON_ONCE (1 );if (unlikely (__ptr_test_bit (0 , &ptr))) {__ptr_clear_bit (0 , &ptr); +dev_put (((struct sk_buff *)ptr)->dev);kfree_skb (ptr);continue ; } +dev_put (((struct xdp_frame *)ptr)->dev_rx);xdp_return_frame (ptr); } }
@@ -308,7 +318,7 @@ static int cpu_map_kthread_run(void *data)void *frames[CPUMAP_BATCH ];void *skbs[CPUMAP_BATCH ];u32 i, n, m; -bool empty; +bool empty, full;/* Release CPU reschedule checks */ if (__ptr_ring_empty (rcpu->queue)) {
@@ -341,10 +351,12 @@ static int cpu_map_kthread_run(void *data)struct sk_buff *skb = f;__ptr_clear_bit (0 , &skb); + rcpu->held[rcpu->nr_held++] = skb->dev; skbs[ret.skb_n++] = skb;continue ; } + rcpu->held[rcpu->nr_held++] = ((struct xdp_frame *)f)->dev_rx; frames[ret.xdp_n++] = f; page =virt_to_page (f);
@@ -395,10 +407,13 @@ static int cpu_map_kthread_run(void *data)/* Flush either every 64 packets or in case of empty ring */ packets += n; empty =__ptr_ring_empty (rcpu->queue); -if (packets >=NAPI_POLL_WEIGHT || empty) { -cpu_map_gro_flush (rcpu, empty); + full = empty || rcpu->nr_held >CPU_MAP_HELD_DEVS -CPUMAP_BATCH ; +if (packets >=NAPI_POLL_WEIGHT || full) { +cpu_map_gro_flush (rcpu, full); packets =0 ; } +while (full && rcpu->nr_held) +dev_put (rcpu->held[--rcpu->nr_held]);local_bh_enable ();/* resched point, may call do_softirq() */ }
@@ -730,12 +745,14 @@ static void bq_flush_to_queue(struct xdp_bulk_queue *bq)for (i =0 ; i < bq->count; i++) {struct xdp_frame *xdpf = bq->q[i]; -int err; - err =__ptr_ring_produce (q, xdpf); -if (err) { +if (__ptr_ring_full (q)) { drops++;xdp_return_frame_rx_napi (xdpf); + }else { +/* The device cannot go before the flush, from now on it can */ +dev_hold (xdpf->dev_rx); +__ptr_ring_produce (q, xdpf); } processed++; }
@@ -799,11 +816,15 @@ int cpu_map_generic_redirect(struct bpf_cpu_map_entry *rcpu,__skb_pull (skb, skb->mac_len);skb_set_redirected (skb, false); +dev_hold (skb->dev);__ptr_set_bit (0 , &skb); ret =ptr_ring_produce (rcpu->queue, skb); -if (ret <0 ) +if (ret <0 ) { +__ptr_clear_bit (0 , &skb); +dev_put (skb->dev); goto trace; + }wake_up_process (rcpu->kthread); trace:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1744/2151 bpf: Unclone skb head on bpf_dynptr_write to skb metadata
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Sitnicki <[email protected]>
[ Upstream commit f38499ff45f567c932d0911e6a30b8ca022b9b52 ]
Currently bpf_dynptr_from_skb_meta() marks the dynptr as read-only when the skb is cloned, preventing writes to metadata.
Remove this restriction and unclone the skb head on bpf_dynptr_write() to metadata, now that the metadata is preserved during uncloning. This makes metadata dynptr consistent with skb dynptr, allowing writes regardless of whether the skb is cloned.
Stable-dep-of: 1c19f2b3b2f3 ("bpf: Follow the head if an skb is written from a slice")
--- include/linux/filter.h | 9 +++++++++ kernel/bpf/helpers.c | 6 ++---- net/core/filter.c | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-)
include/linux/filter.h +9 -0
@@ -1827,6 +1827,8 @@ int __bpf_xdp_store_bytes(struct xdp_buff *xdp, u32 offset, void *buf, u32 len);void *bpf_xdp_pointer (struct xdp_buff *xdp,u32 offset,u32 len);void bpf_xdp_copy_buf (struct xdp_buff *xdp,unsigned long off,void *buf,unsigned long len,bool flush); +int __bpf_skb_meta_store_bytes (struct sk_buff *skb,u32 offset, +const void *from,u32 len,u64 flags);void *bpf_skb_meta_pointer (struct sk_buff *skb,u32 offset);#else /* CONFIG_NET */ static inline int __bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset,
@@ -1863,6 +1865,13 @@ static inline void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off, voi { } +static inline int __bpf_skb_meta_store_bytes (struct sk_buff *skb,u32 offset, +const void *from,u32 len, +u64 flags) +{ +return -EOPNOTSUPP ; +} +static inline void *bpf_skb_meta_pointer (struct sk_buff *skb,u32 offset) {return ERR_PTR (-EOPNOTSUPP );
kernel/bpf/helpers.c +2 -4
@@ -1856,10 +1856,8 @@ int __bpf_dynptr_write(const struct bpf_dynptr_kern *dst, u32 offset, void *src,return -EINVAL ;return __bpf_xdp_store_bytes (dst->data, dst->offset + offset, src, len);case BPF_DYNPTR_TYPE_SKB_META : -if (flags) -return -EINVAL ; -memmove (bpf_skb_meta_pointer (dst->data, dst->offset + offset), src, len); -return 0 ; +return __bpf_skb_meta_store_bytes (dst->data, dst->offset + offset, src, + len, flags);default :WARN_ONCE (true,"bpf_dynptr_write: unknown dynptr type %d\n" , type);return -EFAULT ;
net/core/filter.c +12 -6
@@ -12099,6 +12099,18 @@ void *bpf_skb_meta_pointer(struct sk_buff *skb, u32 offset)return skb_metadata_end (skb) -skb_metadata_len (skb) + offset; } +int __bpf_skb_meta_store_bytes (struct sk_buff *skb,u32 offset, +const void *from,u32 len,u64 flags) +{ +if (unlikely (flags)) +return -EINVAL ; +if (unlikely (bpf_try_make_writable (skb,0 ))) +return -EFAULT ; + +memmove (bpf_skb_meta_pointer (skb, offset), from, len); +return 0 ; +} +__bpf_kfunc_start_defs (); __bpf_kfunc int bpf_dynptr_from_skb(struct __sk_buff *s, u64 flags,struct bpf_dynptr *ptr__uninit)
@@ -12126,9 +12138,6 @@ __bpf_kfunc int bpf_dynptr_from_skb(struct __sk_buff *s, u64 flags,* XDP context with bpf_xdp_adjust_meta(). Serves as an alternative to * &__sk_buff->data_meta. * -* If passed @skb_ is a clone which shares the data with the original, the -* dynptr will be read-only. This limitation may be lifted in the future. -* * Return: * * %0 - dynptr ready to use * * %-EINVAL - invalid flags, dynptr set to null
@@ -12146,9 +12155,6 @@ __bpf_kfunc int bpf_dynptr_from_skb_meta(struct __sk_buff *skb_, u64 flags,bpf_dynptr_init (ptr, skb,BPF_DYNPTR_TYPE_SKB_META ,0 ,skb_metadata_len (skb)); -if (skb_cloned (skb)) -bpf_dynptr_set_rdonly (ptr); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1745/2151 bpf: Follow the head if an skb is written from a slice
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 1c19f2b3b2f3b55c8017092257634cb8229b7d97 ]
The source of bpf_dynptr_write() may be a slice of the skb which is written to, that is a pointer into its head. bpf_dynptr_copy() does it by itself for a copy inside of one skb, if the source is linear and the destination is not.
__bpf_skb_store_bytes() and __bpf_skb_meta_store_bytes() make the skb writable first. If that reallocates the head, the source points to the old one, and freed memory is copied into the packet.
The offsets in the head do not change when it is reallocated here. Move the source along with the head.
--- net/core/filter.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
net/core/filter.c +20 -2
@@ -1717,6 +1717,24 @@ static inline void bpf_pull_mac_rcsum(struct sk_buff *skb)skb_postpull_rcsum (skb,skb_mac_header (skb), skb->mac_len); } +/* +* The source of a write through a dynptr may be a slice of the same skb. +* Making the skb writable can move its head: follow the move. +*/ +static int bpf_try_make_writable_from (struct sk_buff *skb,u32 write_len, +const void **from) +{ +const void *head = skb->head; +bool in_head = *from >= head && + *from < (const void *)skb_end_pointer (skb); +int err; + + err =bpf_try_make_writable (skb, write_len); +if (!err && in_head) + *from = skb->head + (*from - head); +return err; +} + BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset, const void *, from, u32, len, u64, flags) {
@@ -1726,7 +1744,7 @@ BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset,return -EINVAL ;if (unlikely (offset >INT_MAX ))return -EFAULT ; -if (unlikely (bpf_try_make_writable (skb, offset + len))) +if (unlikely (bpf_try_make_writable_from (skb, offset + len, &from)))return -EFAULT ; ptr = skb->data + offset;
@@ -12104,7 +12122,7 @@ int __bpf_skb_meta_store_bytes(struct sk_buff *skb, u32 offset, {if (unlikely (flags))return -EINVAL ; -if (unlikely (bpf_try_make_writable (skb,0 ))) +if (unlikely (bpf_try_make_writable_from (skb,0 , &from)))return -EFAULT ;memmove (bpf_skb_meta_pointer (skb, offset), from, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1746/2151 bpf: Use memmove() to store bytes in an skb
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 1db084f42884c5af881fedf3df4777fe2095b20b ]
Through bpf_dynptr_write() and bpf_dynptr_copy() the source of bpf_skb_store_bytes() can be a slice of the same skb which overlaps the destination. memcpy() then reads bytes which it has overwritten already. On x86 with FSRM it repeats the first bytes of the source instead of copying it. Local, ringbuf and skb metadata dynptrs are written with memmove() for that reason.
--- net/core/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/filter.c +2 -1
@@ -1751,7 +1751,8 @@ BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset,if (flags &BPF_F_RECOMPUTE_CSUM )__skb_postpull_rcsum (skb, ptr, len, offset); -memcpy (ptr, from, len); +/* through a dynptr the source may be an overlapping slice of the skb */ +memmove (ptr, from, len);if (flags &BPF_F_RECOMPUTE_CSUM )__skb_postpush_rcsum (skb, ptr, len, offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1747/2151 bpf: Use memmove() to store bytes in an xdp_buff
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit ab08863c58b1a96ff8378e373cb3d277cbe65b68 ]
bpf_dynptr_write() to the dynptr of an xdp_buff ends in bpf_xdp_store_bytes(). The source can be a slice of the same xdp_buff which overlaps the destination, and the helper itself takes such a slice as well. memcpy() then reads bytes which it has overwritten already. On x86 with FSRM
p = bpf_dynptr_slice_rdwr(&ptr, 0, NULL, 64); bpf_dynptr_write(&ptr, 8, p, 64, 0);
repeats the first 8 bytes of the packet instead of moving 64.
A write that crosses from the linear part into a fragment is copied piece by piece, where the first piece can overwrite what the second one has yet to read. That is not dealt with here.
--- net/core/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/filter.c +2 -1
@@ -4200,7 +4200,8 @@ BPF_CALL_4(bpf_xdp_store_bytes, struct xdp_buff *, xdp, u32, offset,if (!ptr)bpf_xdp_copy_buf (xdp, offset, buf, len, true);else -memcpy (ptr, buf, len); +/* through a dynptr the source may be an overlapping slice */ +memmove (ptr, buf, len);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1748/2151 usb: gadget: dummy_hcd: fix SuperSpeed ep0 maxpacket
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Skalkin <[email protected]>
[ Upstream commit e68f245bcb1f863aeb8eab617bd06878c078029a ]
For USB_SPEED_SUPER, dummy_hcd sets ep0 maxpacket to 9. That is incorrect for SuperSpeed ep0 and breaks short packet handling in control transfer tests.
Set ep0 maxpacket to 512 for SuperSpeed.
--- drivers/usb/gadget/udc/dummy_hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/dummy_hcd.c +1 -1
@@ -918,7 +918,7 @@ static int dummy_set_selfpowered(struct usb_gadget *_gadget, int value)static void dummy_udc_update_ep0 (struct dummy *dum) {if (dum->gadget.speed ==USB_SPEED_SUPER ) - dum->ep[0 ].ep.maxpacket =9 ; + dum->ep[0 ].ep.maxpacket =512 ;else dum->ep[0 ].ep.maxpacket =64 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1749/2151 usb: gadget: dummy_hcd: prevent unbind via sysfs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
[ Upstream commit bdf12cde30830d46a8ef1ba93986356f1164b4f1 ]
The dummy_hcd (Host Controller) and dummy_udc (Device Controller) are implemented as two separate platform drivers that share the same underlying state (struct dummy). They are designed to be created and destroyed together during the module's init and exit phases.
If userspace forces the dummy_hcd driver to unbind from the device via sysfs, dummy_hcd_remove() cleans up the host controllers and sets the pointers to NULL (dum->hs_hcd = NULL). However, the dummy_udc driver is still bound to its device, meaning the USB gadget is still registered with the udc-core subsystem.
If a new gadget driver is subsequently registered, it binds to the still-registered dummy_udc gadget, invoking the dummy_udc_start() callback. This callback attempts to retrieve the HCD state using gadget_to_dummy_hcd(), which returns NULL because of the unbind. This results in a null-pointer dereference:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] ... RIP: 0010:dummy_udc_start+0xd0/0x1f0 drivers/usb/gadget/udc/dummy_hcd.c:1022 ... Call Trace: <TASK> usb_gadget_udc_start_locked drivers/usb/gadget/udc/core.c:1237 [inline] gadget_bind_driver+0x3a8/0x9e0 drivers/usb/gadget/udc/core.c:1667 call_driver_probe drivers/base/dd.c:-1 [inline] really_probe+0x254/0xae0 drivers/base/dd.c:706 __driver_probe_device+0x1e8/0x360 drivers/base/dd.c:868 driver_probe_device+0x4f/0x240 drivers/base/dd.c:898 __driver_attach+0x339/0x600 drivers/base/dd.c:1292 bus_for_each_dev+0x23b/0x2c0 drivers/base/bus.c:383 bus_add_driver+0x345/0x670 drivers/base/bus.c:763 driver_register+0x23a/0x320 drivers/base/driver.c:174 usb_gadget_register_driver_owner+0xf9/0x270 drivers/usb/gadget/udc/core.c:1752 raw_ioctl_run drivers/usb/gadget/legacy/raw_gadget.c:596 [inline] raw_ioctl+0x1541/0x41c0 drivers/usb/gadget/legacy/raw_gadget.c:1307
Adding NULL checks to the UDC callbacks is not a robust solution because there is no synchronization between dummy_hcd_remove() and the UDC callbacks, which would result in a use-after-free race condition if the HCD were unbound concurrently.
Fix this by setting .suppress_bind_attrs = true in both driver definitions. This prevents userspace from unbinding these drivers dynamically, ensuring their lifecycles remain strictly synchronized with the module's load/unload process.
--- drivers/usb/gadget/udc/dummy_hcd.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/gadget/udc/dummy_hcd.c +2 -0
@@ -1184,6 +1184,7 @@ static struct platform_driver dummy_udc_driver = { .resume = dummy_udc_resume, .driver = { .name = gadget_name, + .suppress_bind_attrs = true, }, };
@@ -2806,6 +2807,7 @@ static struct platform_driver dummy_hcd_driver = { .resume = dummy_hcd_resume, .driver = { .name = driver_name, + .suppress_bind_attrs = true, }, };
Signature · 1 line
2.53.0