5.15.226-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 1930/2214 rpmsg: virtio: EPOLLOUT support
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrick Oppenlander <[email protected]>
[ Upstream commit c38d8b66c82c585199e2ad67282295f21cfa489f ]
Previously, polling an rpmsg endpoint (e.g. /dev/ttyRPMSGx) would generate EPOLLIN events but no EPOLLOUT events.
Unfortunately, poll support means that we can no longer disable tx-complete interrupts as there is no way to know whether a poller is waiting in sendq, so we always need notifications.
Stable-dep-of: 7dd4cffdf4c2 ("rpmsg: virtio: fix error handling in TX buffer wait")
--- drivers/rpmsg/virtio_rpmsg_bus.c | 101 ++++++++++--------------------- 1 file changed, 32 insertions(+), 69 deletions(-)
drivers/rpmsg/virtio_rpmsg_bus.c +32 -69
@@ -42,13 +42,12 @@* @buf_size: size of one rx or tx buffer * @last_sbuf: index of last tx buffer used * @bufs_dma: dma base addr of the buffers -* @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders. +* @tx_lock: protects svq and sbufs, to allow concurrent senders. * sending a message might require waking up a dozing remote * processor, which involves sleeping, hence the mutex. * @endpoints: idr of local endpoints, allows fast retrieval * @endpoints_lock: lock of the endpoints set * @sendq: wait queue of sending contexts waiting for a tx buffers -* @sleepers: number of senders that are waiting for a tx buffer * * This structure stores the rpmsg state of a given virtio remote processor * device (there might be several virtio proc devices for each physical
@@ -66,7 +65,6 @@ struct virtproc_info {struct idr endpoints;struct mutex endpoints_lock;wait_queue_head_t sendq; -atomic_t sleepers; };/* The feature bitmap for virtio rpmsg */
@@ -145,6 +143,8 @@ static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,static int virtio_rpmsg_trysend (struct rpmsg_endpoint *ept,void *data,int len);static int virtio_rpmsg_trysendto (struct rpmsg_endpoint *ept,void *data,int len,u32 dst); +static __poll_t virtio_rpmsg_poll (struct rpmsg_endpoint *ept,struct file *filp, +poll_table *wait);static ssize_t virtio_rpmsg_get_mtu (struct rpmsg_endpoint *ept);static struct rpmsg_device *__rpmsg_create_channel (struct virtproc_info *vrp,struct rpmsg_channel_info *chinfo);
@@ -155,6 +155,7 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .sendto = virtio_rpmsg_sendto, .trysend = virtio_rpmsg_trysend, .trysendto = virtio_rpmsg_trysendto, + .poll = virtio_rpmsg_poll, .get_mtu = virtio_rpmsg_get_mtu, };
@@ -437,7 +438,6 @@ static void *get_a_tx_buf(struct virtproc_info *vrp)unsigned int len;void *ret; -/* support multiple concurrent senders */ mutex_lock (&vrp->tx_lock);/*
@@ -455,62 +455,6 @@ static void *get_a_tx_buf(struct virtproc_info *vrp)return ret; } -/** -* rpmsg_upref_sleepers() - enable "tx-complete" interrupts, if needed -* @vrp: virtual remote processor state -* -* This function is called before a sender is blocked, waiting for -* a tx buffer to become available. -* -* If we already have blocking senders, this function merely increases -* the "sleepers" reference count, and exits. -* -* Otherwise, if this is the first sender to block, we also enable -* virtio's tx callbacks, so we'd be immediately notified when a tx -* buffer is consumed (we rely on virtio's tx callback in order -* to wake up sleeping senders as soon as a tx buffer is used by the -* remote processor). -*/ -static void rpmsg_upref_sleepers (struct virtproc_info *vrp) -{ -/* support multiple concurrent senders */ -mutex_lock (&vrp->tx_lock); - -/* are we the first sleeping context waiting for tx buffers ? */ -if (atomic_inc_return (&vrp->sleepers) ==1 ) -/* enable "tx-complete" interrupts before dozing off */ -virtqueue_enable_cb (vrp->svq); - -mutex_unlock (&vrp->tx_lock); -} - -/** -* rpmsg_downref_sleepers() - disable "tx-complete" interrupts, if needed -* @vrp: virtual remote processor state -* -* This function is called after a sender, that waited for a tx buffer -* to become available, is unblocked. -* -* If we still have blocking senders, this function merely decreases -* the "sleepers" reference count, and exits. -* -* Otherwise, if there are no more blocking senders, we also disable -* virtio's tx callbacks, to avoid the overhead incurred with handling -* those (now redundant) interrupts. -*/ -static void rpmsg_downref_sleepers (struct virtproc_info *vrp) -{ -/* support multiple concurrent senders */ -mutex_lock (&vrp->tx_lock); - -/* are we the last sleeping context waiting for tx buffers ? */ -if (atomic_dec_and_test (&vrp->sleepers)) -/* disable "tx-complete" interrupts */ -virtqueue_disable_cb (vrp->svq); - -mutex_unlock (&vrp->tx_lock); -} -/** * rpmsg_send_offchannel_raw() - send a message across to the remote processor * @rpdev: the rpmsg channel
@@ -583,9 +527,6 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,/* no free buffer ? wait for one (but bail after 15 seconds) */ while (!msg) { -/* enable "tx-complete" interrupts, if not already enabled */ -rpmsg_upref_sleepers (vrp); -/* * sleep until a free buffer is available or 15 secs elapse. * the timeout period is not configurable because there's
@@ -596,9 +537,6 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, (msg =get_a_tx_buf (vrp)), msecs_to_jiffies(15000)); -/* disable "tx-complete" interrupts if we're the last sleeper */ -rpmsg_downref_sleepers (vrp); -/* timeout ? */ if (!err) {dev_err (dev,"timeout waiting for a tx buffer\n" );
@@ -677,6 +615,34 @@ static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,return rpmsg_send_offchannel_raw (rpdev, src, dst, data, len, false); } +static __poll_t virtio_rpmsg_poll (struct rpmsg_endpoint *ept,struct file *filp, +poll_table *wait) +{ +struct rpmsg_device *rpdev = ept->rpdev; +struct virtio_rpmsg_channel *vch =to_virtio_rpmsg_channel (rpdev); +struct virtproc_info *vrp = vch->vrp; +__poll_t mask =0 ; + +poll_wait (filp, &vrp->sendq, wait); + +/* support multiple concurrent senders */ +mutex_lock (&vrp->tx_lock); + +/* +* check for a free buffer, either: +* - we haven't used all of the available transmit buffers (half of the +* allocated buffers are used for transmit, hence num_bufs / 2), or, +* - we ask the virtqueue if there's a buffer available +*/ +if (vrp->last_sbuf < vrp->num_bufs /2 || + !virtqueue_enable_cb (vrp->svq)) + mask |=EPOLLOUT ; + +mutex_unlock (&vrp->tx_lock); + +return mask; +} +static ssize_t virtio_rpmsg_get_mtu (struct rpmsg_endpoint *ept) {struct rpmsg_device *rpdev = ept->rpdev;
@@ -921,9 +887,6 @@ static int rpmsg_probe(struct virtio_device *vdev)WARN_ON (err);/* sanity check; this can't really happen */ } -/* suppress "tx-complete" interrupts */ -virtqueue_disable_cb (vrp->svq); - vdev->priv = vrp; rpdev_ctrl =rpmsg_virtio_add_ctrl_dev (vdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1931/2214 rpmsg: virtio: fix error handling in TX buffer wait
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Atul Akella <[email protected]>
[ Upstream commit 7dd4cffdf4c2a496ccf783303a03d687a2127baf ]
The TX buffer wait loop in rpmsg_send_offchannel_raw() ignores the possibility of wait_event_interruptible_timeout() returning a negative value, which happens when the wait is interrupted by a signal. In that case the loop spins back around and re-arms the wait instead of propagating the signal, which can stall a task that is trying to be killed.
Separately, on a genuine timeout (return value 0) the function returns -ERESTARTSYS, which is reserved for signal-interrupted syscalls that the kernel may restart. A timeout is not a signal and should not be treated as restartable; return -ETIMEDOUT instead.
Handle both cases explicitly: return err directly when negative, and return -ETIMEDOUT on timeout.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/rpmsg/virtio_rpmsg_bus.c +4 -1
@@ -537,10 +537,13 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, (msg =get_a_tx_buf (vrp)), msecs_to_jiffies(15000)); +if (err <0 ) +return err; +/* timeout ? */ if (!err) {dev_err (dev,"timeout waiting for a tx buffer\n" ); -return -ERESTARTSYS ; +return -ETIMEDOUT ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1932/2214 ARM: 9492/1: alignment: fix LSR #32 and ASR #32 offset decoding
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 9f878a6c2207f0c12f34a715a6a05cfc95f47460 ]
The register-offset form of LDR/STR may apply a shift to Rm. Per DecodeImmShift() (ARM ARM DDI0406C section A8.4.3, "Pseudocode details of instruction-specified shifts and rotates"), an imm5 of 0 encodes a shift of 32 for LSR and ASR; only LSL treats 0 as "no shift", and ROR with 0 encodes RRX.
do_alignment() special-cases RRX but not LSR or ASR, and IS_SHIFT() does not filter these encodings out, so the block is entered with shiftval == 0 and the offset becomes Rm instead of 0 (LSR #32) or the replicated sign of Rm (ASR #32).
do_alignment_finish_ldst() applies the offset to the base-register writeback of the post-indexed form, so the emulated access itself uses the correct faulting address but Rn is left holding the wrong value.
Reproduced on ARM926EJ-S (versatile_defconfig, CONFIG_ALIGNMENT_TRAP=y, gcc 13.3.0) with a misaligned base and Rm = 0x1000:
ldr r0, [r1], r2, lsr #32 Rn advanced by 0x1000, must be unchanged ldr r0, [r1], r2, asr #32 Rn advanced by 0x1000, must be unchanged ldr r0, [r1], r2, asr #32 with Rm negative, Rn must decrease by 1
All three are correct with the patch applied, while a lsr #1 control case is emulated correctly both before and after.
--- arch/arm/mm/alignment.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/arm/mm/alignment.c +8 -2
@@ -915,11 +915,17 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)break ;case SHIFT_LSR : - offset.un >>= shiftval; +if (shiftval ==0 ) + offset.un =0 ; +else + offset.un >>= shiftval;break ;case SHIFT_ASR : - offset.sn >>= shiftval; +if (shiftval ==0 ) + offset.sn >>=31 ; +else + offset.sn >>= shiftval;break ;case SHIFT_RORRRX :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1933/2214 ARM: 9519/1: dma-mapping: Fix wrong free function in __iommu_alloc_simple() error path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Szyprowski <[email protected]>
[ Upstream commit 74f79365839720bdb0c6bb4fe85c5b2a929ff5d1 ]
In __iommu_alloc_simple(), when IOMMU mapping creation fails, the error path unconditionally called __free_from_pool() regardless of the allocation path taken.
For the COHERENT case, memory is allocated via __alloc_simple_buffer(), which does not use the atomic pool. Calling __free_from_pool() on such memory silently returns without freeing, causing a page memory leak.
Fix this by matching the free function to the allocation path:
- COHERENT: use __dma_free_buffer(virt_to_page(addr), size)
- non-COHERENT: use __free_from_pool(addr, size)
--- arch/arm/mm/dma-mapping.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/mm/dma-mapping.c +4 -1
@@ -1407,7 +1407,10 @@ static void *__iommu_alloc_simple(struct device *dev, size_t size, gfp_t gfp,return addr; err_mapping: -__free_from_pool (addr, size); +if (coherent_flag ==COHERENT ) +__dma_free_buffer (virt_to_page (addr), size); +else +__free_from_pool (addr, size);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1934/2214 PCI: Fix out-of-bounds MMIO read in nvme_disable_and_flr()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohamad Raizudeen <[email protected]>
[ Upstream commit 6aaa3f42e3410ea8e26c857477260159f724cb1d ]
In nvme_disable_and_flr(), the PCI bar is mapped using NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)
However, the function later reads the controller status from NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte boundary. This violates the API contract.
Fix this by increasing the mapping size to include NVME_REG_CSTS. Also change sizeof(cfg) to sizeof(u32) to make the intent clearer.
--- drivers/pci/quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/quirks.c +1 -1
@@ -3957,7 +3957,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)if (probe)return 0 ; - bar =pci_iomap (dev,0 ,NVME_REG_CC +sizeof (cfg)); + bar =pci_iomap (dev,0 ,NVME_REG_CSTS +sizeof (u32));if (!bar)return -ENOTTY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1935/2214 Bluetooth: L2CAP: hold chan in l2cap_ecred_conn_rsp()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit b508a2a2d846ccc4c8f691e4e3dfca6f97dfe85a ]
l2cap_chan_del() calls l2cap_chan_put() to drop the conn->chan_l reference. If this was the last reference, UAF follows.
l2cap_ecred_conn_rsp() iterates chan_l list and calls l2cap_chan_del() on some members, without holding chan reference.
Fix by holding refcount while using chan after l2cap_chan_del().
Since orig is looked up by dcid provided by remote, it's also possible orig == chan, so reference needs to be held also after orig use.
--- net/bluetooth/l2cap_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/bluetooth/l2cap_core.c +5 -0
@@ -6385,12 +6385,14 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, chan->state == BT_CONNECTED)continue ; +l2cap_chan_hold (chan);l2cap_chan_lock (chan);/* Check that there is a dcid for each pending channel */ if (cmd_len <sizeof (dcid)) {l2cap_chan_del (chan,ECONNREFUSED );l2cap_chan_unlock (chan); +l2cap_chan_put (chan);continue ; }
@@ -6429,6 +6431,8 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn,__set_chan_timer (orig,0 );l2cap_chan_unlock (orig); } + +l2cap_chan_put (chan);continue ; }
@@ -6474,6 +6478,7 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, }l2cap_chan_unlock (chan); +l2cap_chan_put (chan); }mutex_unlock (&conn->chan_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1936/2214 Bluetooth: 6LoWPAN: Use RCU-safe device list removal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8c27d7d06e21ba9455ddae4e14f364c57f095cba ]
RCU readers of bt_6lowpan_devices must be able to follow an adapter's forward link until their read-side critical section ends. The entries are published with list_add_rcu(), but device_event() removes an entry on NETDEV_UNREGISTER with list_del(), poisoning that link.
When an adapter is being unregistered and 6LoWPAN is enabled, a 6lowpan_control debugfs write with an existing LE L2CAP connection can enter lookup_peer() after unregister's first synchronize_net(). If the connection has no peer on that adapter, the reader must advance to the next list entry. Neither RTNL nor devices_lock excludes this RCU reader.
The last peer's chan_close_cb() schedules delete_netdev(), which reaches unregister_netdevice_many_notify() through unregister_dev() and lowpan_unregister_netdev(). The following ordering is possible:
Unregister worker Control writer
----------------- --------------
synchronize_net() returns
lowpan_control_write() lookup_peer(): rcu_read_lock() reach adapter; no matching peer
device_event(): devices_lock
list_del(&entry->list)
spin_unlock(&devices_lock)
follow poisoned next link read invalid adapter address
post-notifier synchronize_net()
waits for the reader
This invalid pointer access can fault in lookup_peer(). The first grace period drains existing readers but permits new ones to start, and the later grace period cannot prevent the intervening poisoned-link access.
Use list_del_rcu() under the existing devices_lock to preserve the forward link for readers that already reached the adapter. The existing post-notifier synchronize_net() waits for those readers before netdevice teardown frees the private storage containing lowpan_btle_dev.
KASAN report as below:
[...]
[ 45.867526] Oops: general protection fault, probably for non-canonical address 0xfbd59c0000000023: 0000 [#1] SMP KASAN NOPTI
[ 45.869489] KASAN: maybe wild-memory-access in range [0xdead000000000118-0xdead00000000011f]
[ 45.870981] CPU: 1 UID: 0 PID: 646 Comm: sh Not tainted 7.2.0-rc6-pmb-bt-functional-v1+ #4 PREEMPT(lazy)
[ 45.872609] 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
[ 45.874380] RIP: 0010:lookup_peer+0x1ba/0x320
[ 45.875067] Code: 48 89 d9 ba 04 00 00 00 4c 89 fe bf a0 06 00 00 e8 2b e8 ad fb e9 56 ff ff ff e8 01 1e c3 fb 49 8d 7f 18 48 89 f8 48 c1 e8 03 <80> 3c 28 00 0f 85 4a 01 00 00 4d 8b 47 18 4c 89 f1 ba 04 00 00 00
[ 45.878206] RSP: 0018:ffff888114d67b90 EFLAGS: 00010212
[ 45.879106] RAX: 1bd5a00000000023 RBX: 0000000000000000 RCX: ffffffff85c1d19f
[ 45.880334] RDX: ffff88810dc35700 RSI: 0000000000000000 RDI: dead000000000118
[ 45.881455] RBP: dffffc0000000000 R08: 0000000000000001 R09: 0000000000000001
[ 45.882546] R10: ffffffff893d3057 R11: ffff88810dc35700 R12: ffff88810a690000
[ 45.883839] R13: ffff888115451038 R14: ffff88810a690000 R15: dead000000000100
[ 45.885186] FS: 00007fa889bac780(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000
[ 45.886539] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 45.887527] CR2: 00007ffe304f2f80 CR3: 0000000104f64005 CR4: 0000000000770ef0
[ 45.888687] PKRU: 55555554
[ 45.889183] Call Trace:
[ 45.889666] <TASK>
[ 45.890061] lowpan_control_write+0x445/0x9e0
[ 45.890854] ? __pfx_lowpan_control_write+0x10/0x10
[ 45.891738] ? srso_alias_return_thunk+0x5/0xfbef5
[ 45.892603] ? srso_alias_return_thunk+0x5/0xfbef5
[ 45.893383] ? __debugfs_file_get+0x1bd/0x7f0
[ 45.894057] ? srso_alias_return_thunk+0x5/0xfbef5
[ 45.894902] ? lock_acquire+0x17b/0x2f0
[ 45.895593] ? ksys_write+0x111/0x200
[ 45.896290] full_proxy_write+0x11f/0x180
[ 45.896991] vfs_write+0x25a/0x1010
[ 45.897642] ? __pfx_full_proxy_write+0x10/0x10
[ 45.898440] ? __pfx_vfs_write+0x10/0x10
[ 45.899178] ? lock_release+0x11f/0x280
[ 45.899855] ksys_write+0x111/0x200
[ 45.900435] ? __pfx_ksys_write+0x10/0x10
[ 45.901074] ? irqentry_exit+0xbe/0x820
[ 45.901722] ? srso_alias_return_thunk+0x5/0xfbef5
[ 45.902489] do_syscall_64+0x115/0x6a0
[ 45.903064] entry_SYSCALL_64_after_hwframe+0x77/0x7f
[ 45.903813] RIP: 0033:0x7fa889c3e687
[ 45.904359] 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
[ 45.906981] RSP: 002b:00007ffd7651b960 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
[ 45.908070] RAX: ffffffffffffffda RBX: 00007fa889bac780 RCX: 00007fa889c3e687
[ 45.909102] RDX: 000000000000001c RSI: 00005570f25e8d10 RDI: 0000000000000001
[ 45.910133] RBP: 00005570f25e8d10 R08: 0000000000000000 R09: 0000000000000000
[ 45.911162] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000001
[ 45.912190] R13: 000000000000001c R14: 0000000000000000 R15: 00005570f25e8a78
[ 45.913208] </TASK>
[ 45.913530] Modules linked in:
[ 45.914022] ---[ end trace 0000000000000000 ]---
[ 45.914709] RIP: 0010:lookup_peer+0x1ba/0x320
[ 45.915436] Code: 48 89 d9 ba 04 00 00 00 4c 89 fe bf a0 06 00 00 e8 2b e8 ad fb e9 56 ff ff ff e8 01 1e c3 fb 49 8d 7f 18 48 89 f8 48 c1 e8 03 <80> 3c 28 00 0f 85 4a 01 00 00 4d 8b 47 18 4c 89 f1 ba 04 00 00 00
[ 45.919191] RSP: 0018:ffff888114d67b90 EFLAGS: 00010212
[ 45.920046] RAX: 1bd5a00000000023 RBX: 0000000000000000 RCX: ffffffff85c1d19f
[ 45.921129] RDX: ffff88810dc35700 RSI: 0000000000000000 RDI: dead000000000118
[ 45.922553] RBP: dffffc0000000000 R08: 0000000000000001 R09: 0000000000000001
[ 45.923653] R10: ffffffff893d3057 R11: ffff88810dc35700 R12: ffff88810a690000
[ 45.925119] R13: ffff888115451038 R14: ffff88810a690000 R15: dead000000000100
[ 45.926180] FS: 00007fa889bac780(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000
[ 45.927817] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 45.928726] CR2: 00007ffe304f2f80 CR3: 0000000104f64005 CR4: 0000000000770ef0
[ 45.930069] PKRU: 55555554
[ 45.930456] Kernel panic - not syncing: Fatal exception
[ 45.931542] Kernel Offset: disabled
[ 45.932040] Rebooting in 1 seconds..--- net/bluetooth/6lowpan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/6lowpan.c +1 -1
@@ -1265,7 +1265,7 @@ static int device_event(struct notifier_block *unused,if (entry->netdev == netdev) {BT_DBG ("Unregistered netdev %s %p" , netdev->name, netdev); -list_del (&entry->list); +list_del_rcu (&entry->list);break ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1937/2214 Bluetooth: Add missing newline to bt_dev_{err,warn}_ratelimited()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hitalo Souza <[email protected]>
[ Upstream commit f51ee3bb5fbe9c2019c31befe330bddd3aee39c2 ]
bt_dev_err_ratelimited() and bt_dev_warn_ratelimited() pass the format string to bt_err_ratelimited()/bt_warn_ratelimited() without appending a newline, unlike bt_dev_err() and bt_dev_warn(), which go through BT_ERR()/BT_WARN() and add one. Only 2 of the 22 in-tree callers (both in virtio_bt) put the newline in their own format string.
A printk record without a trailing newline is stored with prb_commit() instead of prb_final_commit(), and readers of the log buffer (/dev/kmsg, syslog) do not see it until it is finalized, which only happens when the next record is reserved. These messages therefore stay invisible until some unrelated message is printed, and journald, which timestamps a record when it reads it, logs them with the time of that later message.
This was observed with a MediaTek MT7921 controller (USB 04ca:3802):
when an eSCO link is closed, the host still receives a few SCO packets for the handle after Disconnection Complete, so hci_scodata_packet() logs "SCO packet for unknown connection handle". Comparing the record's kernel timestamp (_SOURCE_MONOTONIC_TIMESTAMP) with the time journald received it, over one capture:
emitted logged delay 15:36:52.896 15:37:00.214 7.3 s 15:37:03.410 15:39:05.574 122.2 s 15:39:05.574 15:39:12.506 6.9 s 15:39:19.791 15:40:54.109 94.3 s 15:41:22.021 15:41:24.647 2.6 s
Each message showed up together with the next kernel message; the 94 s one looked as if it had been logged in the middle of a later, healthy eSCO connection.
bt_dev_err_ratelimited() lost its newline in commit 657cc646475b ("Bluetooth: Remove usage of BT_ERR_RATELIMITED macro"), which replaced BT_ERR_RATELIMITED(), the variant that appended "\n", with a direct call to bt_err_ratelimited(). bt_dev_warn_ratelimited() never had one.
Append the newline in both macros, as BT_ERR() and BT_WARN() do, and drop it from the two virtio_bt format strings so that their messages do not gain an empty line.
--- drivers/bluetooth/virtio_bt.c | 4 ++-- include/net/bluetooth/bluetooth.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/bluetooth/virtio_bt.c +2 -2
@@ -220,7 +220,7 @@ static void virtbt_rx_handle(struct virtio_bluetooth *vbt, struct sk_buff *skb)if (skb->len < min_hdr) {bt_dev_err_ratelimited (vbt->hdev, -"rx pkt_type 0x%02x payload %u < hdr %zu\n" , +"rx pkt_type 0x%02x payload %u < hdr %zu" , pkt_type, skb->len, min_hdr);kfree_skb (skb);return ;
@@ -243,7 +243,7 @@ static void virtbt_rx_work(struct work_struct *work)if (!len || len >VIRTBT_RX_BUF_SIZE ) {bt_dev_err_ratelimited (vbt->hdev, -"rx reply len %u outside [1, %u]\n" , +"rx reply len %u outside [1, %u]" , len,VIRTBT_RX_BUF_SIZE );kfree_skb (skb); }else {
include/net/bluetooth/bluetooth.h +2 -2
@@ -192,9 +192,9 @@ void bt_err_ratelimited(const char *fmt, ...); BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)#define bt_dev_warn_ratelimited (hdev, fmt, ...) \ - bt_warn_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) + bt_warn_ratelimited("%s: " fmt "\n", bt_dev_name(hdev), ##__VA_ARGS__)#define bt_dev_err_ratelimited (hdev, fmt, ...) \ - bt_err_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) + bt_err_ratelimited("%s: " fmt "\n", bt_dev_name(hdev), ##__VA_ARGS__)/* Connection and socket states */ enum {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1938/2214 Bluetooth: hci_core: Keep RCU protection through LTK filtering
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 817cbcab91fe870e5b69c835cbd708242c9f8c8e ]
The LTK selected by hci_find_ltk() must remain allocated while its value is checked against the blocked-key list. The finder releases RCU before passing k->val to hci_is_blocked_key(). The helper's own RCU section protects the blocked-key list, but the selected LTK may already have been reclaimed before that section starts.
An LE ATT socket security request can reach smp_ltk_encrypt() without holding hdev->lock. With a matching stored LTK and an LTK-type blocked-key entry present, a concurrent MGMT_OP_LOAD_LONG_TERM_KEYS can remove the selected LTK in the following order:
Socket security Management / RCU reclamation
hci_find_ltk()
rcu_read_lock()
select k
rcu_read_unlock()
load_long_term_keys()
hci_dev_lock(hdev)
hci_smp_ltks_clear(hdev)
list_del_rcu(&k->list)
kfree_rcu(k, rcu)
grace period ends; k is freed
hci_is_blocked_key(..., k->val)
memcmp(b->val, val, ...)The final comparison reads freed LTK bytes. Entering a new RCU section in hci_is_blocked_key() cannot protect a pointer obtained before the completed grace period.
Keep the finder's RCU read-side section active through the blocked-key comparison and the warning that reads k->bdaddr. Release it before returning on either matched-key path. This delays reclamation until the finder has finished using the selected record, following the existing IRK lookup pattern.
KFENCE report as below:
==================================================================
BUG: KFENCE: use-after-free read in hci_is_blocked_key+0xdf/0x240
Use-after-free read at 0x00000000b9ee38e4 (in kfence-#249):
hci_is_blocked_key+0xdf/0x240
blocked_key_wrapper+0xc5/0x140 [pmbd_ltk_probe]
hci_find_ltk+0x1aa/0x3e0
smp_ltk_encrypt.isra.0+0xad/0x340
smp_conn_security+0x3b8/0x8c0
l2cap_sock_setsockopt+0x1c4b/0x2270
do_sock_setsockopt+0x1fb/0x430
__sys_setsockopt+0x106/0x180
__x64_sys_setsockopt+0xc2/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
kfence-#249: 0x00000000121f2ad9-0x000000005b5bfb3d, size=72, cache=kmalloc-96
allocated by task 495 on cpu 0 at 36.722380s (2.603973s ago):
hci_add_ltk+0x1f5/0x3a0
load_long_term_keys+0x6d0/0x860
hci_sock_sendmsg+0x128b/0x22e0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
freed by task 533 on cpu 0 at 36.993097s (2.339769s ago):
__rcu_free_sheaf_prepare+0x261/0x2a0
rcu_free_sheaf+0x1f/0xe0
rcu_core+0x661/0x1d10
handle_softirqs+0x201/0x930
__irq_exit_rcu+0x110/0x1e0
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x6c/0x80
asm_sysvec_apic_timer_interrupt+0x1a/0x20
srso_alias_return_thunk+0x0/0xfbef5
__asan_memcpy+0x23/0x60
create_monitor_ctrl_event+0x1a2/0x460
mgmt_cmd_complete+0x2da/0x580
load_long_term_keys+0x741/0x860
hci_sock_sendmsg+0x128b/0x22e0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
CPU: 1 UID: 0 PID: 495 Comm: python3 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
==================================================================--- net/bluetooth/hci_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/hci_core.c +2 -2
@@ -2390,16 +2390,16 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,continue ;if (smp_ltk_is_sc (k) ||ltk_role (k->type) == role) { -rcu_read_unlock (); -if (hci_is_blocked_key (hdev,HCI_BLOCKED_KEY_TYPE_LTK , k->val)) {bt_dev_warn_ratelimited (hdev,"LTK blocked for %pMR" , &k->bdaddr); +rcu_read_unlock ();return NULL ; } +rcu_read_unlock ();return k; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1939/2214 Bluetooth: 6lowpan: Drain RCU readers on registration failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit ebba800d140b580540ad55f670d943e4a7edaffd ]
A lowpan_btle_dev is embedded in its net_device allocation and must remain alive until readers of bt_6lowpan_devices have left their RCU sections. setup_netdev() publishes it before registration, but its error path only unlinks it before calling free_netdev().
If a second controller's registration fails while multicast is sent on an existing 6LoWPAN interface, send_mcast_pkt() can already have selected the new entry. It reads entry->netdev before checking which interface owns it. An early failure, such as allocating the device's name node, leaves NETREG_UNINITIALIZED, so free_netdev() releases the storage immediately.
The following ordering frees the selected entry before the reader loads its netdev field:
Adapter creation (controller B) Multicast on controller A
setup_netdev()
list_add_rcu()
rcu_read_lock()
select B's entry
lowpan_register_netdev() fails
list_del_rcu()
free_netdev()
read entry->netdev
rcu_read_unlock()Removing the list node does not wait for that reader, and devices_lock does not serialize the multicast reader. The subsequent field load is a use-after-free, reported by KASAN in bt_xmit().
Wait for an RCU grace period after dropping devices_lock and before free_netdev(). This keeps the failed adapter allocated until traversals that could have selected it complete. The callback is already sleepable, and the wait happens outside the list spinlock.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in bt_xmit+0x1d06/0x21e0
Read of size 8 at addr ffff88810ef45030 by task python3/556
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? bt_xmit+0x1d06/0x21e0
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? bt_xmit+0x1d06/0x21e0
kasan_report+0xe0/0x110
? bt_xmit+0x1d06/0x21e0
bt_xmit+0x1d06/0x21e0
? __pfx_bt_xmit+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_acquire+0x17b/0x2f0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? dev_hard_start_xmit+0x187/0x660
? __pfx_bt_xmit+0x10/0x10
dev_hard_start_xmit+0x187/0x660
sch_direct_xmit+0x153/0x850
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_sch_direct_xmit+0x10/0x10
? do_raw_spin_lock+0x130/0x270
? __pfx_do_raw_spin_lock+0x10/0x10
? lock_is_held_type+0x8f/0x100
__dev_queue_xmit+0x3111/0x3aa0
? srso_alias_return_thunk+0x5/0xfbef5
? look_up_lock_class+0x59/0x130
? register_lock_class+0x41/0x790
? __pfx___dev_queue_xmit+0x10/0x10
? __lock_acquire+0x466/0x2260
? find_held_lock+0x2b/0x80
? ___neigh_create+0x1690/0x2540
? __local_bh_enable_ip+0xa6/0x120
? srso_alias_return_thunk+0x5/0xfbef5
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_acquire+0x17b/0x2f0
? srso_alias_return_thunk+0x5/0xfbef5
? find_held_lock+0x2b/0x80
? ip6_finish_output2+0x8be/0x1840
? srso_alias_return_thunk+0x5/0xfbef5
? neigh_connected_output+0x39f/0x4e0
? srso_alias_return_thunk+0x5/0xfbef5
neigh_connected_output+0x33f/0x4e0
ip6_finish_output2+0x8be/0x1840
ip6_finish_output+0x424/0xd50
ip6_output+0x210/0x640
? __pfx_ip6_mr_output+0x10/0x10
ip6_local_out+0x193/0x1c0
ip6_send_skb+0xfb/0x3e0
udp_v6_send_skb+0x6e1/0x1180
udpv6_sendmsg+0x1f9b/0x2a00
? get_random_u32+0xaf/0x640
? __pfx_udpv6_sendmsg+0x10/0x10
? lock_release+0xc8/0x280
? srso_alias_return_thunk+0x5/0xfbef5
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
? srso_alias_return_thunk+0x5/0xfbef5
? __local_bh_enable_ip+0xa6/0x120
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_udpv6_sendmsg+0x10/0x10
? inet6_sendmsg+0xff/0x140
inet6_sendmsg+0xff/0x140
__sys_sendto+0x320/0x470
? __pfx___sys_sendto+0x10/0x10
? exc_page_fault+0x5c/0xc0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
? handle_mm_fault+0x12e/0x580
__x64_sys_sendto+0xe5/0x1c0
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Allocated by task 502:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kvmalloc_node_noprof+0x353/0x930
alloc_netdev_mqs+0xa0/0x1250
chan_ready_cb+0x198/0x1110
l2cap_recv_frame+0x6dc0/0x8830
l2cap_recv_acldata+0xe9f/0x10e0
hci_rx_work+0x5a6/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
Freed by task 502:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
free_netdev+0x6ca/0x8f0
chan_ready_cb+0xd91/0x1110
l2cap_recv_frame+0x6dc0/0x8830
l2cap_recv_acldata+0xe9f/0x10e0
hci_rx_work+0x5a6/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
The buggy address belongs to the object at ffff88810ef44000
which
belongs to the cache kmalloc-8k of size
8192
The buggy address is located 4144 bytes inside of
freed
8192-byte region [ffff88810ef44000,
ffff88810ef46000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0
pfn:0x10ef40
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff888100043180 dead000000000100
dead000000000122
raw: 0000000000000000 0000000000020002 00000000f5000000
0000000000000000
head: 0200000000000040 ffff888100043180 dead000000000100
dead000000000122
head: 0000000000000000 0000000000020002 00000000f5000000
0000000000000000
head: 0200000000000003 fffffffffffffe01 00000000ffffffff
00000000ffffffff
head: ffff88810ef41a80 0000000000000000 00000000ffffffff
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88810ef44f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810ef44f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88810ef45000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88810ef45080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810ef45100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Disabling lock debugging due to kernel taint--- net/bluetooth/6lowpan.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/6lowpan.c +1 -0
@@ -704,6 +704,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)spin_lock (&devices_lock);list_del_rcu (&(*dev)->list);spin_unlock (&devices_lock); +synchronize_rcu ();free_netdev (netdev); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1940/2214 Bluetooth: btintel: propagate version TLV parsing errors
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
[ Upstream commit 3a74624b5deae7f5e2b98e638687fbf9594a9781 ]
btintel_read_version_tlv() ignores the parser return value, so setup continues with partially initialized version data after a malformed TLV causes parsing to stop.
Return the parser error to the caller so an invalid response fails setup instead of being treated as successful. Keep this behavioral change separate from the bounds checks so it can be reverted independently if an existing controller sends malformed data.
Stable-dep-of: cf87709d7ff8 ("Bluetooth: btintel: Zero version data before parsing TLVs")
--- drivers/bluetooth/btintel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/bluetooth/btintel.c +3 -2
@@ -620,6 +620,7 @@ static int btintel_read_version_tlv(struct hci_dev *hdev, {struct sk_buff *skb;const u8 param[1 ] = {0xFF }; +int err;if (!version)return -EINVAL ;
@@ -638,10 +639,10 @@ static int btintel_read_version_tlv(struct hci_dev *hdev,return -EIO ; } -btintel_parse_version_tlv (hdev, version, skb); + err =btintel_parse_version_tlv (hdev, version, skb);kfree_skb (skb); -return 0 ; +return err; }/* ------- REGMAP IBT SUPPORT ------- */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1941/2214 Bluetooth: btintel: Zero version data before parsing TLVs
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiran K <[email protected]>
[ Upstream commit cf87709d7ff83b4de5d42b61e4a9806fe374cb9d ]
Firmware may omit optional TLVs, leaving their corresponding fields unset in the caller-supplied struct intel_version_tlv. Since the structure is typically stack-allocated and not cleared beforehand, fields for which no TLV is received retain uninitialized stack memory. This stale data can be logged via btintel_version_info_tlv() and copied back to the caller, leaking kernel stack contents.
Clear the structure in btintel_read_version_tlv() before parsing so that fields with no corresponding TLV are deterministically zero instead of containing garbage.
--- drivers/bluetooth/btintel.c | 1 + 1 file changed, 1 insertion(+)
drivers/bluetooth/btintel.c +1 -0
@@ -639,6 +639,7 @@ static int btintel_read_version_tlv(struct hci_dev *hdev,return -EIO ; } +memset (version,0 ,sizeof (*version)); err =btintel_parse_version_tlv (hdev, version, skb);kfree_skb (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1942/2214 net: selftests: use skb_share_check() in the loopback receive hook
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit fbd3a301b1378423a5cfc23a42e3c0b04e26192c ]
The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_unshare() does not unshare it, so skb_linearize() on a non-linear frame hits BUG_ON(skb_shared()).
Use skb_share_check() instead.
--- net/core/selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/selftests.c +1 -1
@@ -190,7 +190,7 @@ static int net_test_loopback_validate(struct sk_buff *skb,struct tcphdr *thdr;struct iphdr *ihdr; - skb =skb_unshare (skb,GFP_ATOMIC ); + skb =skb_share_check (skb,GFP_ATOMIC );if (!skb) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1943/2214 net: stmmac: selftests: use skb_share_check() in the loopback receive hook
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit a7a89019bac0e8810bde7f1419f4adf9adc23d41 ]
The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_unshare() does not unshare it, so skb_linearize() on a non-linear frame hits BUG_ON(skb_shared()).
Use skb_share_check() instead.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -1
@@ -262,7 +262,7 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb,struct tcphdr *thdr;struct iphdr *ihdr; - skb =skb_unshare (skb,GFP_ATOMIC ); + skb =skb_share_check (skb,GFP_ATOMIC );if (!skb) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1944/2214 net/mlx5e: use skb_share_check() in the loopback selftest hook
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 16fb7aa6955a0af9f67ca42a61d9be58dfc9382a ]
The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_linearize() on a non-linear frame then hits BUG_ON(skb_shared()).
Call skb_share_check() before linearizing the skb.
--- drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c +4 -0
@@ -188,6 +188,10 @@ mlx5e_test_loopback_validate(struct sk_buff *skb,struct udphdr *udph;struct iphdr *iph; + skb =skb_share_check (skb,GFP_ATOMIC ); +if (!skb) + goto out; +if (skb_linearize (skb)) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1945/2214 scsi: libsas: Fix out-of-bounds memcpy() in sas_ssp_task_response()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xingui Yang <[email protected]>
[ Upstream commit 4d7f9c3fdce773f6c69d17c1d4a05bd5e17f4b99 ]
The min_t(int, ...) clamp of the device-provided sense_data_len turns negative for values >= 0x80000000 and is then used as the memcpy() length, reading and writing out of bounds. Compare as u32 instead. Well-formed responses are unaffected.
--- drivers/scsi/libsas/sas_task.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/libsas/sas_task.c +1 -1
@@ -22,7 +22,7 @@ void sas_ssp_task_response(struct device *dev, struct sas_task *task,else if (iu->datapres ==2 ) { tstat->stat =SAS_SAM_STAT_CHECK_CONDITION ; tstat->buf_valid_size = -min_t (int,SAS_STATUS_BUF_SIZE , +min_t (u32,SAS_STATUS_BUF_SIZE ,be32_to_cpu (iu->sense_data_len));memcpy (tstat->buf, iu->sense_data, tstat->buf_valid_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1946/2214 dt-bindings: vendor-prefixes: add Ambarella
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Long Zhao <[email protected]>
[ Upstream commit 5ef299ffb56531b3a4f2b311000da76beed403ee ]
Document the Ambarella, Inc. vendor prefix so Ambarella DT bindings can be applied without waiting for the SoC series.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -83,6 +83,8 @@ patternProperties: description: Amarula Solutions "^amazon,.*": description: Amazon.com, Inc. + "^ambarella,.*": + description: Ambarella, Inc. "^amcc,.*": description: Applied Micro Circuits Corporation (APM, formally AMCC) "^amd,.*":
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1947/2214 ata: libahci: re-enable FBS after error handling on a port multiplier
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyrylo Biryuk <[email protected]>
[ Upstream commit 23eab9e877497397a0e2394ee9174d576816209e ]
ahci_do_softreset() disables FBS before resetting a device behind a port multiplier, as required by AHCI 1.2 section 9.3.9, and re-enables it only when that softreset succeeds. If it fails, for example because a hot-plugged drive is still spinning up ("softreset failed (device not ready)"), EH escalates to a hardreset of the PMP link, and nothing turns FBS back on: only ahci_pmp_attach() does, which runs at the next boot. The port keeps working with command-based switching until then.
Seen on a Marvell 88SE9235 (1b4b:9235) with Marvell 88SM9705 port multipliers (1b4b:9705, in a Synology DX1222 expansion unit): after hot-plugging a drive, the kernel logged "FBS is disabled" followed by "softreset failed (device not ready)" and a PMP hardreset, and never "FBS is enabled" again (twice, on two different ports).
At the end of ahci_error_handler(), re-enable FBS if a PMP is still attached and FBS is supported but disabled.
--- drivers/ata/libahci.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/ata/libahci.c +15 -0
@@ -2096,6 +2096,21 @@ void ahci_error_handler(struct ata_port *ap)sata_pmp_error_handler (ap); +/* +* ahci_do_softreset() turns FBS off before resetting a fan-out link +* and turns it back on only if that reset succeeds. When it fails +* (e.g. a hot-plugged drive is still spinning up), EH escalates to a +* PMP hardreset, which never re-enables FBS, so the port would keep +* command-based switching until the PMP is attached again (reboot). +* Restore FBS once recovery is done and the PMP is still attached. +*/ +if (sata_pmp_attached (ap) &&ata_dev_enabled (ap->link.device)) { +struct ahci_port_priv *pp = ap->private_data; + +if (pp->fbs_supported && !pp->fbs_enabled) +ahci_enable_fbs (ap); + } +if (!ata_dev_enabled (ap->link.device)) hpriv->stop_engine (ap); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1948/2214 net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sagi Maimon <[email protected]>
[ Upstream commit 0c20cb4cfb40cf270d6c4c2c2ff5e5d72322644a ]
axienet_dma_bd_release() walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring with dma_free_coherent() alone. Any descriptor that axienet_free_tx_chain() had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop() disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up to lp->tx_bd_num skbs and mappings each time.
axienet_dma_err_handler() already walks the TX ring this way before it restarts the DMA engine: it unmaps every descriptor whose cntrl is still set - axienet_free_tx_chain() clears it on reclaim - frees any skb still attached, and clears the descriptor. Move that loop into a helper, axienet_free_tx_bufs(), and call it from axienet_dma_bd_release() too. This relies on axienet_stop() having stopped the DMA engine first, as the RX walk in the same function already does. The helper frees the skbs with dev_kfree_skb_any(), as drops: in the error handler, which runs from a workqueue, that frees them directly rather than deferring them to softirq as dev_kfree_skb_irq() did.
The walk must not run on a ring that is not there. axienet_open() does not check the result of the reset that runs axienet_dma_bd_init(), so when that reset fails tx_bd_v is either still NULL or, after an earlier close, points at the ring that close freed. Clear tx_bd_v and rx_bd_v once their rings are freed, and skip the walk when tx_bd_v is NULL. That also ends the second dma_free_coherent() of a stale ring which the same path already did. On the axienet_dma_bd_init() error path the TX ring has just been allocated zeroed, so the walk does nothing.
This was reported by the Sashiko AI review bot.
Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and neither the failed-reset paths nor axienet_dma_err_handler() were exercised.
--- .../net/ethernet/xilinx/xilinx_axienet_main.c | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +50 -24
@@ -176,6 +176,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp,return ret; } +/** +* axienet_free_tx_bufs - Release the buffers still held by the TX ring +* @lp: Pointer to the axienet_local structure +* +* Unmap every descriptor whose mapping is still live, free any skb still +* attached, and clear the descriptor for reuse. axienet_free_tx_chain() +* clears cntrl when it reclaims a descriptor, so a non-zero value means +* the mapping is live. The DMA engine must be stopped. +*/ +static void axienet_free_tx_bufs (struct axienet_local *lp) +{ +struct axidma_bd *cur_p; +u32 i; + +for (i =0 ; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i]; +if (cur_p->cntrl) { +dma_addr_t addr =desc_get_phys_addr (lp, cur_p); + +dma_unmap_single (lp->dev, addr, + (cur_p->cntrl & +XAXIDMA_BD_CTRL_LENGTH_MASK ), +DMA_TO_DEVICE ); + } +/* not reclaimed by axienet_free_tx_chain(), so a drop */ +if (cur_p->skb) +dev_kfree_skb_any (cur_p->skb); + cur_p->phys =0 ; + cur_p->phys_msb =0 ; + cur_p->cntrl =0 ; + cur_p->status =0 ; + cur_p->app0 =0 ; + cur_p->app1 =0 ; + cur_p->app2 =0 ; + cur_p->app3 =0 ; + cur_p->app4 =0 ; + cur_p->skb =NULL ; + } +} +/** * axienet_dma_bd_release - Release buffer descriptor rings * @ndev: Pointer to the net_device structure
@@ -189,11 +229,18 @@ static void axienet_dma_bd_release(struct net_device *ndev)int i;struct axienet_local *lp =netdev_priv (ndev); -/* If we end up here, tx_bd_v must have been DMA allocated. */ +/* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as +* allocating it, and is cleared below once the ring is freed; +* dma_free_coherent() accepts NULL. +*/ +if (lp->tx_bd_v) +axienet_free_tx_bufs (lp); +dma_free_coherent (lp->dev,sizeof (*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v =NULL ;if (!lp->rx_bd_v)return ;
@@ -224,6 +271,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }/**
@@ -1864,29 +1912,7 @@ static void axienet_dma_err_handler(struct work_struct *work)axienet_dma_stop (lp); -for (i =0 ; i < lp->tx_bd_num; i++) { - cur_p = &lp->tx_bd_v[i]; -if (cur_p->cntrl) { -dma_addr_t addr =desc_get_phys_addr (lp, cur_p); - -dma_unmap_single (lp->dev, addr, - (cur_p->cntrl & -XAXIDMA_BD_CTRL_LENGTH_MASK ), -DMA_TO_DEVICE ); - } -if (cur_p->skb) -dev_kfree_skb_irq (cur_p->skb); - cur_p->phys =0 ; - cur_p->phys_msb =0 ; - cur_p->cntrl =0 ; - cur_p->status =0 ; - cur_p->app0 =0 ; - cur_p->app1 =0 ; - cur_p->app2 =0 ; - cur_p->app3 =0 ; - cur_p->app4 =0 ; - cur_p->skb =NULL ; - } +axienet_free_tx_bufs (lp);for (i =0 ; i < lp->rx_bd_num; i++) { cur_p = &lp->rx_bd_v[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1949/2214 IB/IPoIB: Cancel normal flush work on device stop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 66196a559be5963b1ced18418c876caf9bfb76e6 ]
ipoib_ib_dev_flush_normal() can race with ipoib_stop() because the normal flush work does not run under RTNL.
Before commit a77a57a1a22a ("IPoIB: Fix deadlock on RTNL in ipoib_stop()"), ipoib_stop() flushed ipoib_workqueue after clearing IPOIB_FLAG_ADMIN_UP and before calling ipoib_ib_dev_down(). This ensured that any in-flight flush work completed before ipoib_ib_dev_down() performed the final clear of IPOIB_FLAG_OPER_UP.
After that commit removed the workqueue flush to avoid a deadlock with workqueue tasks taking RTNL, a normal flush can continue running concurrently with ipoib_stop() after IPOIB_FLAG_ADMIN_UP has been cleared.
The flush may observe IPOIB_FLAG_ADMIN_UP set and continue running while ipoib_stop() clears IPOIB_FLAG_ADMIN_UP and brings the device down. The flush can then call ipoib_ib_dev_up() and set IPOIB_FLAG_OPER_UP again after the device has already been stopped:
flush_normal (ipoib_workqueue) ipoib_stop() (RTNL held)
------------------------------ ------------------------
test_bit(ADMIN_UP) == 1
clear_bit(ADMIN_UP)
ipoib_ib_dev_down()
clear_bit(OPER_UP) ipoib_ib_dev_up()
set_bit(OPER_UP)
This leaves the interface with ADMIN_UP clear and OPER_UP set. During device removal, ipoib_ndo_uninit() waits in destroy_workqueue() while holding RTNL, while ipoib_mcast_carrier_on_task() may keep retrying rtnl_trylock() as long as OPER_UP remains set, resulting in a deadlock.
Cancel the normal flush work from ipoib_stop() after clearing IPOIB_FLAG_ADMIN_UP and before bringing the device down. A pending normal flush is canceled, while an already running flush is allowed to finish before ipoib_ib_dev_down() performs the final transition to OPER_UP clear.
Only the normal flush needs this synchronization. The heavy flush is already serialized with ipoib_stop() by RTNL, while the light flush does not bring the device back up and therefore cannot recreate this race.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/ulp/ipoib/ipoib_main.c +7 -0
@@ -189,6 +189,13 @@ static int ipoib_stop(struct net_device *dev)clear_bit (IPOIB_FLAG_ADMIN_UP , &priv->flags); +/* Normal flush runs without RTNL and may bring the device back +* up. Cancel it before the device down transition. +* Heavy flush is already serialized by RTNL and must not be +* waited on here while RTNL is held. +*/ +cancel_work_sync (&priv->flush_normal); +netif_stop_queue (dev);ipoib_ib_dev_down (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1950/2214 irqchip/gic-v3-its: Clear vpt_page after freeing the pending table
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 0d604b1e4617d18dbb5573290ba447d7369251d1 ]
its_vpe_teardown() frees vpt_page without clearing it, so its vpt_page == NULL guard only holds the first time it runs on a vPE. struct its_vpe outlives a failed KVM_DEV_ARM_VGIC_CTRL_INIT, so a retry that fails again frees the pending table and the vPE ID a second time.
--- drivers/irqchip/irq-gic-v3-its.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v3-its.c +1 -0
@@ -4475,6 +4475,7 @@ static void its_vpe_teardown(struct its_vpe *vpe)its_vpe_db_proxy_unmap (vpe);its_vpe_id_free (vpe->vpe_id);its_free_pending_table (vpe->vpt_page); + vpe->vpt_page =NULL ; } static void its_vpe_irq_domain_free(struct irq_domain *domain,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1951/2214 irqchip/gic-v3-its: Give the percpu rdist struct its own flags field
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valentin Schneider <[email protected]>
[ Upstream commit c0cdc89072a3e1ae3981437f385de14b7bba8fd8 ]
Later patches will require tracking some per-rdist status. Reuse the bytes "lost" to padding within the __percpu rdist struct as a flags field, and re-encode ->lpi_enabled within said flags.
No change in functionality intended.
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 8 +++++--- include/linux/irqchip/arm-gic-v3.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +5 -3
@@ -46,6 +46,8 @@#define RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING (1 << 0)#define RDIST_FLAGS_RD_TABLES_PREALLOCATED (1 << 1) +#define RD_LOCAL_LPI_ENABLED BIT(0) +static u32 lpi_id_bits;/*
@@ -3086,7 +3088,7 @@ static void its_cpu_init_lpis(void)phys_addr_t paddr;u64 val, tmp; -if (gic_data_rdist ()->lpi_enabled) +if (gic_data_rdist ()->flags &RD_LOCAL_LPI_ENABLED )return ; val =readl_relaxed (rbase +GICR_CTLR );
@@ -3200,7 +3202,7 @@ static void its_cpu_init_lpis(void)/* Make sure the GIC has seen the above */ dsb (sy); out: -gic_data_rdist ()->lpi_enabled = true; +gic_data_rdist ()->flags |=RD_LOCAL_LPI_ENABLED ; pr_info("GICv3: CPU%d: using %s LPI pending table @%pa\n", smp_processor_id(), gic_data_rdist()->pend_page ? "allocated" : "reserved",
@@ -5189,7 +5191,7 @@ static int redist_disable_lpis(void)* * If running with preallocated tables, there is nothing to do. */ -if (gic_data_rdist ()->lpi_enabled || +if ((gic_data_rdist ()->flags &RD_LOCAL_LPI_ENABLED ) || (gic_rdists->flags &RDIST_FLAGS_RD_TABLES_PREALLOCATED ))return 0 ;
include/linux/irqchip/arm-gic-v3.h +1 -1
@@ -616,7 +616,7 @@ struct rdists {void __iomem *rd_base;struct page *pend_page;phys_addr_t phys_base; -bool lpi_enabled; +u64 flags;cpumask_t *vpe_table_mask;void *vpe_l1_base; }__percpu *rdist;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1952/2214 irqchip/gic-v3-its: Postpone LPI pending table freeing and memreserve
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valentin Schneider <[email protected]>
[ Upstream commit d23bc2bc1d634658d7fa96395419c1c553a784f0 ]
Memory used by the LPI tables have to be made persistent for kexec to have a chance to work, as explained in [1]. If they have been made persistent and we are booting into a kexec'd kernel, we also need to free the pages that were preemptively allocated by the new kernel for those tables.
Both of those operations currently happen during its_cpu_init(), which happens in a _STARTING (IOW atomic) cpuhp callback for secondary CPUs. efi_mem_reserve_iomem() issues a GFP_ATOMIC allocation, which unfortunately doesn't work under PREEMPT_RT (this ends up grabbing a non-raw spinlock, which can sleep under PREEMPT_RT). Similarly, freeing the pages ends up grabbing a sleepable spinlock.
Since the memreserve is only required by kexec, it doesn't have to be done so early in the secondary boot process. Issue the reservation in a new CPUHP_AP_ONLINE_DYN cpuhp callback, and piggy-back the page freeing on top of it. A CPU gets to run the body of this new callback exactly once.
As kexec issues a machine_shutdown() prior to machine_kexec(), it will be serialized vs a CPU being plugged to life by the hotplug machinery - either the CPU will have been brought up and have had its redistributor's pending table memreserved, or it never went online and will have its table allocated by the new kernel.
[1]: https://lore.kernel.org/lkml/[email protected]/
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 58 +++++++++++++++++++++++++++--- drivers/irqchip/irq-gic-v3.c | 1 + include/linux/irqchip/arm-gic-v3.h | 1 + 3 files changed, 56 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +54 -4
@@ -47,6 +47,8 @@#define RDIST_FLAGS_RD_TABLES_PREALLOCATED (1 << 1)#define RD_LOCAL_LPI_ENABLED BIT(0) +#define RD_LOCAL_PENDTABLE_PREALLOCATED BIT(1) +#define RD_LOCAL_MEMRESERVE_DONE BIT(2)static u32 lpi_id_bits;
@@ -3107,15 +3109,13 @@ static void its_cpu_init_lpis(void) paddr &=GENMASK_ULL (51 ,16 );WARN_ON (!gic_check_reserved_range (paddr,LPI_PENDBASE_SZ )); -its_free_pending_table (gic_data_rdist ()->pend_page); -gic_data_rdist ()->pend_page =NULL ; +gic_data_rdist ()->flags |=RD_LOCAL_PENDTABLE_PREALLOCATED ; goto out; } pend_page =gic_data_rdist ()->pend_page; paddr =page_to_phys (pend_page); -WARN_ON (gic_reserve_range (paddr,LPI_PENDBASE_SZ ));/* set PROPBASE */ val = (gic_rdists->prop_table_pa |
@@ -3205,7 +3205,8 @@ static void its_cpu_init_lpis(void)gic_data_rdist ()->flags |=RD_LOCAL_LPI_ENABLED ;pr_info ("GICv3: CPU%d: using %s LPI pending table @%pa\n" ,smp_processor_id (), -gic_data_rdist ()->pend_page ?"allocated" :"reserved" , +gic_data_rdist ()->flags &RD_LOCAL_PENDTABLE_PREALLOCATED ? +"reserved" :"allocated" , &paddr); }
@@ -5253,6 +5254,38 @@ int its_cpu_init(void)return 0 ; } +static int its_cpu_memreserve_lpi (unsigned int cpu) +{ +struct page *pend_page; +int ret =0 ; + +/* This gets to run exactly once per CPU */ +if (gic_data_rdist ()->flags &RD_LOCAL_MEMRESERVE_DONE ) +return 0 ; + + pend_page =gic_data_rdist ()->pend_page; +if (WARN_ON (!pend_page)) { + ret = -ENOMEM ; + goto out; + } +/* +* If the pending table was pre-programmed, free the memory we +* preemptively allocated. Otherwise, reserve that memory for +* later kexecs. +*/ +if (gic_data_rdist ()->flags &RD_LOCAL_PENDTABLE_PREALLOCATED ) { +its_free_pending_table (pend_page); +gic_data_rdist ()->pend_page =NULL ; + }else { +phys_addr_t paddr =page_to_phys (pend_page); +WARN_ON (gic_reserve_range (paddr,LPI_PENDBASE_SZ )); + } + +out: +gic_data_rdist ()->flags |=RD_LOCAL_MEMRESERVE_DONE ; +return ret; +} +static const struct of_device_id its_device_id[] = { { .compatible ="arm,gic-v3-its" , }, {},
@@ -5436,6 +5469,23 @@ static void __init its_acpi_probe(void)static void __init its_acpi_probe (void ) { }#endif +int __init its_lpi_memreserve_init (void ) +{ +int state; + +if (!efi_enabled (EFI_CONFIG_TABLES )) +return 0 ; + + state =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN , +"irqchip/arm/gicv3/memreserve:online" , + its_cpu_memreserve_lpi, +NULL ); +if (state <0 ) +return state; + +return 0 ; +} +int __init its_init (struct fwnode_handle *handle,struct rdists *rdists,struct irq_domain *parent_domain) {
drivers/irqchip/irq-gic-v3.c +1 -0
@@ -1877,6 +1877,7 @@ static int __init gic_init_bases(void __iomem *dist_base,if (gic_dist_supports_lpis ()) {its_init (handle, &gic_data.rdists, gic_data.domain);its_cpu_init (); +its_lpi_memreserve_init (); }else {if (IS_ENABLED (CONFIG_ARM_GIC_V2M ))gicv2m_init (handle, gic_data.domain);
include/linux/irqchip/arm-gic-v3.h +1 -0
@@ -633,6 +633,7 @@ struct rdists {struct irq_domain ;struct fwnode_handle ; +int __init its_lpi_memreserve_init (void );int its_cpu_init (void );int its_init (struct fwnode_handle *handle,struct rdists *rdists,struct irq_domain *domain);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1953/2214 irqchip/gic-v3-its: Reset each ITSs BASERn register before probe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit c733ebb7cb67dfb146a07c0ae329a0de9ec52f36 ]
A recent bug report outlined that the way GICv4.1 is handled across kexec is pretty bad. We can end-up in a situation where ITSs share memory (this is the case when SVPET==1) and reprogram the base registers, creating a situation where ITSs that are part of a given affinity group see different pointers. Which is illegal. Boo.
In order to restore some sanity, reset the BASERn registers to 0 *before* probing any ITS. Although this isn't optimised at all, this is only a once-per-boot cost, which shouldn't show up on anyone's radar.
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 120 +++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 21 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +99 -21
@@ -4905,6 +4905,38 @@ static struct syscore_ops its_syscore_ops = { .resume = its_restore_enable, }; +static void __init __iomem *its_map_one (struct resource *res,int *err) +{ +void __iomem *its_base; +u32 val; + + its_base =ioremap (res->start,SZ_64K ); +if (!its_base) { +pr_warn ("ITS@%pa: Unable to map ITS registers\n" , &res->start); + *err = -ENOMEM ; +return NULL ; + } + + val =readl_relaxed (its_base +GITS_PIDR2 ) &GIC_PIDR2_ARCH_MASK ; +if (val !=0x30 && val !=0x40 ) { +pr_warn ("ITS@%pa: No ITS detected, giving up\n" , &res->start); + *err = -ENODEV ; + goto out_unmap; + } + + *err =its_force_quiescent (its_base); +if (*err) { +pr_warn ("ITS@%pa: Failed to quiesce, giving up\n" , &res->start); + goto out_unmap; + } + +return its_base; + +out_unmap: +iounmap (its_base); +return NULL ; +} +static int its_init_domain (struct fwnode_handle *handle,struct its_node *its) {struct irq_domain *inner_domain;
@@ -5012,29 +5044,14 @@ static int __init its_probe_one(struct resource *res, {struct its_node *its;void __iomem *its_base; -u32 val, ctlr;u64 baser, tmp, typer;struct page *page; +u32 ctlr;int err; - its_base =ioremap (res->start,SZ_64K ); -if (!its_base) { -pr_warn ("ITS@%pa: Unable to map ITS registers\n" , &res->start); -return -ENOMEM ; - } - - val =readl_relaxed (its_base +GITS_PIDR2 ) &GIC_PIDR2_ARCH_MASK ; -if (val !=0x30 && val !=0x40 ) { -pr_warn ("ITS@%pa: No ITS detected, giving up\n" , &res->start); - err = -ENODEV ; - goto out_unmap; - } - - err =its_force_quiescent (its_base); -if (err) { -pr_warn ("ITS@%pa: Failed to quiesce, giving up\n" , &res->start); - goto out_unmap; - } + its_base =its_map_one (res, &err); +if (!its_base) +return err;pr_info ("ITS %pR\n" , res);
@@ -5286,6 +5303,23 @@ static int its_cpu_memreserve_lpi(unsigned int cpu)return ret; } +/* Mark all the BASER registers as invalid before they get reprogrammed */ +static int __init its_reset_one (struct resource *res) +{ +void __iomem *its_base; +int err, i; + + its_base =its_map_one (res, &err); +if (!its_base) +return err; + +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) +gits_write_baser (0 , its_base +GITS_BASER + (i <<3 )); + +iounmap (its_base); +return 0 ; +} +static const struct of_device_id its_device_id[] = { { .compatible ="arm,gic-v3-its" , }, {},
@@ -5296,6 +5330,26 @@ static int __init its_of_probe(struct device_node *node)struct device_node *np;struct resource res; +/* +* Make sure *all* the ITS are reset before we probe any, as +* they may be sharing memory. If any of the ITS fails to +* reset, don't even try to go any further, as this could +* result in something even worse. +*/ +for (np =of_find_matching_node (node, its_device_id); np; + np =of_find_matching_node (np, its_device_id)) { +int err; + +if (!of_device_is_available (np) || + !of_property_read_bool (np,"msi-controller" ) || +of_address_to_resource (np,0 , &res)) +continue ; + + err =its_reset_one (&res); +if (err) +return err; + } +for (np =of_find_matching_node (node, its_device_id); np; np =of_find_matching_node (np, its_device_id)) {if (!of_device_is_available (np))
@@ -5458,11 +5512,35 @@ static int __init gic_acpi_parse_madt_its(union acpi_subtable_headers *header, return err; } +static int __init its_acpi_reset (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_madt_generic_translator *its_entry; +struct resource res; + + its_entry = (struct acpi_madt_generic_translator *)header; + res = (struct resource ) { + .start = its_entry->base_address, + .end = its_entry->base_address +ACPI_GICV3_ITS_MEM_SIZE -1 , + .flags =IORESOURCE_MEM , + }; + +return its_reset_one (&res); +} +static void __init its_acpi_probe (void ) {acpi_table_parse_srat_its (); -acpi_table_parse_madt (ACPI_MADT_TYPE_GENERIC_TRANSLATOR , - gic_acpi_parse_madt_its,0 ); +/* +* Make sure *all* the ITS are reset before we probe any, as +* they may be sharing memory. If any of the ITS fails to +* reset, don't even try to go any further, as this could +* result in something even worse. +*/ +if (acpi_table_parse_madt (ACPI_MADT_TYPE_GENERIC_TRANSLATOR , + its_acpi_reset,0 ) >0 ) +acpi_table_parse_madt (ACPI_MADT_TYPE_GENERIC_TRANSLATOR , + gic_acpi_parse_madt_its,0 );acpi_its_srat_maps_free (); }#else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1954/2214 irqchip/gic-v3-its: Use irq_domain_create_hierarchy()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 1e46e040decede1723a5b11f0689942134c29d9a ]
Use the irq_domain_create_hierarchy() helper to create the hierarchical domain, which both serves as documentation and avoids poking at irqdomain internals.
Note that the domain host_data was first set to the struct its_node during allocation only to immediately be overwritten with the struct msi_domain_info.
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +7 -6
@@ -4946,18 +4946,19 @@ static int its_init_domain(struct fwnode_handle *handle, struct its_node *its)if (!info)return -ENOMEM ; - inner_domain =irq_domain_create_tree (handle, &its_domain_ops, its); + info->ops = &its_msi_domain_ops; + info->data = its; + + inner_domain =irq_domain_create_hierarchy (its_parent, + its->msi_domain_flags,0 , + handle, &its_domain_ops, + info);if (!inner_domain) {kfree (info);return -ENOMEM ; } - inner_domain->parent = its_parent;irq_domain_update_bus_token (inner_domain,DOMAIN_BUS_NEXUS ); - inner_domain->flags |= its->msi_domain_flags; - info->ops = &its_msi_domain_ops; - info->data = its; - inner_domain->host_data = info;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1955/2214 irqchip/gic-v3-its: Split allocation from initialisation of its_node
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 9585a495ac936049dba141e8f9d99159ca06d46a ]
In order to pave the way for more fancy quirk handling without making more of a mess of this terrible driver, split the allocation of the ITS descriptor (its_node) from the actual probing.
This will allow firmware-specific hooks to be added between these two points.
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 149 ++++++++++++++++++------------- 1 file changed, 89 insertions(+), 60 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +89 -60
@@ -4937,7 +4937,7 @@ static void __init __iomem *its_map_one(struct resource *res, int *err)return NULL ; } -static int its_init_domain (struct fwnode_handle *handle,struct its_node *its) +static int its_init_domain (struct its_node *its) {struct irq_domain *inner_domain;struct msi_domain_info *info;
@@ -4951,7 +4951,7 @@ static int its_init_domain(struct fwnode_handle *handle, struct its_node *its) inner_domain =irq_domain_create_hierarchy (its_parent, its->msi_domain_flags,0 , - handle, &its_domain_ops, + its->fwnode_handle, &its_domain_ops, info);if (!inner_domain) {kfree (info);
@@ -5002,8 +5002,7 @@ static int its_init_vpe_domain(void)return 0 ; } -static int __init its_compute_its_list_map (struct resource *res, -void __iomem *its_base) +static int __init its_compute_its_list_map (struct its_node *its) {int its_number;u32 ctlr;
@@ -5017,15 +5016,15 @@ static int __init its_compute_its_list_map(struct resource *res, its_number =find_first_zero_bit (&its_list_map, GICv4_ITS_LIST_MAX);if (its_number >= GICv4_ITS_LIST_MAX) {pr_err ("ITS@%pa: No ITSList entry available!\n" , - &res->start); + &its->phys_base);return -EINVAL ; } - ctlr =readl_relaxed (its_base +GITS_CTLR ); + ctlr =readl_relaxed (its->base +GITS_CTLR ); ctlr &= ~GITS_CTLR_ITS_NUMBER ; ctlr |= its_number <<GITS_CTLR_ITS_NUMBER_SHIFT ; -writel_relaxed (ctlr, its_base +GITS_CTLR ); - ctlr =readl_relaxed (its_base +GITS_CTLR ); +writel_relaxed (ctlr, its->base +GITS_CTLR ); + ctlr =readl_relaxed (its->base +GITS_CTLR );if ((ctlr &GITS_CTLR_ITS_NUMBER ) != (its_number <<GITS_CTLR_ITS_NUMBER_SHIFT )) { its_number = ctlr &GITS_CTLR_ITS_NUMBER ; its_number >>=GITS_CTLR_ITS_NUMBER_SHIFT ;
@@ -5033,75 +5032,50 @@ static int __init its_compute_its_list_map(struct resource *res,if (test_and_set_bit (its_number, &its_list_map)) {pr_err ("ITS@%pa: Duplicate ITSList entry %d\n" , - &res->start, its_number); + &its->phys_base, its_number);return -EINVAL ; }return its_number; } -static int __init its_probe_one (struct resource *res, -struct fwnode_handle *handle,int numa_node) +static int __init its_probe_one (struct its_node *its) { -struct its_node *its; -void __iomem *its_base; -u64 baser, tmp, typer; +u64 baser, tmp;struct page *page;u32 ctlr;int err; - its_base =its_map_one (res, &err); -if (!its_base) -return err; - -pr_info ("ITS %pR\n" , res); - - its =kzalloc (sizeof (*its),GFP_KERNEL ); -if (!its) { - err = -ENOMEM ; - goto out_unmap; - } - -raw_spin_lock_init (&its->lock); -mutex_init (&its->dev_alloc_lock); -INIT_LIST_HEAD (&its->entry); -INIT_LIST_HEAD (&its->its_device_list); - typer =gic_read_typer (its_base +GITS_TYPER ); - its->typer = typer; - its->base = its_base; - its->phys_base = res->start;if (is_v4 (its)) { -if (!(typer &GITS_TYPER_VMOVP )) { - err =its_compute_its_list_map (res, its_base); +if (!(its->typer &GITS_TYPER_VMOVP )) { + err =its_compute_its_list_map (its);if (err <0 ) - goto out_free_its; + goto out; its->list_nr = err;pr_info ("ITS@%pa: Using ITS number %d\n" , - &res->start, err); + &its->phys_base, err); }else { -pr_info ("ITS@%pa: Single VMOVP capable\n" , &res->start); +pr_info ("ITS@%pa: Single VMOVP capable\n" , &its->phys_base); }if (is_v4_1 (its)) { -u32 svpet =FIELD_GET (GITS_TYPER_SVPET , typer); +u32 svpet =FIELD_GET (GITS_TYPER_SVPET , its->typer); - its->sgir_base =ioremap (res->start +SZ_128K ,SZ_64K ); + its->sgir_base =ioremap (its->phys_base +SZ_128K ,SZ_64K );if (!its->sgir_base) { err = -ENOMEM ; - goto out_free_its; + goto out; } - its->mpidr =readl_relaxed (its_base +GITS_MPIDR ); + its->mpidr =readl_relaxed (its->base +GITS_MPIDR );pr_info ("ITS@%pa: Using GICv4.1 mode %08x %08x\n" , - &res->start, its->mpidr, svpet); + &its->phys_base, its->mpidr, svpet); } } - its->numa_node = numa_node; - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO,get_order (ITS_CMD_QUEUE_SZ ));if (!page) {
@@ -5110,12 +5084,9 @@ static int __init its_probe_one(struct resource *res, } its->cmd_base = (void *)page_address (page); its->cmd_write = its->cmd_base; - its->fwnode_handle = handle; its->get_msi_base = its_irq_get_msi_base; its->msi_domain_flags =IRQ_DOMAIN_FLAG_MSI_REMAP ; -its_enable_quirks (its); - err =its_alloc_tables (its);if (err) goto out_free_cmd;
@@ -5156,7 +5127,7 @@ static int __init its_probe_one(struct resource *res, ctlr |= GITS_CTLR_ImDe;writel_relaxed (ctlr, its->base +GITS_CTLR ); - err =its_init_domain (handle, its); + err =its_init_domain (its);if (err) goto out_free_collection;
@@ -5175,11 +5146,8 @@ static int __init its_probe_one(struct resource *res, out_unmap_sgir:if (its->sgir_base)iounmap (its->sgir_base); -out_free_its: -kfree (its); -out_unmap: -iounmap (its_base); -pr_err ("ITS@%pa: failed probing (%d)\n" , &res->start, err); +out: +pr_err ("ITS@%pa: failed probing (%d)\n" , &its->phys_base, err);return err; }
@@ -5326,10 +5294,53 @@ static const struct of_device_id its_device_id[] = { {}, }; +static struct its_node __init *its_node_init (struct resource *res, +struct fwnode_handle *handle,int numa_node) +{ +void __iomem *its_base; +struct its_node *its; +int err; + + its_base =its_map_one (res, &err); +if (!its_base) +return NULL ; + +pr_info ("ITS %pR\n" , res); + + its =kzalloc (sizeof (*its),GFP_KERNEL ); +if (!its) + goto out_unmap; + +raw_spin_lock_init (&its->lock); +mutex_init (&its->dev_alloc_lock); +INIT_LIST_HEAD (&its->entry); +INIT_LIST_HEAD (&its->its_device_list); + + its->typer =gic_read_typer (its_base +GITS_TYPER ); + its->base = its_base; + its->phys_base = res->start; + + its->numa_node = numa_node; + its->fwnode_handle = handle; + +return its; + +out_unmap: +iounmap (its_base); +return NULL ; +} + +static void its_node_destroy (struct its_node *its) +{ +iounmap (its->base); +kfree (its); +} +static int __init its_of_probe (struct device_node *node) {struct device_node *np;struct resource res; +int err;/* * Make sure *all* the ITS are reset before we probe any, as
@@ -5339,8 +5350,6 @@ static int __init its_of_probe(struct device_node *node)*/ for (np =of_find_matching_node (node, its_device_id); np; np =of_find_matching_node (np, its_device_id)) { -int err; -if (!of_device_is_available (np) || !of_property_read_bool (np,"msi-controller" ) ||of_address_to_resource (np,0 , &res))
@@ -5353,6 +5362,8 @@ static int __init its_of_probe(struct device_node *node)for (np =of_find_matching_node (node, its_device_id); np; np =of_find_matching_node (np, its_device_id)) { +struct its_node *its; +if (!of_device_is_available (np))continue ;if (!of_property_read_bool (np,"msi-controller" )) {
@@ -5366,7 +5377,17 @@ static int __init its_of_probe(struct device_node *node)continue ; } -its_probe_one (&res, &np->fwnode,of_node_to_nid (np)); + + its =its_node_init (&res, &np->fwnode,of_node_to_nid (np)); +if (!its) +return -ENOMEM ; + +its_enable_quirks (its); + err =its_probe_one (its); +if (err) { +its_node_destroy (its); +return err; + } }return 0 ; }
@@ -5478,6 +5499,7 @@ static int __init gic_acpi_parse_madt_its(union acpi_subtable_headers *header, {struct acpi_madt_generic_translator *its_entry;struct fwnode_handle *dom_handle; +struct its_node *its;struct resource res;int err;
@@ -5502,11 +5524,18 @@ static int __init gic_acpi_parse_madt_its(union acpi_subtable_headers *header, goto dom_err; } - err =its_probe_one (&res, dom_handle, -acpi_get_its_numa_node (its_entry->translation_id)); + its =its_node_init (&res, dom_handle, +acpi_get_its_numa_node (its_entry->translation_id)); +if (!its) { + err = -ENOMEM ; + goto node_err; + } + + err =its_probe_one (its);if (!err)return 0 ; +node_err:iort_deregister_domain_token (its_entry->translation_id); dom_err:irq_domain_free_fwnode (dom_handle);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1956/2214 irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Price <[email protected]>
[ Upstream commit b08e2f42e86b5848add254da45b56fc672e2bced ]
Within a realm guest the ITS is emulated by the host. This means the allocations must have been made available to the host by a call to set_memory_decrypted(). Introduce an allocation function which performs this extra call.
For the ITT use a custom genpool-based allocator that calls set_memory_decrypted() for each page allocated, but then suballocates the size needed for each ITT. Note that there is no mechanism implemented to return pages from the genpool, but it is unlikely that the peak number of devices will be much larger than the normal level - so this isn't expected to be an issue.
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 138 +++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 23 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +115 -23
@@ -13,11 +13,13 @@#include <linux/delay.h> #include <linux/dma-iommu.h> #include <linux/efi.h> +#include <linux/genalloc.h> #include <linux/interrupt.h> #include <linux/iopoll.h> #include <linux/irqdomain.h> #include <linux/list.h> #include <linux/log2.h> +#include <linux/mem_encrypt.h> #include <linux/memblock.h> #include <linux/mm.h> #include <linux/msi.h>
@@ -27,6 +29,7 @@#include <linux/of_pci.h> #include <linux/of_platform.h> #include <linux/percpu.h> +#include <linux/set_memory.h> #include <linux/slab.h> #include <linux/syscore_ops.h>
@@ -165,6 +168,7 @@ struct its_device {struct its_node *its;struct event_lpi_map event_map;void *itt; +u32 itt_sz;u32 nr_ites;u32 device_id;bool shared;
@@ -200,6 +204,87 @@ static DEFINE_IDA(its_vpeid_ida);#define gic_data_rdist_rd_base () (gic_data_rdist()->rd_base)#define gic_data_rdist_vlpi_base () (gic_data_rdist_rd_base() + SZ_128K) +static struct page *its_alloc_pages_node (int node,gfp_t gfp, +unsigned int order) +{ +struct page *page; +int ret =0 ; + + page =alloc_pages_node (node, gfp, order); + +if (!page) +return NULL ; + + ret =set_memory_decrypted ((unsigned long )page_address (page), +1 << order); +/* +* If set_memory_decrypted() fails then we don't know what state the +* page is in, so we can't free it. Instead we leak it. +* set_memory_decrypted() will already have WARNed. +*/ +if (ret) +return NULL ; + +return page; +} + +static struct page *its_alloc_pages (gfp_t gfp,unsigned int order) +{ +return its_alloc_pages_node (NUMA_NO_NODE , gfp, order); +} + +static void its_free_pages (void *addr,unsigned int order) +{ +/* +* If the memory cannot be encrypted again then we must leak the pages. +* set_memory_encrypted() will already have WARNed. +*/ +if (set_memory_encrypted ((unsigned long )addr,1 << order)) +return ; +free_pages ((unsigned long )addr, order); +} + +static struct gen_pool *itt_pool; + +static void *itt_alloc_pool (int node,int size) +{ +unsigned long addr; +struct page *page; + +if (size >=PAGE_SIZE ) { + page =its_alloc_pages_node (node,GFP_KERNEL | __GFP_ZERO,get_order (size)); + +return page ?page_address (page) :NULL ; + } + +do { + addr =gen_pool_alloc (itt_pool, size); +if (addr) +break ; + + page =its_alloc_pages_node (node,GFP_KERNEL | __GFP_ZERO,1 ); +if (!page) +break ; + +gen_pool_add (itt_pool, (unsigned long )page_address (page),PAGE_SIZE , node); + }while (!addr); + +return (void *)addr; +} + +static void itt_free_pool (void *addr,int size) +{ +if (!addr) +return ; + +if (size >=PAGE_SIZE ) { +its_free_pages (addr,get_order (size)); +return ; + } + +gen_pool_free (itt_pool, (unsigned long )addr, size); +} +/* * Skip ITSs that have no vLPIs mapped, unless we're on GICv4.1, as we * always have vSGIs mapped.
@@ -2208,7 +2293,8 @@ static struct page *its_allocate_prop_table(gfp_t gfp_flags) {struct page *prop_page; - prop_page =alloc_pages (gfp_flags,get_order (LPI_PROPBASE_SZ )); + prop_page =its_alloc_pages (gfp_flags, +get_order (LPI_PROPBASE_SZ ));if (!prop_page)return NULL ;
@@ -2219,8 +2305,7 @@ static struct page *its_allocate_prop_table(gfp_t gfp_flags)static void its_free_prop_table (struct page *prop_page) { -free_pages ((unsigned long )page_address (prop_page), -get_order (LPI_PROPBASE_SZ )); +its_free_pages (page_address (prop_page),get_order (LPI_PROPBASE_SZ )); }static bool gic_check_reserved_range (phys_addr_t addr,unsigned long size)
@@ -2342,7 +2427,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, order =get_order (GITS_BASER_PAGES_MAX * psz); } - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, order); + page =its_alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, order);if (!page)return -ENOMEM ;
@@ -2355,7 +2440,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,/* 52bit PA is supported only when PageSize=64K */ if (psz !=SZ_64K ) {pr_err ("ITS: no 52bit PA support when psz=%d\n" , psz); -free_pages ((unsigned long )base, order); +its_free_pages (base, order);return -ENXIO ; }
@@ -2409,7 +2494,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,pr_err ("ITS@%pa: %s doesn't stick: %llx %llx\n" , &its->phys_base, its_base_type_string[type], val, tmp); -free_pages ((unsigned long )base, order); +its_free_pages (base, order);return -ENXIO ; }
@@ -2548,8 +2633,7 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -free_pages ((unsigned long )its->tables[i].base, - its->tables[i].order); +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2808,7 +2892,7 @@ static bool allocate_vpe_l2_table(int cpu, u32 id)/* Allocate memory for 2nd level table */ if (!table[idx]) { - page =alloc_pages (GFP_KERNEL | __GFP_ZERO,get_order (psz)); + page =its_alloc_pages (GFP_KERNEL | __GFP_ZERO,get_order (psz));if (!page)return false;
@@ -2927,7 +3011,7 @@ static int allocate_vpe_l1_table(void)pr_debug ("np = %d, npg = %lld, psz = %d, epp = %d, esz = %d\n" , np, npg, psz, epp, esz); - page =alloc_pages (GFP_ATOMIC | __GFP_ZERO,get_order (np *PAGE_SIZE )); + page =its_alloc_pages (GFP_ATOMIC | __GFP_ZERO,get_order (np *PAGE_SIZE ));if (!page)return -ENOMEM ;
@@ -2971,8 +3055,7 @@ static struct page *its_allocate_pending_table(gfp_t gfp_flags) {struct page *pend_page; - pend_page =alloc_pages (gfp_flags | __GFP_ZERO, -get_order (LPI_PENDBASE_SZ )); + pend_page =its_alloc_pages (gfp_flags | __GFP_ZERO,get_order (LPI_PENDBASE_SZ ));if (!pend_page)return NULL ;
@@ -2984,7 +3067,7 @@ static struct page *its_allocate_pending_table(gfp_t gfp_flags)static void its_free_pending_table (struct page *pt) { -free_pages ((unsigned long )page_address (pt),get_order (LPI_PENDBASE_SZ )); +its_free_pages (page_address (pt),get_order (LPI_PENDBASE_SZ )); }/*
@@ -3311,8 +3394,8 @@ static bool its_alloc_table_entry(struct its_node *its,/* Allocate memory for 2nd level table */ if (!table[idx]) { - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, -get_order (baser->psz)); + page =its_alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, +get_order (baser->psz));if (!page)return false;
@@ -3408,7 +3491,6 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,if (WARN_ON (!is_power_of_2 (nvecs))) nvecs =roundup_pow_of_two (nvecs); - dev =kzalloc (sizeof (*dev),GFP_KERNEL );/* * Even if the device wants a single LPI, the ITT must be * sized as a power of two (and you need at least one bit...).
@@ -3419,7 +3501,11 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN ) +ITS_ITT_ALIGN -1 ; - itt =kzalloc_node (sz,GFP_KERNEL , its->numa_node); + + itt =itt_alloc_pool (its->numa_node, sz); + + dev =kzalloc (sizeof (*dev),GFP_KERNEL ); +if (alloc_lpis) { lpi_map =its_lpi_alloc (nvecs, &lpi_base, &nr_lpis);if (lpi_map)
@@ -3431,9 +3517,9 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, lpi_base =0 ; } -if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) { +if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) {kfree (dev); -kfree (itt); +itt_free_pool (itt, sz);bitmap_free (lpi_map);kfree (col_map);return NULL ;
@@ -3443,6 +3529,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, dev->its = its; dev->itt = itt; + dev->itt_sz = sz; dev->nr_ites = nr_ites; dev->event_map.lpi_map = lpi_map; dev->event_map.col_map = col_map;
@@ -3470,7 +3557,7 @@ static void its_free_device(struct its_device *its_dev)list_del (&its_dev->entry);raw_spin_unlock_irqrestore (&its_dev->its->lock, flags);kfree (its_dev->event_map.col_map); -kfree (its_dev->itt); +itt_free_pool (its_dev->itt, its_dev->itt_sz);kfree (its_dev); }
@@ -5076,8 +5163,9 @@ static int __init its_probe_one(struct its_node *its) } } - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, -get_order (ITS_CMD_QUEUE_SZ )); + page =its_alloc_pages_node (its->numa_node, +GFP_KERNEL | __GFP_ZERO, +get_order (ITS_CMD_QUEUE_SZ ));if (!page) { err = -ENOMEM ; goto out_unmap_sgir;
@@ -5142,7 +5230,7 @@ static int __init its_probe_one(struct its_node *its) out_free_tables:its_free_tables (its); out_free_cmd: -free_pages ((unsigned long )its->cmd_base,get_order (ITS_CMD_QUEUE_SZ )); +its_free_pages (its->cmd_base,get_order (ITS_CMD_QUEUE_SZ )); out_unmap_sgir:if (its->sgir_base)iounmap (its->sgir_base);
@@ -5603,6 +5691,10 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,bool has_v4_1 = false;int err; + itt_pool =gen_pool_create (get_order (ITS_ITT_ALIGN ),-1 ); +if (!itt_pool) +return -ENOMEM ; + gic_rdists = rdists; its_parent = parent_domain;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1957/2214 irqchip/gic-v3-its: Dont free a vPE table shared with another ITS
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 32e056cc1d1582951f981113ca8b98914f29c32a ]
On GICv4.1, its_alloc_tables() copies a sibling's vPE table baser rather than allocating one, but its_free_tables() frees it like the rest. A probe failure on the copying ITS then frees pages the enabled sibling still points GITS_BASER2 at, and the kernel comes up running on that sibling.
Mark a shared table so its_free_tables() skips it.
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
@@ -85,6 +85,8 @@ struct its_baser {u64 val;u32 order;u32 psz; +/* Inherited from a sibling ITS, not freed here */ +bool shared; };struct its_device ;
@@ -2633,7 +2635,8 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -its_free_pages (its->tables[i].base, its->tables[i].order); +if (!its->tables[i].shared) +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2727,6 +2730,7 @@ static int its_alloc_tables(struct its_node *its)WARN_ON (i !=2 );if ((sibling =find_sibling_its (its))) { *baser = sibling->tables[2 ]; + baser->shared = true;its_write_baser (its, baser, baser->val);continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1958/2214 irqchip/gic-v3-its: Dont free the tables of an enabled ITS
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit d09b36d8e0e60f35bd1cd7d63aadc6dfad61700c ]
its_probe_one() enables the ITS before its_init_domain(), the last step that can fail, and the unwind from there frees the tables and the command queue without disabling it. The kernel comes up with an enabled ITS pointing at freed pages.
Enable the ITS last. Nothing reaches the new domain before then: this runs from init_IRQ(), and the ITS joins its_nodes only after the enable.
--- drivers/irqchip/irq-gic-v3-its.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +6 -4
@@ -5213,16 +5213,18 @@ static int __init its_probe_one(struct its_node *its) }gits_write_cwriter (0 , its->base +GITS_CWRITER ); + + err =its_init_domain (its); +if (err) + goto out_free_collection; + +/* Enable last: the unwind frees memory an enabled ITS may access */ ctlr =readl_relaxed (its->base +GITS_CTLR ); ctlr |=GITS_CTLR_ENABLE ;if (is_v4 (its)) ctlr |= GITS_CTLR_ImDe;writel_relaxed (ctlr, its->base +GITS_CTLR ); - err =its_init_domain (its); -if (err) - goto out_free_collection; -raw_spin_lock (&its_lock);list_add (&its->entry, &its_nodes);raw_spin_unlock (&its_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1959/2214 ALSA: pcm: Use deferred fasync helper
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 96b097091c66df4f6fbf5cbff21df6cc02a2f055 ]
For avoiding the potential deadlock via kill_fasync() call, use the new fasync helpers to defer the invocation from timer API. Note that it's merely a workaround.
Stable-dep-of: 91d0048a97e0 ("ALSA: pcm: Add refcount for races between drain and unlink")
--- include/sound/pcm.h | 2 +- sound/core/pcm.c | 1 + sound/core/pcm_lib.c | 2 +- sound/core/pcm_native.c | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-)
include/sound/pcm.h +1 -1
@@ -398,7 +398,7 @@ struct snd_pcm_runtime {snd_pcm_uframes_t twake;/* do transfer (!poll) wakeup if non-zero */ wait_queue_head_t sleep;/* poll sleep */ wait_queue_head_t tsleep;/* transfer sleep */ -struct fasync_struct *fasync; +struct snd_fasync *fasync;bool stop_operating;/* sync_stop will be called */ struct mutex buffer_mutex;/* protect for buffer changes */ atomic_t buffer_accessing;/* >0: in r/w operation, <0: blocked */
sound/core/pcm.c +1 -0
@@ -1008,6 +1008,7 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream) substream->runtime =NULL ; }mutex_destroy (&runtime->buffer_mutex); +snd_fasync_free (runtime->fasync);kfree (runtime);put_pid (substream->pid); substream->pid =NULL ;
sound/core/pcm_lib.c +1 -1
@@ -1821,7 +1821,7 @@ void snd_pcm_period_elapsed_under_stream_lock(struct snd_pcm_substream *substreasnd_timer_interrupt (substream->timer,1 );#endif _end: -kill_fasync (&runtime->fasync,SIGIO ,POLL_IN ); +snd_kill_fasync (runtime->fasync,SIGIO ,POLL_IN ); }EXPORT_SYMBOL (snd_pcm_period_elapsed_under_stream_lock);
sound/core/pcm_native.c +1 -1
@@ -4007,7 +4007,7 @@ static int snd_pcm_fasync(int fd, struct file * file, int on) runtime = substream->runtime;if (runtime->state ==SNDRV_PCM_STATE_DISCONNECTED )return -EBADFD ; -return fasync_helper (fd, file, on, &runtime->fasync); +return snd_fasync_helper (fd, file, on, &runtime->fasync); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1960/2214 ALSA: Add simple refcount helper functions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit dcca9b6064c33c84fbeb9f09814178a206321249 ]
There are many open-code to manage the same pattern for refcount + wakeup sync at closing. Let's provide the common helper functions to replace the open-code.
- The recount is kept in struct snd_refcount, where it's initialized by snd_refcount_init().
- The user can simply reference or unreference via snd_refcount_get() and snd_refcount_put() functions
- The user can wait for the all usages gone by snd_refcount_sync()
Note that here we use atomic_t instead of refcount_t since the current users allow reusing the refcount after sync again. The design of refcount_t prevents exactly this behavior, so it doesn't fit.
Stable-dep-of: 91d0048a97e0 ("ALSA: pcm: Add refcount for races between drain and unlink")
--- include/sound/core.h | 21 +++++++++++++++++++++ sound/core/misc.c | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
include/sound/core.h +21 -0
@@ -74,6 +74,27 @@ struct snd_device {#define snd_device (n) list_entry(n, struct snd_device, list) +/* +* A simple reference counter with a wait queue; +* typically used for usage counts, and you can synchronize at finishing +* via snd_refcount_sync(), which is woken up when the refcount reaches to +* zero again. +*/ +struct snd_refcount { +atomic_t count; +wait_queue_head_t waiter; +}; + +void snd_refcount_init (struct snd_refcount *ref); + +static inline void snd_refcount_get (struct snd_refcount *ref) +{ +atomic_inc (&ref->count); +} + +void snd_refcount_put (struct snd_refcount *ref); +void snd_refcount_sync (struct snd_refcount *ref); +/* main structure for soundcard */ struct snd_card {
sound/core/misc.c +24 -0
@@ -247,3 +247,27 @@ void snd_fasync_free(struct snd_fasync *fasync)kfree (fasync); }EXPORT_SYMBOL_GPL (snd_fasync_free); + +/* +* generic refcount helper +*/ + +void snd_refcount_init (struct snd_refcount *ref) +{ +atomic_set (&ref->count,0 ); +init_waitqueue_head (&ref->waiter); +} +EXPORT_SYMBOL_GPL (snd_refcount_init); + +void snd_refcount_put (struct snd_refcount *ref) +{ +if (atomic_dec_and_test (&ref->count)) +wake_up (&ref->waiter); +} +EXPORT_SYMBOL_GPL (snd_refcount_put); + +void snd_refcount_sync (struct snd_refcount *ref) +{ +wait_event (ref->waiter, !atomic_read (&ref->count)); +} +EXPORT_SYMBOL_GPL (snd_refcount_sync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1961/2214 ALSA: pcm: Add refcount for races between drain and unlink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 91d0048a97e0fdc0a071caa0ba59e659bc6f84df ]
We added a workaround for the case where a linked substream gets unlinked during the drain operation by another substream of the same linked group in the commit 9b1dbd69ba6f ("ALSA: pcm: fix use-after-free on linked stream runtime in snd_pcm_drain()"). There, we just cached the parameters of the draining substream for avoiding UAF.
Then, we check the draining substream (to_check) again in the loop and remove it from the queue only when it's still present. It means, however, that the wait queue entry won't be removed if the substream went out of the link beforehand, hence a stale wq entry remains. Later on, this can be woken up, and this may hit a UAF, too. The problem surfaced more due to the recent change to call snd_pcm_unlink() earlier.
For properly handling both cases above, in this patch, we introduce a refcount to the snd_pcm_runtime that indicates the substream is being accessed / used, then at snd_pcm_release_substream(), it's synced before the actual resource release via snd_refcount_sync(). This guarantees that the accessors are finished, and safe to release memories. Along with the introduction of a refcount, the comments and the code changes by the former fix were partially reverted as they don't fit with the updated code flow any longer.
Last but not least, the setup of wait queue entry and prepare_to_wait() call are moved before the group unref. With this change, we can avoid the race between the enqueue and the wakeup, too.
--- include/sound/pcm.h | 2 ++ sound/core/pcm.c | 1 + sound/core/pcm_native.c | 54 ++++++++++++++++------------------------- 3 files changed, 24 insertions(+), 33 deletions(-)
include/sound/pcm.h +2 -0
@@ -8,6 +8,7 @@* Abramo Bagnara <[email protected]> */ +#include <sound/core.h> #include <sound/asound.h> #include <sound/memalloc.h> #include <sound/minors.h>
@@ -398,6 +399,7 @@ struct snd_pcm_runtime {snd_pcm_uframes_t twake;/* do transfer (!poll) wakeup if non-zero */ wait_queue_head_t sleep;/* poll sleep */ wait_queue_head_t tsleep;/* transfer sleep */ +struct snd_refcount refcnt;/* refcount for draining, etc */ struct snd_fasync *fasync;bool stop_operating;/* sync_stop will be called */ struct mutex buffer_mutex;/* protect for buffer changes */
sound/core/pcm.c +1 -0
@@ -970,6 +970,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,init_waitqueue_head (&runtime->sleep);init_waitqueue_head (&runtime->tsleep); +snd_refcount_init (&runtime->refcnt);__snd_pcm_set_state (runtime,SNDRV_PCM_STATE_OPEN );mutex_init (&runtime->buffer_mutex);
sound/core/pcm_native.c +21 -33
81 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1962/2214 RDMA/rxe: reject IB_WR_REG_MR from user QPs in rxe_reg_fast_mr()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit 33afe9909f213d8bb8e80f0b93382dde0f56e2c7 ]
IB_WR_REG_MR is documented as kernel-only ("can not be issued by userspace"), but nothing enforces it. rxe_wr_opcode_info[IB_WR_REG_MR] sets WR_LOCAL_OP_MASK for IB_QPT_RC, a QP type userspace can create, so a user QP that writes opcode = IB_WR_REG_MR into its mmap'd SQ ring reaches rxe_do_local_ops() -> rxe_reg_fast_mr(). That function then trusts the ring-supplied fields:
struct rxe_mr *mr = to_rmr(wqe->wr.wr.reg.mr); ... if (unlikely(mr->state != RXE_MR_STATE_FREE)) /* deref */ ... mr->access = access; /* write */
For a user QP wqe->wr.wr.reg.mr is a fully attacker-chosen pointer, so this is an arbitrary-kernel-address dereference (arbitrary read confirmed, oops). No existing check distinguishes a user QP on this path.
Reject IB_WR_REG_MR for user QPs before dereferencing the supplied pointer.
--- drivers/infiniband/sw/rxe/rxe_mr.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/sw/rxe/rxe_mr.c +4 -0
@@ -571,6 +571,10 @@ int rxe_reg_fast_mr(struct rxe_qp *qp, struct rxe_send_wqe *wqe)u32 key = wqe->wr.wr.reg.key;u32 access = wqe->wr.wr.reg.access; +/* IB_WR_REG_MR is a kernel-only op; a user QP must not reach here. */ +if (qp->is_user) +return -EOPNOTSUPP ; +/* user can only register MR in free state */ if (unlikely (mr->state !=RXE_MR_STATE_FREE )) { pr_warn("%s: mr->lkey = 0x%x not free\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1963/2214 RDMA/rxe: Move AV from rxe_send_wqe to rxe_send_wr
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit cfc0312d9c83a5bbb66fa73ba47dd1301d75b2e8 ]
Move the struct rxe_av av from struct rxe_send_wqe to struct rxe_send_wr placing it in wr.ud at the same offset as it was previously. This has the effect of increasing the size of struct rxe_send_wr while keeping the size of struct rxe_send_wqe the same. This better reflects the use of this field which is only used for UD sends. This change has no effect on ABI compatibility so the modified rxe driver will operate with older versions of rdma-core.
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_av.c | 2 +- drivers/infiniband/sw/rxe/rxe_verbs.c | 3 ++- include/uapi/rdma/rdma_user_rxe.h | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rxe/rxe_av.c +1 -1
@@ -107,5 +107,5 @@ struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt)if (qp_type (pkt->qp) ==IB_QPT_RC ||qp_type (pkt->qp) ==IB_QPT_UC )return &pkt->qp->pri_av; -return (pkt->wqe) ? &pkt->wqe->av :NULL ; +return (pkt->wqe) ? &pkt->wqe->wr.wr.ud.av :NULL ; }
drivers/infiniband/sw/rxe/rxe_verbs.c +2 -1
@@ -584,7 +584,8 @@ static void init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,if (qp_type (qp) ==IB_QPT_UD ||qp_type (qp) ==IB_QPT_SMI ||qp_type (qp) ==IB_QPT_GSI ) -memcpy (&wqe->av, &to_rah (ud_wr (ibwr)->ah)->av,sizeof (wqe->av)); +memcpy (&wqe->wr.wr.ud.av, &to_rah (ud_wr (ibwr)->ah)->av, +sizeof (struct rxe_av ));if (unlikely (ibwr->send_flags &IB_SEND_INLINE ))copy_inline_data_to_wqe (wqe, ibwr);
include/uapi/rdma/rdma_user_rxe.h +3 -1
@@ -98,6 +98,9 @@ struct rxe_send_wr {__u32 remote_qpn;__u32 remote_qkey;__u16 pkey_index; +__u16 reserved; +__u32 pad[5 ]; +struct rxe_av av; } ud;struct {__aligned_u64 addr;
@@ -148,7 +151,6 @@ struct rxe_dma_info {struct rxe_send_wqe {struct rxe_send_wr wr; -struct rxe_av av;__u32 status;__u32 state;__aligned_u64 iova;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1964/2214 RDMA/rxe: Create AH index and return to user space
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit 73a54932100375ba94b31710f1e3f1234f23be0b ]
Make changes to rdma_user_rxe.h to allow indexing AH objects, passing the index in UD send WRs to the driver and returning the index to the rxe provider.
Modify rxe_create_ah() to add an index to AH when created and if called from a new user provider return it to user space. If called from an old provider mark the AH as not having a useful index. Modify rxe_destroy_ah to drop the index before deleting the object.
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_verbs.c | 31 ++++++++++++++++++++++++++- drivers/infiniband/sw/rxe/rxe_verbs.h | 2 ++ include/uapi/rdma/rdma_user_rxe.h | 8 ++++++- 3 files changed, 39 insertions(+), 2 deletions(-)
drivers/infiniband/sw/rxe/rxe_verbs.c +30 -1
@@ -161,9 +161,19 @@ static int rxe_create_ah(struct ib_ah *ibah, struct ib_udata *udata) { -int err;struct rxe_dev *rxe =to_rdev (ibah->device);struct rxe_ah *ah =to_rah (ibah); +struct rxe_create_ah_resp __user *uresp =NULL ; +int err; + +if (udata) { +/* test if new user provider */ +if (udata->outlen >=sizeof (*uresp)) + uresp = udata->outbuf; + ah->is_user = true; + }else { + ah->is_user = false; + } err =rxe_av_chk_attr (rxe, init_attr->ah_attr);if (err)
@@ -173,6 +183,24 @@ static int rxe_create_ah(struct ib_ah *ibah,if (err)return err; +/* create index > 0 */ +rxe_add_index (ah); + ah->ah_num = ah->pelem.index; + +if (uresp) { +/* only if new user provider */ + err =copy_to_user (&uresp->ah_num, &ah->ah_num, +sizeof (uresp->ah_num)); +if (err) { +rxe_drop_index (ah); +rxe_drop_ref (ah); +return -EFAULT ; + } + }else if (ah->is_user) { +/* only if old user provider */ + ah->ah_num =0 ; + } +rxe_init_av (init_attr->ah_attr, &ah->av);return 0 ; }
@@ -205,6 +233,7 @@ static int rxe_destroy_ah(struct ib_ah *ibah, u32 flags) {struct rxe_ah *ah =to_rah (ibah); +rxe_drop_index (ah);rxe_drop_ref (ah);return 0 ; }
drivers/infiniband/sw/rxe/rxe_verbs.h +2 -0
@@ -48,6 +48,8 @@ struct rxe_ah {struct rxe_pool_entry pelem;struct rxe_pd *pd;struct rxe_av av; +bool is_user; +int ah_num; };struct rxe_cqe {
include/uapi/rdma/rdma_user_rxe.h +7 -1
@@ -99,7 +99,8 @@ struct rxe_send_wr {__u32 remote_qkey;__u16 pkey_index;__u16 reserved; -__u32 pad[5 ]; +__u32 ah_num; +__u32 pad[4 ];struct rxe_av av; } ud;struct {
@@ -170,6 +171,11 @@ struct rxe_recv_wqe {struct rxe_dma_info dma; }; +struct rxe_create_ah_resp { +__u32 ah_num; +__u32 reserved; +}; +struct rxe_create_cq_resp {struct mminfo mi; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1965/2214 RDMA/rxe: Replace ah->pd by ah->ibah.pd
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit 4da698eabf0f7c1c1806670d3fd3895512fdf43b ]
The pd field in struct rxe_ah is redundant with the pd field in the rdma-core's ib_ah. Eliminate the pd field in rxe_ah and add an inline to extract the pd from the ibah field.
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_verbs.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_verbs.h +5 -1
@@ -46,7 +46,6 @@ struct rxe_pd {struct rxe_ah {struct ib_ah ibah;struct rxe_pool_entry pelem; -struct rxe_pd *pd;struct rxe_av av;bool is_user;int ah_num;
@@ -471,6 +470,11 @@ static inline struct rxe_mw *to_rmw(struct ib_mw *mw) return mw ? container_of(mw, struct rxe_mw, ibmw) : NULL; } +static inline struct rxe_pd *rxe_ah_pd (struct rxe_ah *ah) +{ +return to_rpd (ah->ibah.pd); +} +static inline struct rxe_pd *mr_pd (struct rxe_mr *mr) {return to_rpd (mr->ibmr.pd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1966/2214 RDMA/rxe: Lookup kernel AH from ah index in UD WQEs
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit e2fe06c9080694f2c28894f14ef8ebfd923ac94d ]
Add code to rxe_get_av in rxe_av.c to use the AH index in UD send WQEs to lookup the kernel AH. For old user providers continue to use the AV passed in WQEs. Move setting pkt->rxe to before the call to rxe_get_av() to get access to the AH pool.
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_av.c | 20 +++++++++++++++++++- drivers/infiniband/sw/rxe/rxe_req.c | 8 +++++--- 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/infiniband/sw/rxe/rxe_av.c +19 -1
@@ -101,11 +101,29 @@ void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr)struct rxe_av *rxe_get_av (struct rxe_pkt_info *pkt) { +struct rxe_ah *ah; +u32 ah_num; +if (!pkt || !pkt->qp)return NULL ;if (qp_type (pkt->qp) ==IB_QPT_RC ||qp_type (pkt->qp) ==IB_QPT_UC )return &pkt->qp->pri_av; -return (pkt->wqe) ? &pkt->wqe->wr.wr.ud.av :NULL ; +if (!pkt->wqe) +return NULL ; + + ah_num = pkt->wqe->wr.wr.ud.ah_num; +if (ah_num) { +/* only new user provider or kernel client */ + ah =rxe_pool_get_index (&pkt->rxe->ah_pool, ah_num); +if (!ah || ah->ah_num != ah_num ||rxe_ah_pd (ah) != pkt->qp->pd) { +pr_warn ("Unable to find AH matching ah_num\n" ); +return NULL ; + } +return &ah->av; + } + +/* only old user provider for UD sends*/ +return &pkt->wqe->wr.wr.ud.av; }
drivers/infiniband/sw/rxe/rxe_req.c +5 -3
@@ -379,9 +379,8 @@ static struct sk_buff *init_req_packet(struct rxe_qp *qp,/* length from start of bth to end of icrc */ paylen = rxe_opcode[opcode].length + payload + pad +RXE_ICRC_SIZE ; -/* pkt->hdr, rxe, port_num and mask are initialized in ifc -* layer -*/ +/* pkt->hdr, port_num and mask are initialized in ifc layer */ + pkt->rxe = rxe; pkt->opcode = opcode; pkt->qp = qp; pkt->psn = qp->req.psn;
@@ -391,6 +390,9 @@ static struct sk_buff *init_req_packet(struct rxe_qp *qp,/* init skb */ av =rxe_get_av (pkt); +if (!av) +return NULL ; + skb =rxe_init_packet (rxe, av, paylen, pkt);if (unlikely (!skb))return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1967/2214 RDMA/rxe: Change variable and function argument to proper type
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengguang Xu <[email protected]>
[ Upstream commit 7e8e611d6a0ff228577b1167335ffefb0f44d5d8 ]
The type of wqe length is u32 so in order to avoid overflow and shadow casting change variable and relevant function argument to proper type.
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_req.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/infiniband/sw/rxe/rxe_req.c +5 -5
@@ -362,7 +362,7 @@ static inline int get_mtu(struct rxe_qp *qp)static struct sk_buff *init_req_packet (struct rxe_qp *qp,struct rxe_send_wqe *wqe, -int opcode,int payload, +int opcode,u32 payload,struct rxe_pkt_info *pkt) {struct rxe_dev *rxe =to_rdev (qp->ibqp.device);
@@ -456,7 +456,7 @@ static struct sk_buff *init_req_packet(struct rxe_qp *qp,static int finish_packet (struct rxe_qp *qp,struct rxe_send_wqe *wqe,struct rxe_pkt_info *pkt,struct sk_buff *skb, -int paylen) +u32 paylen) {int err;
@@ -504,7 +504,7 @@ static void update_wqe_state(struct rxe_qp *qp,static void update_wqe_psn (struct rxe_qp *qp,struct rxe_send_wqe *wqe,struct rxe_pkt_info *pkt, -int payload) +u32 payload) {/* number of packets left to send including current one */ int num_pkt = (wqe->dma.resid + payload + qp->mtu -1 ) / qp->mtu;
@@ -547,7 +547,7 @@ static void rollback_state(struct rxe_send_wqe *wqe, }static void update_state (struct rxe_qp *qp,struct rxe_send_wqe *wqe, -struct rxe_pkt_info *pkt,int payload) +struct rxe_pkt_info *pkt,u32 payload) { qp->req.opcode = pkt->opcode;
@@ -621,7 +621,7 @@ int rxe_requester(void *arg)struct sk_buff *skb;struct rxe_send_wqe *wqe;enum rxe_hdr_mask mask; -int payload; +u32 payload;int mtu;int opcode;int ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1968/2214 RDMA/rxe: Fix ref error in rxe_av.c
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit 63221acb0c63141cc7650f8eefb148337061e6db ]
The commit referenced below can take a reference to the AH which is never dropped. This only happens in the UD request path. This patch optionally passes that AH back to the caller so that it can hold the reference while the AV is being accessed and then drop it. Code to do this is added to rxe_req.c. The AV is also passed to rxe_prepare in rxe_net.c as an optimization.
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_av.c | 19 +++++++++- drivers/infiniband/sw/rxe/rxe_loc.h | 5 ++- drivers/infiniband/sw/rxe/rxe_net.c | 17 +++++---- drivers/infiniband/sw/rxe/rxe_req.c | 55 +++++++++++++++++----------- drivers/infiniband/sw/rxe/rxe_resp.c | 2 +- 5 files changed, 63 insertions(+), 35 deletions(-)
drivers/infiniband/sw/rxe/rxe_av.c +17 -2
@@ -99,11 +99,14 @@ void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr) av->network_type = type; } -struct rxe_av *rxe_get_av (struct rxe_pkt_info *pkt) +struct rxe_av *rxe_get_av (struct rxe_pkt_info *pkt,struct rxe_ah **ahp) {struct rxe_ah *ah;u32 ah_num; +if (ahp) + *ahp =NULL ; +if (!pkt || !pkt->qp)return NULL ;
@@ -117,10 +120,22 @@ struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt)if (ah_num) {/* only new user provider or kernel client */ ah =rxe_pool_get_index (&pkt->rxe->ah_pool, ah_num); -if (!ah || ah->ah_num != ah_num ||rxe_ah_pd (ah) != pkt->qp->pd) { +if (!ah) {pr_warn ("Unable to find AH matching ah_num\n" );return NULL ; } + +if (rxe_ah_pd (ah) != pkt->qp->pd) { +pr_warn ("PDs don't match for AH and QP\n" ); +rxe_drop_ref (ah); +return NULL ; + } + +if (ahp) + *ahp = ah; +else +rxe_drop_ref (ah); +return &ah->av; }
drivers/infiniband/sw/rxe/rxe_loc.h +3 -2
@@ -19,7 +19,7 @@ void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr);void rxe_av_fill_ip_info (struct rxe_av *av,struct rdma_ah_attr *attr); -struct rxe_av *rxe_get_av (struct rxe_pkt_info *pkt); +struct rxe_av *rxe_get_av (struct rxe_pkt_info *pkt,struct rxe_ah **ahp);/* rxe_cq.c */ int rxe_cq_chk_attr(struct rxe_dev *rxe, struct rxe_cq *cq,
@@ -101,7 +101,8 @@ void rxe_mw_cleanup(struct rxe_pool_entry *arg);/* rxe_net.c */ struct sk_buff *rxe_init_packet (struct rxe_dev *rxe,struct rxe_av *av,int paylen,struct rxe_pkt_info *pkt); -int rxe_prepare (struct rxe_pkt_info *pkt,struct sk_buff *skb); +int rxe_prepare (struct rxe_av *av,struct rxe_pkt_info *pkt, +struct sk_buff *skb);int rxe_xmit_packet (struct rxe_qp *qp,struct rxe_pkt_info *pkt,struct sk_buff *skb);const char *rxe_parent_name (struct rxe_dev *rxe,unsigned int port_num);
drivers/infiniband/sw/rxe/rxe_net.c +9 -8
@@ -296,13 +296,13 @@ static void prepare_ipv6_hdr(struct dst_entry *dst, struct sk_buff *skb, ip6h->payload_len =htons (skb->len -sizeof (*ip6h)); } -static int prepare4 (struct rxe_pkt_info *pkt,struct sk_buff *skb) +static int prepare4 (struct rxe_av *av,struct rxe_pkt_info *pkt, +struct sk_buff *skb) {struct rxe_qp *qp = pkt->qp;struct dst_entry *dst;bool xnet = false;__be16 df =htons (IP_DF ); -struct rxe_av *av =rxe_get_av (pkt);struct in_addr *saddr = &av->sgid_addr._sockaddr_in.sin_addr;struct in_addr *daddr = &av->dgid_addr._sockaddr_in.sin_addr;
@@ -322,11 +322,11 @@ static int prepare4(struct rxe_pkt_info *pkt, struct sk_buff *skb)return 0 ; } -static int prepare6 (struct rxe_pkt_info *pkt,struct sk_buff *skb) +static int prepare6 (struct rxe_av *av,struct rxe_pkt_info *pkt, +struct sk_buff *skb) {struct rxe_qp *qp = pkt->qp;struct dst_entry *dst; -struct rxe_av *av =rxe_get_av (pkt);struct in6_addr *saddr = &av->sgid_addr._sockaddr_in6.sin6_addr;struct in6_addr *daddr = &av->dgid_addr._sockaddr_in6.sin6_addr;
@@ -347,16 +347,17 @@ static int prepare6(struct rxe_pkt_info *pkt, struct sk_buff *skb)return 0 ; } -int rxe_prepare (struct rxe_pkt_info *pkt,struct sk_buff *skb) +int rxe_prepare (struct rxe_av *av,struct rxe_pkt_info *pkt, +struct sk_buff *skb) {int err =0 ;if (skb->protocol ==htons (ETH_P_IP )) - err =prepare4 (pkt, skb); + err =prepare4 (av, pkt, skb);else if (skb->protocol ==htons (ETH_P_IPV6 )) - err =prepare6 (pkt, skb); + err =prepare6 (av, pkt, skb); -if (ether_addr_equal (skb->dev->dev_addr,rxe_get_av (pkt)->dmac)) +if (ether_addr_equal (skb->dev->dev_addr, av->dmac)) pkt->mask |=RXE_LOOPBACK_MASK ;return err;
drivers/infiniband/sw/rxe/rxe_req.c +33 -22
121 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_resp.c +1 -1
@@ -634,7 +634,7 @@ static struct sk_buff *prepare_ack_packet(struct rxe_qp *qp,if (ack->mask &RXE_ATMACK_MASK )atmack_set_orig (ack, qp->resp.atomic_orig); - err =rxe_prepare (ack, skb); + err =rxe_prepare (&qp->pri_av, ack, skb);if (err) {kfree_skb (skb);return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1969/2214 RDMA/rxe: Replace paylen by payload
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit e7734156b0ad7c32643de851d644db74ea4b0074 ]
In finish_packet() in rxe_req.c a variable was incorrectly called paylen instead of payload. Elsewhere in the rxe source payload is always used for the RoCE payload length and paylen is always used for the UDP payload length. This will cause unnecessary confusion.
Replace paylen by payload in finish_packet().
Stable-dep-of: 47a9c0338f2e ("RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]")
--- drivers/infiniband/sw/rxe/rxe_req.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/sw/rxe/rxe_req.c +6 -6
@@ -444,7 +444,7 @@ static struct sk_buff *init_req_packet(struct rxe_qp *qp,static int finish_packet (struct rxe_qp *qp,struct rxe_av *av,struct rxe_send_wqe *wqe,struct rxe_pkt_info *pkt, -struct sk_buff *skb,u32 paylen) +struct sk_buff *skb,u32 payload) {int err;
@@ -456,19 +456,19 @@ static int finish_packet(struct rxe_qp *qp, struct rxe_av *av,if (wqe->wr.send_flags &IB_SEND_INLINE ) {u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset]; -memcpy (payload_addr (pkt), tmp, paylen); +memcpy (payload_addr (pkt), tmp, payload); - wqe->dma.resid -= paylen; - wqe->dma.sge_offset += paylen; + wqe->dma.resid -= payload; + wqe->dma.sge_offset += payload; }else { err =copy_data (qp->pd,0 , &wqe->dma, -payload_addr (pkt), paylen, +payload_addr (pkt), payload,RXE_FROM_MR_OBJ );if (err)return err; }if (bth_pad (pkt)) { -u8 *pad =payload_addr (pkt) + paylen; +u8 *pad =payload_addr (pkt) + payload;memset (pad,0 ,bth_pad (pkt)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1970/2214 RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit 47a9c0338f2e0d4178d77b0d2f529fe1fde84642 ]
For a user QP, rxe_post_send() takes the qp->is_user branch and never runs init_send_wqe(), so dma.length/resid/num_sge/cur_sge/sge_offset all come straight from the mmap'd SQ ring. In the inline send path finish_packet() uses sge_offset directly as an index:
u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset]; memcpy(payload_addr(pkt), tmp, payload);
inline_data is a flex array whose capacity is qp->sq.max_inline, but sge_offset is a u32 from user space, so the source pointer is
displaced arbitrarily past the WQE and the memcpy reads out of
bounds.
commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]") added num_sge/cur_sge checks on the send path but not sge_offset, the
third attacker-controlled index in the same struct.
Read sge_offset once with READ_ONCE() and bound it (and the payload that follows it) by qp->sq.max_inline before indexing, so the value that is validated is the value that is used.
--- drivers/infiniband/sw/rxe/rxe_req.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_req.c +8 -1
@@ -454,7 +454,14 @@ static int finish_packet(struct rxe_qp *qp, struct rxe_av *av,if (pkt->mask &RXE_WRITE_OR_SEND ) {if (wqe->wr.send_flags &IB_SEND_INLINE ) { -u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset]; +u32 sge_offset =READ_ONCE (wqe->dma.sge_offset); +u8 *tmp; + +if (unlikely (sge_offset > (u32 )qp->sq.max_inline || + payload > (u32 )qp->sq.max_inline - sge_offset)) +return -EINVAL ; + + tmp = &wqe->dma.inline_data[sge_offset];memcpy (payload_addr (pkt), tmp, payload);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1971/2214 RDMA/rxe: bound the WQE opcode before indexing rxe_wr_opcode_info[]
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit c887e53e1c852b88bd5442d1bf4717ee3e7aadda ]
wr_opcode_mask() indexes the global rxe_wr_opcode_info[] array with a caller-supplied opcode and no bounds check. For a user QP the WQE comes from an mmap'd SQ ring, so wqe->wr.opcode is an attacker-controlled __u32 read back by the requester (req_next_wqe() -> rxe_requester()); rxe_post_send() takes the qp->is_user branch and never runs validate_send_wr(), whose only opcode check is itself !wr_opcode_mask() (it indexes before it checks). rxe_wr_opcode_info[] has entries only up to IB_WR_REG_MR, so an out-of-range opcode reads out of bounds and the result is used as a mask and dereferenced; observed as a KASAN global-out-of-bounds "Read of size 4" and a wild-pointer oops.
Return a zero mask for an out-of-range opcode, matching how validate_send_wr() already treats a zero mask (an invalid WR), so no path indexes the array out of bounds.
--- drivers/infiniband/sw/rxe/rxe_loc.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/infiniband/sw/rxe/rxe_loc.h +3 -0
@@ -205,6 +205,9 @@ void rxe_comp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb);static inline unsigned int wr_opcode_mask (int opcode,struct rxe_qp *qp) { +if (unlikely (opcode <0 || opcode >IB_WR_REG_MR )) +return 0 ; +return rxe_wr_opcode_info[opcode].mask[qp->ibqp.qp_type]; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1972/2214 ALSA: core: Serialize snd_refcount put and sync
In reply to Greg Kroah-Hartman5.15-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
@@ -83,6 +83,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
@@ -256,11 +256,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); }
@@ -268,6 +270,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 1973/2214 kselftest/arm64: signal: copy each test binary only once
In reply to Greg Kroah-Hartman5.15-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
@@ -18,8 +18,8 @@ KSFT_KHDR_INSTALL := 1 # 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 1974/2214 IB/rdmavt: Fix error unwind path for qp_priv_init() in rvt_create_qp()
In reply to Greg Kroah-Hartman5.15-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
@@ -1177,7 +1177,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 1975/2214 RDMA/irdma: Fix FRWR IRDMAQPSQ_PBLADDR field population
In reply to Greg Kroah-Hartman5.15-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
@@ -1313,7 +1313,7 @@ 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 1976/2214 selftests: keep the build status from wrapping to success
In reply to Greg Kroah-Hartman5.15-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
@@ -175,7 +175,7 @@ all: khdr mkdir $$BUILD_TARGET -p; \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ $(if $(FORCE_TARGETS),|| exit); \ - ret=$$((ret * $$?)); \ + [ $$? -eq 0 ] && ret=0; \ done; exit $$ret; run_tests: all
@@ -233,7 +233,7 @@ ifdef INSTALL_PATH BUILD_TARGET=$$BUILD/$$TARGET; \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ $(if $(FORCE_TARGETS),|| exit); \ - ret=$$((ret * $$?)); \ + [ $$? -eq 0 ] && ret=0; \ done; exit $$ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1977/2214 ASoC: remove unused substream in macro soc_link_mark_pop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongbo Li <[email protected]>
[ Upstream commit 2f12d0de77b99f0f35755d16efeb12e6f45e5710 ]
The soc_link_mark_pop don't need substream, therefore we can remove it.
Stable-dep-of: 7ef99fcfbbac ("ASoC: soc-link: Correct stream stop operations in snd_soc_link_trigger")
--- sound/soc/soc-link.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/soc-link.c +5 -5
@@ -35,7 +35,7 @@ static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,* In such case, we can update these macros. */ #define soc_link_mark_push (rtd, substream, tgt) ((rtd)->mark_##tgt = substream) -#define soc_link_mark_pop (rtd, substream, tgt) ((rtd)->mark_##tgt = NULL) +#define soc_link_mark_pop (rtd, tgt) ((rtd)->mark_##tgt = NULL)#define soc_link_mark_match (rtd, substream, tgt) ((rtd)->mark_##tgt == substream)int snd_soc_link_init (struct snd_soc_pcm_runtime *rtd)
@@ -94,7 +94,7 @@ void snd_soc_link_shutdown(struct snd_pcm_substream *substream, rtd->dai_link->ops->shutdown (substream);/* remove marked substream */ -soc_link_mark_pop (rtd, substream, startup); +soc_link_mark_pop (rtd, startup); }int snd_soc_link_prepare (struct snd_pcm_substream *substream)
@@ -138,7 +138,7 @@ void snd_soc_link_hw_free(struct snd_pcm_substream *substream, int rollback) rtd->dai_link->ops->hw_free (substream);/* remove marked substream */ -soc_link_mark_pop (rtd, substream, hw_params); +soc_link_mark_pop (rtd, hw_params); }static int soc_link_trigger (struct snd_pcm_substream *substream,int cmd)
@@ -175,7 +175,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, substream, startup); +soc_link_mark_pop (rtd, startup); }return ret;
@@ -209,7 +209,7 @@ void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream, rtd->dai_link->compr_ops->shutdown) rtd->dai_link->compr_ops->shutdown (cstream); -soc_link_mark_pop (rtd, cstream, compr_startup); +soc_link_mark_pop (rtd, compr_startup); }EXPORT_SYMBOL_GPL (snd_soc_link_compr_shutdown);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1978/2214 ASoC: soc-link: Correct stream stop operations in snd_soc_link_trigger
In reply to Greg Kroah-Hartman5.15-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
@@ -175,7 +175,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 1979/2214 ASoC: ops: Fix return value in snd_soc_limit_volume()
In reply to Greg Kroah-Hartman5.15-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
@@ -624,7 +624,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);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)
@@ -636,7 +636,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;
@@ -646,10 +646,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 1980/2214 ASoC: soc-ac97: Fix error handling in snd_soc_new_ac97_component()
In reply to Greg Kroah-Hartman5.15-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
@@ -235,10 +235,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 1981/2214 ASoC: soc-component: Fix return type of snd_soc_pcm_component_pointer()
In reply to Greg Kroah-Hartman5.15-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
@@ -477,7 +477,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
@@ -921,7 +921,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 =asoc_substream_to_rtd (substream);struct snd_soc_component *component;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1982/2214 ASoC: mediatek: mt8195: make several arrays static const
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
[ Upstream commit 91745b034dca6044407b559fe28dd1cf7efccc29 ]
Don't populate various arrays on the stack but instead make them static const. Also makes the object code smaller by a few hundred bytes.
Stable-dep-of: c23390ecf5c0 ("ASoC: mediatek: mt8195: Fix register access clock error handling")
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +6 -6
@@ -321,7 +321,7 @@ int mt8195_afe_enable_reg_rw_clk(struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv;int i; -unsigned int clk_array[] = { +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 */ MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL ,/* bus clock for DRAM access */
@@ -342,7 +342,7 @@ int mt8195_afe_disable_reg_rw_clk(struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv;int i; -unsigned int clk_array[] = { +static const unsigned int clk_array[] = {MT8195_CLK_AUD_A1SYS ,MT8195_CLK_AUD_A1SYS_HP ,MT8195_CLK_AUD_AFE ,
@@ -375,11 +375,11 @@ static int mt8195_afe_enable_timing_sys(struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv;int i; -unsigned int clk_array[] = { +static const unsigned int clk_array[] = {MT8195_CLK_AUD_A1SYS ,MT8195_CLK_AUD_A2SYS , }; -unsigned int cg_array[] = { +static const unsigned int cg_array[] = {MT8195_TOP_CG_A1SYS_TIMING ,MT8195_TOP_CG_A2SYS_TIMING ,MT8195_TOP_CG_26M_TIMING ,
@@ -398,11 +398,11 @@ static int mt8195_afe_disable_timing_sys(struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv;int i; -unsigned int clk_array[] = { +static const unsigned int clk_array[] = {MT8195_CLK_AUD_A2SYS ,MT8195_CLK_AUD_A1SYS , }; -unsigned int cg_array[] = { +static const unsigned int cg_array[] = {MT8195_TOP_CG_26M_TIMING ,MT8195_TOP_CG_A2SYS_TIMING ,MT8195_TOP_CG_A1SYS_TIMING ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1983/2214 ASoC: mediatek: mt8195: Fix register access clock error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -320,7 +320,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 */
@@ -332,10 +332,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 1984/2214 ASoC: mediatek: mt8195: Fix timing system clock error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -383,7 +383,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 ,
@@ -394,13 +394,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 1985/2214 ASoC: mediatek: mt8195: enable apll tuner
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trevor Wu <[email protected]>
[ Upstream commit ff5a90173d981934e1134d28af3625acaab01d80 ]
Normally, the clock source of audio module is either 26M or APLL1/APLL2, but APLL1/APLL2 are not the multiple of 26M.
In the patch, APLL1 and APLL2 tuners are enabled to handle sample rate mismatch when the data path crosses two different clock domains.
Stable-dep-of: 9f1b48c658ac ("ASoC: mediatek: mt8195: Fix main clock error handling")
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 282 ++++++++++++++++++++- sound/soc/mediatek/mt8195/mt8195-afe-clk.h | 11 + sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 3 - 3 files changed, 292 insertions(+), 4 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +281 -1
@@ -40,6 +40,8 @@ static const char *aud_clks[MT8195_CLK_NUM] = { [MT8195_CLK_SCP_ADSP_AUDIODSP] = "scp_adsp_audiodsp",/* afe clock gate */ [MT8195_CLK_AUD_AFE] = "aud_afe", + [MT8195_CLK_AUD_APLL1_TUNER] = "aud_apll1_tuner", + [MT8195_CLK_AUD_APLL2_TUNER] = "aud_apll2_tuner", [MT8195_CLK_AUD_APLL] = "aud_apll", [MT8195_CLK_AUD_APLL2] = "aud_apll2", [MT8195_CLK_AUD_DAC] = "aud_dac",
@@ -77,6 +79,268 @@ static const char *aud_clks[MT8195_CLK_NUM] = { [MT8195_CLK_AUD_MEMIF_DL11] = "aud_memif_dl11", }; +struct mt8195_afe_tuner_cfg { +unsigned int id; +int apll_div_reg; +unsigned int apll_div_shift; +unsigned int apll_div_maskbit; +unsigned int apll_div_default; +int ref_ck_sel_reg; +unsigned int ref_ck_sel_shift; +unsigned int ref_ck_sel_maskbit; +unsigned int ref_ck_sel_default; +int tuner_en_reg; +unsigned int tuner_en_shift; +unsigned int tuner_en_maskbit; +int upper_bound_reg; +unsigned int upper_bound_shift; +unsigned int upper_bound_maskbit; +unsigned int upper_bound_default; +spinlock_t ctrl_lock;/* lock for apll tuner ctrl*/ +int ref_cnt; +}; + +static struct mt8195_afe_tuner_cfg mt8195_afe_tuner_cfgs[MT8195_AUD_PLL_NUM ] = { + [MT8195_AUD_PLL1 ] = { + .id =MT8195_AUD_PLL1 , + .apll_div_reg =AFE_APLL_TUNER_CFG , + .apll_div_shift =4 , + .apll_div_maskbit =0xf , + .apll_div_default =0x7 , + .ref_ck_sel_reg =AFE_APLL_TUNER_CFG , + .ref_ck_sel_shift =1 , + .ref_ck_sel_maskbit =0x3 , + .ref_ck_sel_default =0x2 , + .tuner_en_reg =AFE_APLL_TUNER_CFG , + .tuner_en_shift =0 , + .tuner_en_maskbit =0x1 , + .upper_bound_reg =AFE_APLL_TUNER_CFG , + .upper_bound_shift =8 , + .upper_bound_maskbit =0xff , + .upper_bound_default =0x2 , + }, + [MT8195_AUD_PLL2 ] = { + .id =MT8195_AUD_PLL2 , + .apll_div_reg =AFE_APLL_TUNER_CFG1 , + .apll_div_shift =4 , + .apll_div_maskbit =0xf , + .apll_div_default =0x7 , + .ref_ck_sel_reg =AFE_APLL_TUNER_CFG1 , + .ref_ck_sel_shift =1 , + .ref_ck_sel_maskbit =0x3 , + .ref_ck_sel_default =0x1 , + .tuner_en_reg =AFE_APLL_TUNER_CFG1 , + .tuner_en_shift =0 , + .tuner_en_maskbit =0x1 , + .upper_bound_reg =AFE_APLL_TUNER_CFG1 , + .upper_bound_shift =8 , + .upper_bound_maskbit =0xff , + .upper_bound_default =0x2 , + }, + [MT8195_AUD_PLL3 ] = { + .id =MT8195_AUD_PLL3 , + .apll_div_reg =AFE_EARC_APLL_TUNER_CFG , + .apll_div_shift =4 , + .apll_div_maskbit =0x3f , + .apll_div_default =0x3 , + .ref_ck_sel_reg =AFE_EARC_APLL_TUNER_CFG , + .ref_ck_sel_shift =24 , + .ref_ck_sel_maskbit =0x3 , + .ref_ck_sel_default =0x0 , + .tuner_en_reg =AFE_EARC_APLL_TUNER_CFG , + .tuner_en_shift =0 , + .tuner_en_maskbit =0x1 , + .upper_bound_reg =AFE_EARC_APLL_TUNER_CFG , + .upper_bound_shift =12 , + .upper_bound_maskbit =0xff , + .upper_bound_default =0x4 , + }, + [MT8195_AUD_PLL4 ] = { + .id =MT8195_AUD_PLL4 , + .apll_div_reg =AFE_SPDIFIN_APLL_TUNER_CFG , + .apll_div_shift =4 , + .apll_div_maskbit =0x3f , + .apll_div_default =0x7 , + .ref_ck_sel_reg =AFE_SPDIFIN_APLL_TUNER_CFG1 , + .ref_ck_sel_shift =8 , + .ref_ck_sel_maskbit =0x1 , + .ref_ck_sel_default =0 , + .tuner_en_reg =AFE_SPDIFIN_APLL_TUNER_CFG , + .tuner_en_shift =0 , + .tuner_en_maskbit =0x1 , + .upper_bound_reg =AFE_SPDIFIN_APLL_TUNER_CFG , + .upper_bound_shift =12 , + .upper_bound_maskbit =0xff , + .upper_bound_default =0x4 , + }, + [MT8195_AUD_PLL5 ] = { + .id =MT8195_AUD_PLL5 , + .apll_div_reg =AFE_LINEIN_APLL_TUNER_CFG , + .apll_div_shift =4 , + .apll_div_maskbit =0x3f , + .apll_div_default =0x3 , + .ref_ck_sel_reg =AFE_LINEIN_APLL_TUNER_CFG , + .ref_ck_sel_shift =24 , + .ref_ck_sel_maskbit =0x1 , + .ref_ck_sel_default =0 , + .tuner_en_reg =AFE_LINEIN_APLL_TUNER_CFG , + .tuner_en_shift =0 , + .tuner_en_maskbit =0x1 , + .upper_bound_reg =AFE_LINEIN_APLL_TUNER_CFG , + .upper_bound_shift =12 , + .upper_bound_maskbit =0xff , + .upper_bound_default =0x4 , + }, +}; + +static struct mt8195_afe_tuner_cfg *mt8195_afe_found_apll_tuner (unsigned int id) +{ +if (id >=MT8195_AUD_PLL_NUM ) +return NULL ; + +return &mt8195_afe_tuner_cfgs[id]; +} + +static int mt8195_afe_init_apll_tuner (unsigned int id) +{ +struct mt8195_afe_tuner_cfg *cfg =mt8195_afe_found_apll_tuner (id); + +if (!cfg) +return -EINVAL ; + + cfg->ref_cnt =0 ; +spin_lock_init (&cfg->ctrl_lock); + +return 0 ; +} + +static int mt8195_afe_setup_apll_tuner (struct mtk_base_afe *afe, +unsigned int id) +{ +const struct mt8195_afe_tuner_cfg *cfg =mt8195_afe_found_apll_tuner (id); + +if (!cfg) +return -EINVAL ; + +regmap_update_bits (afe->regmap, cfg->apll_div_reg, + cfg->apll_div_maskbit << cfg->apll_div_shift, + cfg->apll_div_default << cfg->apll_div_shift); + +regmap_update_bits (afe->regmap, cfg->ref_ck_sel_reg, + cfg->ref_ck_sel_maskbit << cfg->ref_ck_sel_shift, + cfg->ref_ck_sel_default << cfg->ref_ck_sel_shift); + +regmap_update_bits (afe->regmap, cfg->upper_bound_reg, + cfg->upper_bound_maskbit << cfg->upper_bound_shift, + cfg->upper_bound_default << cfg->upper_bound_shift); + +return 0 ; +} + +static int mt8195_afe_enable_tuner_clk (struct mtk_base_afe *afe, +unsigned int id) +{ +struct mt8195_afe_private *afe_priv = afe->platform_priv; + +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 ]); +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 ]); +break ; +default : +break ; + } + +return 0 ; +} + +static int mt8195_afe_disable_tuner_clk (struct mtk_base_afe *afe, +unsigned int id) +{ +struct mt8195_afe_private *afe_priv = afe->platform_priv; + +switch (id) { +case MT8195_AUD_PLL1 : +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER ]); +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); +break ; +case MT8195_AUD_PLL2 : +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER ]); +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); +break ; +default : +break ; + } + +return 0 ; +} + +static int mt8195_afe_enable_apll_tuner (struct mtk_base_afe *afe, +unsigned int id) +{ +struct mt8195_afe_tuner_cfg *cfg =mt8195_afe_found_apll_tuner (id); +unsigned long flags; +int ret =0 ; + +if (!cfg) +return -EINVAL ; + + ret =mt8195_afe_setup_apll_tuner (afe, id); +if (ret) +return ret; + + ret =mt8195_afe_enable_tuner_clk (afe, id); +if (ret) +return ret; + +spin_lock_irqsave (&cfg->ctrl_lock, flags); + + cfg->ref_cnt++; +if (cfg->ref_cnt ==1 ) +regmap_update_bits (afe->regmap, + cfg->tuner_en_reg, + cfg->tuner_en_maskbit << cfg->tuner_en_shift, +1 << cfg->tuner_en_shift); + +spin_unlock_irqrestore (&cfg->ctrl_lock, flags); + +return ret; +} + +static int mt8195_afe_disable_apll_tuner (struct mtk_base_afe *afe, +unsigned int id) +{ +struct mt8195_afe_tuner_cfg *cfg =mt8195_afe_found_apll_tuner (id); +unsigned long flags; +int ret =0 ; + +if (!cfg) +return -EINVAL ; + +spin_lock_irqsave (&cfg->ctrl_lock, flags); + + cfg->ref_cnt--; +if (cfg->ref_cnt ==0 ) +regmap_update_bits (afe->regmap, + cfg->tuner_en_reg, + cfg->tuner_en_maskbit << cfg->tuner_en_shift, +0 << cfg->tuner_en_shift); +else if (cfg->ref_cnt <0 ) + cfg->ref_cnt =0 ; + +spin_unlock_irqrestore (&cfg->ctrl_lock, flags); + + ret =mt8195_afe_disable_tuner_clk (afe, id); +if (ret) +return ret; + +return ret; +} +int mt8195_afe_get_mclk_source_clk_id (int sel) {switch (sel) {
@@ -113,7 +377,7 @@ int mt8195_afe_get_default_mclk_source_by_rate(int rate)int mt8195_afe_init_clock (struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv; -int i; +int i, ret;mt8195_audsys_clk_register (afe);
@@ -133,6 +397,16 @@ int mt8195_afe_init_clock(struct mtk_base_afe *afe) } } +/* initial tuner */ +for (i =0 ; i <MT8195_AUD_PLL_NUM ; i++) { + ret =mt8195_afe_init_apll_tuner (i); +if (ret) { +dev_dbg (afe->dev,"%s(), init apll_tuner%d failed" , + __func__, (i +1 )); +return -EINVAL ; + } + } +return 0 ; }
@@ -441,11 +715,17 @@ int mt8195_afe_enable_main_clock(struct mtk_base_afe *afe)mt8195_afe_enable_afe_on (afe); +mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL1 ); +mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL2 ); +return 0 ; }int mt8195_afe_disable_main_clock (struct mtk_base_afe *afe) { +mt8195_afe_disable_apll_tuner (afe,MT8195_AUD_PLL2 ); +mt8195_afe_disable_apll_tuner (afe,MT8195_AUD_PLL1 ); +mt8195_afe_disable_afe_on (afe);mt8195_afe_disable_timing_sys (afe);
sound/soc/mediatek/mt8195/mt8195-afe-clk.h +11 -0
@@ -35,6 +35,8 @@ enum {MT8195_CLK_INFRA_AO_AUDIO_26M_B ,MT8195_CLK_SCP_ADSP_AUDIODSP ,MT8195_CLK_AUD_AFE , +MT8195_CLK_AUD_APLL1_TUNER , +MT8195_CLK_AUD_APLL2_TUNER ,MT8195_CLK_AUD_APLL ,MT8195_CLK_AUD_APLL2 , MT8195_CLK_AUD_DAC,
@@ -84,6 +86,15 @@ enum { MT8195_MCK_SEL_NUM, }; +enum { +MT8195_AUD_PLL1 , +MT8195_AUD_PLL2 , +MT8195_AUD_PLL3 , +MT8195_AUD_PLL4 , +MT8195_AUD_PLL5 , +MT8195_AUD_PLL_NUM , +}; +struct mtk_base_afe ;int mt8195_afe_get_mclk_source_clk_id (int sel);
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +0 -3
@@ -2582,8 +2582,6 @@ static bool mt8195_is_volatile_reg(struct device *dev, unsigned int reg)case AFE_IRQ3_CON_MON :case AFE_IRQ_MCU_MON2 :case ADSP_IRQ_STATUS : -case AFE_APLL_TUNER_CFG : -case AFE_APLL_TUNER_CFG1 :case AUDIO_TOP_STA0 :case AUDIO_TOP_STA1 :case AFE_GAIN1_CUR :
@@ -2622,7 +2620,6 @@ static bool mt8195_is_volatile_reg(struct device *dev, unsigned int reg)case SPDIFIN_USERCODE10 :case SPDIFIN_USERCODE11 :case SPDIFIN_USERCODE12 : -case AFE_SPDIFIN_APLL_TUNER_CFG :case AFE_LINEIN_APLL_TUNER_MON :case AFE_EARC_APLL_TUNER_MON :case AFE_CM0_MON :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1986/2214 ASoC: mediatek: mt8195: Fix main clock error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -711,14 +711,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 1987/2214 ASoC: mediatek: mt8195: Fix paired memif clock error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -284,15 +284,23 @@ mt8195_afe_paired_memif_clk_prepare(struct snd_pcm_substream *substream,struct mt8195_afe_private *afe_priv = afe->platform_priv;int id =asoc_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]);
@@ -313,6 +321,7 @@ mt8195_afe_paired_memif_clk_enable(struct snd_pcm_substream *substream,struct mt8195_afe_private *afe_priv = afe->platform_priv;int id =asoc_rtd_to_cpu (rtd,0 )->id;int clk_id; +int ret;if (id !=MT8195_AFE_MEMIF_DL8 && id !=MT8195_AFE_MEMIF_DL10 )return 0 ;
@@ -320,11 +329,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 1988/2214 ASoC: mediatek: mt8195: Fix FE startup error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -362,24 +362,38 @@ static int mt8195_afe_fe_startup(struct snd_pcm_substream *substream,int id =asoc_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 1989/2214 ASoC: mediatek: mt8195: Check paired MEMIF clock enable in FE trigger
In reply to Greg Kroah-Hartman5.15-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
@@ -464,7 +464,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 1990/2214 ASoC: mediatek: mt8195: Fix runtime resume error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -2969,18 +2969,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 mt8195_afe_component_probe (struct snd_soc_component *component)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1991/2214 ASoC: mediatek: mt8195: Remove unnecessary print function dev_err()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Li <[email protected]>
[ Upstream commit 7d642c9c14b6fae0c05b91a92a86fae6674a2126 ]
The print function dev_err() is redundant because platform_get_irq() already prints an error.
Eliminate the follow coccicheck warning:
./sound/soc/mediatek/mt8195/mt8195-afe-pcm.c:3126:2-9: line 3126 is redundant because platform_get_irq() already prints an error
Stable-dep-of: 9d5dedb285fb ("ASoC: mediatek: mt8195: Propagate IRQ lookup errors")
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +1 -3
@@ -3167,10 +3167,8 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev)/* request irq */ irq_id =platform_get_irq (pdev,0 ); -if (irq_id <0 ) { -dev_err (dev,"%s no irq found\n" , dev->of_node->name); +if (irq_id <0 )return -ENXIO ; - } 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 1992/2214 ASoC: mediatek: mt8195: Propagate IRQ lookup errors
In reply to Greg Kroah-Hartman5.15-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
@@ -3168,7 +3168,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 1993/2214 ASoC: mediatek: mt8195: Fix ETDM MCLK error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -1500,9 +1500,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 1994/2214 ASoC: mediatek: mt8195: add dai id check before accessing array
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trevor Wu <[email protected]>
[ Upstream commit ff728899065922534d80170685fb807194d6487b ]
Coverity shows "afe_priv->dai_priv[dai_id] evaluates to an address that could be at negative offset of an array.". Add dai id check before accessing the array element. This ensures that the offset of an array must be a valid index.
Stable-dep-of: 8e67c67f3fd2 ("ASoC: mediatek: mt8195: Fix ETDM startup error handling")
--- sound/soc/mediatek/mt8195/mt8195-dai-adda.c | 17 +- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 177 +++++++++++++++++--- sound/soc/mediatek/mt8195/mt8195-dai-pcm.c | 26 ++- 3 files changed, 185 insertions(+), 35 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-adda.c +11 -6
@@ -704,13 +704,18 @@ static int mtk_dai_adda_hw_params(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; -struct mtk_dai_adda_priv *adda_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_adda_priv *adda_priv;unsigned int rate =params_rate (params); -int id = dai->id; -int ret =0 ; +int ret; + +if (dai->id !=MT8195_AFE_IO_DL_SRC && + dai->id !=MT8195_AFE_IO_UL_SRC1 && + dai->id !=MT8195_AFE_IO_UL_SRC2 ) +return -EINVAL ; + adda_priv = afe_priv->dai_priv[dai->id];dev_dbg (afe->dev,"%s(), id %d, stream %d, rate %d\n" , - __func__, id, substream->stream, rate); + __func__, dai->id, substream->stream, rate);if (rate >ADDA_HIRES_THRES ) adda_priv->hires_required =1 ;
@@ -718,9 +723,9 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, adda_priv->hires_required =0 ;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) - ret =mtk_dai_da_configure (afe, rate, id); + ret =mtk_dai_da_configure (afe, rate, dai->id);else - ret =mtk_dai_ad_configure (afe, rate, id); + ret =mtk_dai_ad_configure (afe, rate, dai->id);return ret; }
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +154 -23
371 lines not on this page · raw message
sound/soc/mediatek/mt8195/mt8195-dai-pcm.c +20 -6
@@ -122,17 +122,26 @@ static int mtk_dai_pcm_configure(struct snd_pcm_substream *substream,struct snd_pcm_runtime *const runtime = substream->runtime;struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; -unsigned int slave_mode = pcmif_priv->slave_mode; -unsigned int lrck_inv = pcmif_priv->lrck_inv; -unsigned int bck_inv = pcmif_priv->bck_inv; -unsigned int fmt = pcmif_priv->format; +struct mtk_dai_pcmif_priv *pcmif_priv; +unsigned int slave_mode; +unsigned int lrck_inv; +unsigned int bck_inv; +unsigned int fmt;unsigned int bit_width = dai->sample_bits;unsigned int val =0 ;unsigned int mask =0 ;int fs =0 ;int mode =0 ; +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; + slave_mode = pcmif_priv->slave_mode; + lrck_inv = pcmif_priv->lrck_inv; + bck_inv = pcmif_priv->bck_inv; + fmt = pcmif_priv->format; +/* sync freq mode */ fs =mt8195_afe_fs_timing (runtime->rate);if (fs <0 )
@@ -233,10 +242,15 @@ static int mtk_dai_pcm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_pcmif_priv *pcmif_priv;dev_dbg (dai->dev,"%s fmt 0x%x\n" , __func__, fmt); +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : pcmif_priv->format =MTK_DAI_PCM_FMT_I2S ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1995/2214 ASoC: mediatek: mt8195: Fix ETDM startup error handling
In reply to Greg Kroah-Hartman5.15-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 1996/2214 ASoC: mediatek: mt8195: Fix HDMI TX startup error handling
In reply to Greg Kroah-Hartman5.15-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 1997/2214 ASoC: mediatek: mt8195: Fix ETDM probe error handling
In reply to Greg Kroah-Hartman5.15-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
@@ -2527,6 +2527,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);
@@ -2534,15 +2535,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 struct snd_soc_dai_driver mtk_dai_etdm_driver[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1998/2214 tracing: Print the bucket size as unsigned
In reply to Greg Kroah-Hartman5.15-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
@@ -5269,7 +5269,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 1999/2214 tracing/histogram: Document expression arithmetic and constants
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kalesh Singh <[email protected]>
[ Upstream commit 2d2f6d4b8ce738ef43fc3436b43cecd2fea64152 ]
Histogram expressions now support division, and multiplication in addition to the already supported subtraction and addition operators.
Numeric constants can also be used in a hist trigger expressions or assigned to a variable and used by refernce in an expression.
Stable-dep-of: 289e2a775de4 ("tracing: Clamp the printed end of a histogram bucket at U64_MAX")
--- Documentation/trace/histogram.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/trace/histogram.rst +14 -0
@@ -1763,6 +1763,20 @@ using the same key and variable from yet another event:: # echo 'hist:key=pid:wakeupswitch_lat=$wakeup_lat+$switchtime_lat ...' >> event3/trigger +Expressions support the use of addition, subtraction, multiplication and +division operators (+-*/). + +Note that division by zero always returns -1. + +Numeric constants can also be used directly in an expression:: + + # echo 'hist:keys=next_pid:timestamp_secs=common_timestamp/1000000 ...' >> event/trigger + +or assigned to a variable and referenced in a subsequent expression:: + + # echo 'hist:keys=next_pid:us_per_sec=1000000 ...' >> event/trigger + # echo 'hist:keys=next_pid:timestamp_secs=common_timestamp/$us_per_sec ...' >> event/trigger + 2.2.2 Synthetic Events ----------------------
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2000/2214 tracing: docs: Update histogram doc for .percent/.graph and nohitcount
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 8c2b99790196d34a58a2b00a4c9862d2de3af3e2 ]
Update histogram document for .percent/.graph suffixes and 'nohitcount' option.
Stable-dep-of: 289e2a775de4 ("tracing: Clamp the printed end of a histogram bucket at U64_MAX")
--- Documentation/trace/histogram.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Documentation/trace/histogram.rst +9 -1
@@ -25,7 +25,7 @@ Documentation written by Tom Zanussi hist:keys=<field1[,field2,...]>[:values=<field1[,field2,...]>] [:sort=<field1[,field2,...]>][:size=#entries][:pause][:continue] - [:clear][:name=histname1][:<handler>.<action>] [if <filter>] + [:clear][:name=histname1][:nohitcount][:<handler>.<action>] [if <filter>] When a matching event is hit, an entry is added to a hash table using the key(s) and value(s) named. Keys and values correspond to
@@ -79,6 +79,8 @@ Documentation written by Tom Zanussi .log2 display log2 value rather than raw number .buckets=size display grouping of values rather than raw number .usecs display a common_timestamp in microseconds + .percent display a number of percentage value + .graph display a bar-graph of a value ============= ================================================= Note that in general the semantics of a given field aren't
@@ -137,6 +139,12 @@ Documentation written by Tom Zanussi existing trigger, rather than via the '>' operator, which will cause the trigger to be removed through truncation. + The 'nohitcount' (or NOHC) parameter will suppress display of + raw hitcount in the histogram. This option requires at least one + value field which is not a 'raw hitcount'. For example, + 'hist:...:vals=hitcount:nohitcount' is rejected, but + 'hist:...:vals=hitcount.percent:nohitcount' is OK. + - enable_hist/disable_hist The enable_hist and disable_hist triggers can be used to have one
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2001/2214 tracing/histogram: Document variable stacktrace
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt (Google) <[email protected]>
[ Upstream commit 88238513bb26713ef6d4418bdf1af062fe608bcb ]
Add a little documentation (and a useful example) of how a stacktrace can be used within a histogram variable and synthetic event.
Stable-dep-of: 289e2a775de4 ("tracing: Clamp the printed end of a histogram bucket at U64_MAX")
--- Documentation/trace/histogram.rst | 129 ++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)
Documentation/trace/histogram.rst +129 -0
@@ -81,6 +81,7 @@ Documentation written by Tom Zanussi .usecs display a common_timestamp in microseconds .percent display a number of percentage value .graph display a bar-graph of a value + .stacktrace display as a stacktrace (must by a long[] type) ============= ================================================= Note that in general the semantics of a given field aren't
@@ -1785,6 +1786,8 @@ or assigned to a variable and referenced in a subsequent expression:: # echo 'hist:keys=next_pid:us_per_sec=1000000 ...' >> event/trigger # echo 'hist:keys=next_pid:timestamp_secs=common_timestamp/$us_per_sec ...' >> event/trigger +Variables can even hold stacktraces, which are useful with synthetic events. + 2.2.2 Synthetic Events ----------------------
@@ -1939,6 +1942,132 @@ the ".buckets" modifier and specify a size (in this case groups of 10). Entries: 16 Dropped: 0 +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: + + # cd /sys/kernel/tracing + # echo 's:block_lat pid_t pid; u64 delta; unsigned long[] stack;' > dynamic_events + # echo 'hist:keys=next_pid:ts=common_timestamp.usecs,st=stacktrace if prev_state == 2' >> events/sched/sched_switch/trigger + # echo 'hist:keys=prev_pid:delta=common_timestamp.usecs-$ts,s=$st:onmax($delta).trace(block_lat,prev_pid,$delta,$s)' >> events/sched/sched_switch/trigger + # echo 1 > events/synthetic/block_lat/enable + # cat trace + + # tracer: nop + # + # entries-in-buffer/entries-written: 2/2 #P:8 + # + # _-----=> irqs-off/BH-disabled + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + <idle>-0 [005] d..4. 521.164922: block_lat: pid=0 delta=8322 stack=STACK: + => __schedule+0x448/0x7b0 + => schedule+0x5a/0xb0 + => io_schedule+0x42/0x70 + => bit_wait_io+0xd/0x60 + => __wait_on_bit+0x4b/0x140 + => out_of_line_wait_on_bit+0x91/0xb0 + => jbd2_journal_commit_transaction+0x1679/0x1a70 + => kjournald2+0xa9/0x280 + => kthread+0xe9/0x110 + => ret_from_fork+0x2c/0x50 + + <...>-2 [004] d..4. 525.184257: block_lat: pid=2 delta=76 stack=STACK: + => __schedule+0x448/0x7b0 + => schedule+0x5a/0xb0 + => schedule_timeout+0x11a/0x150 + => wait_for_completion_killable+0x144/0x1f0 + => __kthread_create_on_node+0xe7/0x1e0 + => kthread_create_on_node+0x51/0x70 + => create_worker+0xcc/0x1a0 + => worker_thread+0x2ad/0x380 + => kthread+0xe9/0x110 + => ret_from_fork+0x2c/0x50 + +A synthetic event that has a stacktrace field may use it as a key in histogram: + + # echo 'hist:delta.buckets=100,stack.stacktrace:sort=delta' > events/synthetic/block_lat/trigger + # cat events/synthetic/block_lat/hist + + # event histogram + # + # trigger info: hist:keys=delta.buckets=100,stacktrace:vals=hitcount:sort=delta.buckets=100:size=2048 [active] + # + + { delta: ~ 0-99, stacktrace: + event_hist_trigger+0x464/0x480 + event_triggers_call+0x52/0xe0 + trace_event_buffer_commit+0x193/0x250 + trace_event_raw_event_sched_switch+0xfc/0x150 + __traceiter_sched_switch+0x41/0x60 + __schedule+0x448/0x7b0 + schedule_idle+0x26/0x40 + cpu_startup_entry+0x19/0x20 + start_secondary+0xed/0xf0 + secondary_startup_64_no_verify+0xe0/0xeb + } hitcount: 6 + { delta: ~ 0-99, stacktrace: + event_hist_trigger+0x464/0x480 + event_triggers_call+0x52/0xe0 + trace_event_buffer_commit+0x193/0x250 + trace_event_raw_event_sched_switch+0xfc/0x150 + __traceiter_sched_switch+0x41/0x60 + __schedule+0x448/0x7b0 + schedule_idle+0x26/0x40 + cpu_startup_entry+0x19/0x20 + __pfx_kernel_init+0x0/0x10 + arch_call_rest_init+0xa/0x24 + start_kernel+0x964/0x98d + secondary_startup_64_no_verify+0xe0/0xeb + } hitcount: 3 + { delta: ~ 0-99, stacktrace: + event_hist_trigger+0x464/0x480 + event_triggers_call+0x52/0xe0 + trace_event_buffer_commit+0x193/0x250 + trace_event_raw_event_sched_switch+0xfc/0x150 + __traceiter_sched_switch+0x41/0x60 + __schedule+0x448/0x7b0 + schedule+0x5a/0xb0 + worker_thread+0xaf/0x380 + kthread+0xe9/0x110 + ret_from_fork+0x2c/0x50 + } hitcount: 1 + { delta: ~ 100-199, stacktrace: + event_hist_trigger+0x464/0x480 + event_triggers_call+0x52/0xe0 + trace_event_buffer_commit+0x193/0x250 + trace_event_raw_event_sched_switch+0xfc/0x150 + __traceiter_sched_switch+0x41/0x60 + __schedule+0x448/0x7b0 + schedule_idle+0x26/0x40 + cpu_startup_entry+0x19/0x20 + start_secondary+0xed/0xf0 + secondary_startup_64_no_verify+0xe0/0xeb + } hitcount: 15 + [..] + { delta: ~ 8500-8599, stacktrace: + event_hist_trigger+0x464/0x480 + event_triggers_call+0x52/0xe0 + trace_event_buffer_commit+0x193/0x250 + trace_event_raw_event_sched_switch+0xfc/0x150 + __traceiter_sched_switch+0x41/0x60 + __schedule+0x448/0x7b0 + schedule_idle+0x26/0x40 + cpu_startup_entry+0x19/0x20 + start_secondary+0xed/0xf0 + secondary_startup_64_no_verify+0xe0/0xeb + } hitcount: 1 + + Totals: + Hits: 89 + Entries: 11 + Dropped: 0 + 2.2.3 Hist trigger 'handlers' and 'actions' -------------------------------------------
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2002/2214 tracing: Clamp the printed end of a histogram bucket at U64_MAX
In reply to Greg Kroah-Hartman5.15-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
@@ -1942,6 +1942,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
@@ -4822,9 +4822,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 2003/2214 tracing: Print a signed histogram key as signed
In reply to Greg Kroah-Hartman5.15-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
@@ -207,6 +207,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,
@@ -4835,7 +4843,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 2004/2214 macsec: prevent AES-GCM nonce reuse after packet number wrap
In reply to Greg Kroah-Hartman5.15-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
@@ -496,6 +496,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
@@ -503,6 +506,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 2005/2214 net: usb: lan78xx: reject invalid EEPROM write requests
In reply to Greg Kroah-Hartman5.15-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
@@ -1428,13 +1428,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 2006/2214 HID: wacom: fix wacom_intuos_irq NULL pen_input deref
In reply to Greg Kroah-Hartman5.15-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
@@ -1073,10 +1073,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 &&
@@ -1087,23 +1087,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 2007/2214 bpftool: Fix inverted tracefs validation when scanning /proc/mounts
In reply to Greg Kroah-Hartman5.15-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
@@ -88,7 +88,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 2008/2214 blk-iocost: charge zone appends as writes
In reply to Greg Kroah-Hartman5.15-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
@@ -2537,6 +2537,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 2009/2214 blk-iocost: account zone append completions in latency stats
In reply to Greg Kroah-Hartman5.15-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
@@ -2581,6 +2581,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 ;
@@ -2817,6 +2818,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 2010/2214 ima: reject a kexec buffer whose declared size exceeds the buffer
In reply to Greg Kroah-Hartman5.15-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
@@ -445,6 +445,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 2011/2214 usbnet: fix smp_processor_id() use in preemptible context
In reply to Greg Kroah-Hartman5.15-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
@@ -331,7 +331,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;
@@ -344,10 +344,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); stats64->rx_packets++; 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);
@@ -1282,13 +1284,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); stats64->tx_packets += entry->packets; 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 2012/2214 ALSA: 6fire: take stream_mutex in the Digital Thru control
In reply to Greg Kroah-Hartman5.15-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 2013/2214 ARC: Strip libgcc debug information when generating BTF
In reply to Greg Kroah-Hartman5.15-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
@@ -92,7 +92,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 2014/2214 ASoC: codecs: da732x: Fix definition of ADC2 EQ Overall Volume control
In reply to Greg Kroah-Hartman5.15-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 2015/2214 ASoC: codecs: sta32x: Fix definition of Ch2 and Ch3 Volume Bypass controls
In reply to Greg Kroah-Hartman5.15-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
@@ -468,8 +468,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 2016/2214 ASoC: codecs: sta350: Fix definition of Ch2 and Ch3 Volume Bypass controls
In reply to Greg Kroah-Hartman5.15-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
@@ -485,9 +485,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 2017/2214 calipso: update payload_len when removing the CALIPSO option
In reply to Greg Kroah-Hartman5.15-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
@@ -1432,6 +1432,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 2018/2214 gre: keep the UDP tunnel GSO type when completing GRO
In reply to Greg Kroah-Hartman5.15-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
@@ -243,7 +243,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 2019/2214 bpf: Fix verifier WARN on narrow read of bpf_tcp_sock u64 fields
In reply to Greg Kroah-Hartman5.15-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
@@ -6811,8 +6811,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 2020/2214 bpf: Validate the SRH which End.DT6 uncovers in End.BPF
In reply to Greg Kroah-Hartman5.15-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
@@ -6212,15 +6212,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 2021/2214 bpf: Pull the inner header for End.DT6 in End.BPF
In reply to Greg Kroah-Hartman5.15-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
@@ -6252,9 +6252,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 2022/2214 bpf: Update the SRH state if End.B6 fails late
In reply to Greg Kroah-Hartman5.15-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
@@ -6273,8 +6273,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 :
@@ -6282,8 +6282,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 2023/2214 bpf: Clear sk_refcnt of a clone before its storage is linked
In reply to Greg Kroah-Hartman5.15-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
@@ -197,6 +197,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 2024/2214 bpf: Bound the nesting that the BTF show code follows
In reply to Greg Kroah-Hartman5.15-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
@@ -792,6 +792,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)
@@ -1183,8 +1185,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 2025/2214 bpf: Dont take an extension for an iterator program
In reply to Greg Kroah-Hartman5.15-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
@@ -335,6 +335,13 @@ bool bpf_iter_prog_supported(struct bpf_prog *prog)int prefix_len =strlen (prefix);bool supported = false; +/* +* 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 false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2026/2214 netfilter: conntrack: fix unlikely UaF in gc worker
In reply to Greg Kroah-Hartman5.15-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
@@ -2590,6 +2590,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 2027/2214 selftests: netfilter: conntrack_vrf.sh: move to lib.sh infra
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 954398b4d83759244656d37b4b626e912dc0969c ]
swap test for "ip" with "conntrack", former is already accounted for via setup_ns helper. Also switch to bash.
Stable-dep-of: a20a01ae8981 ("selftests: netfilter: fix return value in zone subtest")
--- .../selftests/netfilter/conntrack_vrf.sh | 101 +++++++----------- 1 file changed, 39 insertions(+), 62 deletions(-)
tools/testing/selftests/netfilter/conntrack_vrf.sh +39 -62
@@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # This script demonstrates interaction of conntrack and vrf. # The vrf driver calls the netfilter hooks again, with oif/iif
@@ -28,84 +28,65 @@ # that was supposed to be fixed by the commit mentioned above to make sure # that any fix to test case 1 won't break masquerade again. -ksft_skip=4 +source lib.sh IP0=172.30.30.1 IP1=172.30.30.2 PFXL=30 ret=0 -sfx=$(mktemp -u "XXXXXXXX") -ns0="ns0-$sfx" -ns1="ns1-$sfx" - cleanup() { ip netns pids $ns0 | xargs kill 2>/dev/null ip netns pids $ns1 | xargs kill 2>/dev/null - ip netns del $ns0 $ns1 + cleanup_all_ns } -nft --version > /dev/null 2>&1 -if [ $? -ne 0 ];then +if ! nft --version > /dev/null 2>&1;then echo "SKIP: Could not run test without nft tool" exit $ksft_skip fi -ip -Version > /dev/null 2>&1 -if [ $? -ne 0 ];then - echo "SKIP: Could not run test without ip tool" - exit $ksft_skip -fi - -ip netns add "$ns0" -if [ $? -ne 0 ];then - echo "SKIP: Could not create net namespace $ns0" +if ! conntrack --version > /dev/null 2>&1;then + echo "SKIP: Could not run test without conntrack tool" exit $ksft_skip fi -ip netns add "$ns1" trap cleanup EXIT -ip netns exec $ns0 sysctl -q -w net.ipv4.conf.default.rp_filter=0 -ip netns exec $ns0 sysctl -q -w net.ipv4.conf.all.rp_filter=0 -ip netns exec $ns0 sysctl -q -w net.ipv4.conf.all.rp_filter=0 +setup_ns ns0 ns1 -ip link add veth0 netns "$ns0" type veth peer name veth0 netns "$ns1" > /dev/null 2>&1 -if [ $? -ne 0 ];then +ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.default.rp_filter=0 +ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.rp_filter=0 +ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.rp_filter=0 + +if ! ip link add veth0 netns "$ns0" type veth peer name veth0 netns "$ns1" > /dev/null 2>&1; then echo "SKIP: Could not add veth device" exit $ksft_skip fi -ip -net $ns0 li add tvrf type vrf table 9876 -if [ $? -ne 0 ];then +if ! ip -net "$ns0" li add tvrf type vrf table 9876; then echo "SKIP: Could not add vrf device" exit $ksft_skip fi -ip -net $ns0 li set lo up - -ip -net $ns0 li set veth0 master tvrf -ip -net $ns0 li set tvrf up -ip -net $ns0 li set veth0 up -ip -net $ns1 li set veth0 up +ip -net "$ns0" li set veth0 master tvrf +ip -net "$ns0" li set tvrf up +ip -net "$ns0" li set veth0 up +ip -net "$ns1" li set veth0 up -ip -net $ns0 addr add $IP0/$PFXL dev veth0 -ip -net $ns1 addr add $IP1/$PFXL dev veth0 +ip -net "$ns0" addr add $IP0/$PFXL dev veth0 +ip -net "$ns1" addr add $IP1/$PFXL dev veth0 -ip netns exec $ns1 iperf3 -s > /dev/null 2>&1& -if [ $? -ne 0 ];then - echo "SKIP: Could not start iperf3" - exit $ksft_skip -fi +ip netns exec "$ns1" iperf3 -s > /dev/null 2>&1 & # test vrf ingress handling. # The incoming connection should be placed in conntrack zone 1, # as decided by the first iteration of the ruleset. test_ct_zone_in() { -ip netns exec $ns0 nft -f - <<EOF +ip netns exec "$ns0" nft -f - <<EOF table testct { chain rawpre { type filter hook prerouting priority raw;
@@ -126,21 +107,21 @@ table testct { } } EOF - ip netns exec $ns1 ping -W 1 -c 1 -I veth0 $IP0 > /dev/null + ip netns exec "$ns1" ping -W 1 -c 1 -I veth0 "$IP0" > /dev/null # should be in zone 1, not zone 2 - count=$(ip netns exec $ns0 conntrack -L -s $IP1 -d $IP0 -p icmp --zone 1 2>/dev/null | wc -l) - if [ $count -eq 1 ]; then + count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 1 2>/dev/null | wc -l) + if [ "$count" -eq 1 ]; then echo "PASS: entry found in conntrack zone 1" else echo "FAIL: entry not found in conntrack zone 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 + 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" else echo "FAIL: entry not in zone 1 or 2, dumping table" - ip netns exec $ns0 conntrack -L - ip netns exec $ns0 nft list ruleset + ip netns exec "$ns0" conntrack -L + ip netns exec "$ns0" nft list ruleset fi fi }
@@ -153,12 +134,12 @@ test_masquerade_vrf() local qdisc=$1 if [ "$qdisc" != "default" ]; then - tc -net $ns0 qdisc add dev tvrf root $qdisc + tc -net "$ns0" qdisc add dev tvrf root "$qdisc" fi - ip netns exec $ns0 conntrack -F 2>/dev/null + ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec $ns0 nft -f - <<EOF +ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain rawout {
@@ -179,17 +160,15 @@ table ip nat { } } EOF - ip netns exec $ns0 ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null - if [ $? -ne 0 ]; then + if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null; then echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on vrf device" ret=1 return fi # must also check that nat table was evaluated on second (lower device) iteration. - ip netns exec $ns0 nft list table ip nat |grep -q 'counter packets 2' && - ip netns exec $ns0 nft list table ip nat |grep -q 'untracked counter packets [1-9]' - if [ $? -eq 0 ]; then + ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2' && + if ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then echo "PASS: iperf3 connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" else echo "FAIL: vrf rules have unexpected counter value"
@@ -197,7 +176,7 @@ EOF fi if [ "$qdisc" != "default" ]; then - tc -net $ns0 qdisc del dev tvrf root + tc -net "$ns0" qdisc del dev tvrf root fi }
@@ -206,8 +185,8 @@ EOF # oifname is the lower device (veth0 in this case). test_masquerade_veth() { - ip netns exec $ns0 conntrack -F 2>/dev/null -ip netns exec $ns0 nft -f - <<EOF + ip netns exec "$ns0" conntrack -F 2>/dev/null +ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain postrouting {
@@ -216,16 +195,14 @@ table ip nat { } } EOF - ip netns exec $ns0 ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null - if [ $? -ne 0 ]; then + if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null; then echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on veth device" ret=1 return fi # must also check that nat table was evaluated on second (lower device) iteration. - ip netns exec $ns0 nft list table ip nat |grep -q 'counter packets 2' - if [ $? -eq 0 ]; then + if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2'; then echo "PASS: iperf3 connect with masquerade + sport rewrite on veth device" else echo "FAIL: vrf masq rule has unexpected counter value"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2028/2214 selftests: netfilter: conntrack_vrf.sh: prefer socat, not iperf3
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 99bc5950ebd4f84e48b5d1c53c13cf117031de82 ]
Use socat, like most of the other scripts already do. This also makes the script complete slightly faster (3s -> 1s).
iperf3 establishes two connections (1 control connection, and 1+x depending on test), so adjust expected counter values as well.
Stable-dep-of: a20a01ae8981 ("selftests: netfilter: fix return value in zone subtest")
--- .../selftests/netfilter/conntrack_vrf.sh | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-)
tools/testing/selftests/netfilter/conntrack_vrf.sh +21 -19
@@ -43,15 +43,9 @@ cleanup() cleanup_all_ns } -if ! nft --version > /dev/null 2>&1;then - echo "SKIP: Could not run test without nft tool" - exit $ksft_skip -fi - -if ! conntrack --version > /dev/null 2>&1;then - echo "SKIP: Could not run test without conntrack tool" - exit $ksft_skip -fi +checktool "nft --version" "run test without nft" +checktool "conntrack --version" "run test without conntrack" +checktool "socat -h" "run test without socat" trap cleanup EXIT
@@ -79,7 +73,15 @@ ip -net "$ns1" li set veth0 up ip -net "$ns0" addr add $IP0/$PFXL dev veth0 ip -net "$ns1" addr add $IP1/$PFXL dev veth0 -ip netns exec "$ns1" iperf3 -s > /dev/null 2>&1 & +listener_ready() +{ + local ns="$1" + + ss -N "$ns" -l -n -t -o "sport = :55555" | grep -q "55555" +} + +ip netns exec "$ns1" socat -u -4 TCP-LISTEN:55555,reuseaddr,fork STDOUT > /dev/null & +busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1" # test vrf ingress handling. # The incoming connection should be placed in conntrack zone 1,
@@ -160,16 +162,16 @@ table ip nat { } } EOF - if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null; then - echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on vrf device" + 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 return fi # must also check that nat table was evaluated on second (lower device) iteration. - ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2' && - if ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then - echo "PASS: iperf3 connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" + if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 1' && + ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then + echo "PASS: connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" else echo "FAIL: vrf rules have unexpected counter value" ret=1
@@ -195,15 +197,15 @@ table ip nat { } } EOF - if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null; then - echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on veth device" + 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 return fi # must also check that nat table was evaluated on second (lower device) iteration. - if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2'; then - echo "PASS: iperf3 connect with masquerade + sport rewrite on veth device" + if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 1'; then + echo "PASS: connect with masquerade + sport rewrite on veth device" else echo "FAIL: vrf masq rule has unexpected counter value" ret=1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2029/2214 selftests: netfilter: fix return value in zone subtest
In reply to Greg Kroah-Hartman5.15-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/netfilter/conntrack_vrf.sh | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
tools/testing/selftests/netfilter/conntrack_vrf.sh +22 -3
@@ -88,7 +88,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;
@@ -109,6 +109,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
@@ -117,6 +123,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"
@@ -141,7 +148,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 {
@@ -162,6 +169,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
@@ -188,7 +201,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 {
@@ -197,6 +210,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 2030/2214 netfilter: nft_compat: restrict raw table targets/matches
In reply to Greg Kroah-Hartman5.15-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 2031/2214 bpf: Dont take a program with a target program for an iterator
In reply to Greg Kroah-Hartman5.15-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
@@ -336,10 +336,10 @@ bool bpf_iter_prog_supported(struct bpf_prog *prog)bool supported = false;/* -* 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 2032/2214 usb: gadget: dummy_hcd: fix SuperSpeed ep0 maxpacket
In reply to Greg Kroah-Hartman5.15-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
@@ -914,7 +914,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 2033/2214 usb: gadget: dummy_hcd: prevent unbind via sysfs
In reply to Greg Kroah-Hartman5.15-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
@@ -1181,6 +1181,7 @@ static struct platform_driver dummy_udc_driver = { .resume = dummy_udc_resume, .driver = { .name = gadget_name, + .suppress_bind_attrs = true, }, };
@@ -2790,6 +2791,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
Greg Kroah-Hartman
maintainerPATCH 2034/2214 power: supply: gpio-charger: Report discharging without input power
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Velkov <[email protected]>
[ Upstream commit f0f400459bf6a037e70768de623fff3f8920b8bb ]
The status property follows only the charge-status GPIO. Without input power a charger such as the BQ24133 releases its open-drain STAT pin, and depending on the board the GPIO then reads as charging.
On Kobol Helios64 the board runs from its battery after a mains loss, and the charger reports online 0 with status "Charging".
Report "Discharging" whenever the online GPIO is present and inactive.
--- drivers/power/supply/gpio-charger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/gpio-charger.c +4 -1
@@ -100,7 +100,10 @@ static int gpio_charger_get_property(struct power_supply *psy, val->intval =gpiod_get_value_cansleep (gpio_charger->gpiod);break ;case POWER_SUPPLY_PROP_STATUS : -if (gpiod_get_value_cansleep (gpio_charger->charge_status)) +/* Without input power the battery discharges, whatever the status pin says */ +if (gpio_charger->gpiod && !gpiod_get_value_cansleep (gpio_charger->gpiod)) + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; +else if (gpiod_get_value_cansleep (gpio_charger->charge_status)) val->intval =POWER_SUPPLY_STATUS_CHARGING ;else val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2035/2214 RDMA/core: Preserve the selected source GID on failed AH modification
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit d01ee4c84193196b6e4be4caf1ff8fdcc441ed96 ]
When an address-handle modification fails, the core replaces its source-GID reference. The old address then loses the reference which keeps its source entry alive.
--- drivers/infiniband/core/verbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/core/verbs.c +2 -1
@@ -956,7 +956,8 @@ int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr) ah->device->ops.modify_ah(ah, ah_attr) : -EOPNOTSUPP ; - ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr); +if (!ret) + ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr);rdma_unfill_sgid_attr (ah_attr, old_sgid_attr);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2036/2214 RDMA/core: Remove device argument from rdma_build_skb()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunsheng Lin <[email protected]>
[ Upstream commit 05195dcb43504e381bf383e837fc935aac4258cc ]
'device' argument is never used since rdma_build_skb() is introduced, so remove it.
Stable-dep-of: fdfd099222d9 ("RDMA/core: Reject LAG selection when source MAC lookup fails")
--- drivers/infiniband/core/lag.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/infiniband/core/lag.c +2 -3
@@ -7,8 +7,7 @@#include <rdma/ib_cache.h> #include <rdma/lag.h> -static struct sk_buff *rdma_build_skb (struct ib_device *device, -struct net_device *netdev, +static struct sk_buff *rdma_build_skb (struct net_device *netdev,struct rdma_ah_attr *ah_attr,gfp_t flags) {
@@ -86,7 +85,7 @@ static struct net_device *rdma_get_xmit_slave_udp(struct ib_device *device,struct net_device *slave;struct sk_buff *skb; - skb =rdma_build_skb (device, master, ah_attr, flags); + skb =rdma_build_skb (master, ah_attr, flags);if (!skb)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2037/2214 RDMA/core: Reject LAG selection when source MAC lookup fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit fdfd099222d9de9e2f1b8d69e94494c5489272cc ]
GID deletion can clear the source device association after LAG lookup retains the bonding master. Ignoring the resulting L2 lookup failure copies uninitialized source MAC bytes into the synthetic hash packet.
Read the source MAC before allocating the packet and propagate lookup errors to the caller, so failed lookups cannot influence slave selection.
--- drivers/infiniband/core/lag.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/infiniband/core/lag.c +8 -4
@@ -19,6 +19,11 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,u8 smac[ETH_ALEN ];bool is_ipv4;int hdr_len; +int ret; + + ret =rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac); +if (ret) +return ERR_PTR (ret); is_ipv4 =ipv6_addr_v4mapped ((struct in6_addr *)ah_attr->grh.dgid.raw); hdr_len =ETH_HLEN +sizeof (struct udphdr ) +LL_RESERVED_SPACE (netdev);
@@ -26,7 +31,7 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev, skb =alloc_skb (hdr_len, flags);if (!skb) -return NULL ; +return ERR_PTR (-ENOMEM ); skb->dev = netdev;skb_reserve (skb, hdr_len);
@@ -70,7 +75,6 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,skb_reset_mac_header (skb); eth =eth_hdr (skb); skb->protocol = eth->h_proto =htons (is_ipv4 ?ETH_P_IP :ETH_P_IPV6 ); -rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac);memcpy (eth->h_source, smac,ETH_ALEN );memcpy (eth->h_dest, ah_attr->roce.dmac,ETH_ALEN );
@@ -86,8 +90,8 @@ static struct net_device *rdma_get_xmit_slave_udp(struct ib_device *device,struct sk_buff *skb; skb =rdma_build_skb (master, ah_attr, flags); -if (!skb) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (skb)) +return ERR_CAST (skb);rcu_read_lock (); slave = netdev_get_xmit_slave(master, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2038/2214 RDMA/srp: Avoid reading uninitialized has_port on srp_parse_in() failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 4b8f20dc8d25f575e8b8bb5abb09ab803a7e1a3f ]
srp_parse_in() returns -ENOMEM without initializing *has_port if kstrdup() fails. Only check has_port when srp_parse_in() succeeds.
--- drivers/infiniband/ulp/srp/ib_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -3469,7 +3469,7 @@ static int srp_parse_options(struct net *net, const char *buf, } ret =srp_parse_in (net, &target->rdma_cm.dst.ss, p, &has_port); -if (!has_port) +if (ret ==0 && !has_port) ret = -EINVAL ;if (ret <0 ) {pr_warn ("bad dest parameter '%s'\n" , p);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2039/2214 ASoC: codecs: sta32x: Fix definition of limiter threshold controls
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit e06bf60ee5bffa9eeacff0bf8b03d4572b04f67d ]
The limiter attack and release thresholds are the two 4-bit halves of one register, so their maximum is 15, not 16. With 16 the controls on bits 3:0 also write bit 4, which belongs to the other threshold.
--- sound/soc/codecs/sta32x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/sta32x.c +8 -8
@@ -484,21 +484,21 @@ SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta32x_limiter2_release_rate_enum),* two different enum definitions; provide both */ SOC_SINGLE_TLV ("Limiter1 Attack Threshold (AC Mode)" ,STA32X_L1ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_ac_attack_tlv), +15 ,0 , sta32x_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (AC Mode)" ,STA32X_L2ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_ac_attack_tlv), +15 ,0 , sta32x_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (AC Mode)" ,STA32X_L1ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_ac_release_tlv), +15 ,0 , sta32x_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (AC Mode)" ,STA32X_L2ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_ac_release_tlv), +15 ,0 , sta32x_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter1 Attack Threshold (DRC Mode)" ,STA32X_L1ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_drc_attack_tlv), +15 ,0 , sta32x_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (DRC Mode)" ,STA32X_L2ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_drc_attack_tlv), +15 ,0 , sta32x_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (DRC Mode)" ,STA32X_L1ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_drc_release_tlv), +15 ,0 , sta32x_limiter_drc_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (DRC Mode)" ,STA32X_L2ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_drc_release_tlv), +15 ,0 , sta32x_limiter_drc_release_tlv),BIQUAD_COEFS ("Ch1 - Biquad 1" ,0 ), BIQUAD_COEFS("Ch1 - Biquad 2", 5),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2040/2214 ASoC: codecs: sta350: Fix definition of limiter threshold controls
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 77623752c156763d7a80414afe5b769ba4532bd3 ]
The limiter attack and release thresholds are the two 4-bit halves of one register, so their maximum is 15, not 16. With 16 the controls on bits 3:0 also write bit 4, which belongs to the other threshold.
--- sound/soc/codecs/sta350.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/sta350.c +8 -8
@@ -510,28 +510,28 @@ SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta350_limiter2_release_rate_enum),*/ SOC_SINGLE_TLV ("Limiter1 Attack Threshold (AC Mode)" ,STA350_L1ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_ac_attack_tlv), +15 ,0 , sta350_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (AC Mode)" ,STA350_L2ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_ac_attack_tlv), +15 ,0 , sta350_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (AC Mode)" ,STA350_L1ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_ac_release_tlv), +15 ,0 , sta350_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (AC Mode)" ,STA350_L2ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_ac_release_tlv), +15 ,0 , sta350_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter1 Attack Threshold (DRC Mode)" ,STA350_L1ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_drc_attack_tlv), +15 ,0 , sta350_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (DRC Mode)" ,STA350_L2ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_drc_attack_tlv), +15 ,0 , sta350_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (DRC Mode)" ,STA350_L1ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_drc_release_tlv), +15 ,0 , sta350_limiter_drc_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (DRC Mode)" ,STA350_L2ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_drc_release_tlv), +15 ,0 , sta350_limiter_drc_release_tlv),BIQUAD_COEFS ("Ch1 - Biquad 1" ,0 ), BIQUAD_COEFS("Ch1 - Biquad 2", 5),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2041/2214 RDMA/rxe: Clear pkt->qp before the early drop exits in rxe_rcv()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiwei Zhang <[email protected]>
[ Upstream commit 7d7214b39b14c9763c14445b139f63369063b65e ]
rxe_rcv() puts pkt->qp at its drop label, but leaves pkt->qp uninitialized on the two paths that take an early goto:
if (unlikely(skb->len < RXE_BTH_BYTES)) goto drop; if (rxe_chk_dgid(rxe, skb) < 0) goto drop; pkt->opcode = bth_opcode(pkt); pkt->psn = bth_psn(pkt); pkt->qp = NULL; <- too late for the gotos above ... drop: if (pkt->qp) rxe_put(pkt->qp);
pkt points into skb->cb, which rxe does not own at this point: the network stack has used that space for its own state. For IPv6, ip6_rcv_core() memsets inet6_skb_parm and then writes
IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
at offset 14, so the qword at cb + 8, which is where pkt->qp lives, reads back as 0x0006000000000000 for every IPv6 packet.
Any IPv6 datagram to port 4791 whose payload is shorter than the BTH takes the first goto and reaches the drop label with that value, so rxe_put() runs refcount_dec_and_test() on 0x0006000000000150 and the kernel faults, in softirq, on a non-canonical address:
general protection fault, probably for non-canonical address 0x0006000000000150: 0000 [#1] PREEMPT SMP RIP: 0010:__rxe_put+0x.../... Call Trace: <IRQ> rxe_rcv+0x.../... [rdma_rxe] rxe_udp_encap_recv+0x.../... [rdma_rxe] udp_queue_rcv_one_skb ... Kernel panic - not syncing: Fatal exception in interrupt
The fault happens in softirq, so it panics even with panic_on_oops=0, and with panic=0 the machine hangs until it is power cycled. A remote sender only needs to send an empty UDP datagram to port 4791; no RDMA connection, GID or other state is involved and the rxe socket is bound in init_net.
IPv4 is not affected: ip_rcv_core() memsets the whole inet_skb_parm, so the pkt->qp slot is zero there.
Fix by clearing pkt->qp before the first early exit. pkt->qp is only ever assigned a reference-owning value by hdr_check() and rxe_rcv_mcast_pkt(), both of which run after this point, so the put at the drop label stays balanced.
The ordering has been unsafe since the driver was merged: the two early gotos have preceded pkt->qp = NULL in every version since 8700e3e7c485.
Testing done: the driver was built and run on a 6.2 vendor tree that carries this code, where a single 0-byte IPv6 datagram to port 4791 reproduced the panic above (that tree does not pull the UDP header in rxe_udp_encap_recv(), so payloads of 0..3 bytes reach the first goto there, versus 0..11 on mainline). With this change, the same packets are dropped as intended and tracing the drop label shows pkt->qp is 0 on every path that reaches it. Not done: the mainline tree was not built in the environment used to prepare this, and the reproducer is left out of this message on purpose - both are available on request.
--- drivers/infiniband/sw/rxe/rxe_recv.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_recv.c +8 -1
@@ -362,6 +362,14 @@ void rxe_rcv(struct sk_buff *skb)struct rxe_pkt_info *pkt =SKB_TO_PKT (skb);struct rxe_dev *rxe = pkt->rxe; +/* +* pkt lives in skb->cb, which the network stack has already used +* for its own state: for IPv6 the qword holding pkt->qp holds +* inet6_skb_parm.nhoff. The drop label puts pkt->qp, so clear +* it before the first early exit. +*/ + pkt->qp =NULL ; +if (unlikely (skb->len <RXE_BTH_BYTES )) goto drop;
@@ -372,7 +380,6 @@ void rxe_rcv(struct sk_buff *skb) pkt->opcode =bth_opcode (pkt); pkt->psn =bth_psn (pkt); - pkt->qp =NULL ; pkt->mask |= rxe_opcode[pkt->opcode].mask;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2042/2214 RDMA/usnic: Bound buffer size to sizeof(buf) in flowinfo_read()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 9dd8b9a337af844291edcd9139c927d0f7958dbe ]
In flowinfo_read(), 'left' tracks the remaining space in the 512-byte stack buffer 'buf', but it is initialized to 'count'.
Initialize 'left' to sizeof(buf) instead of 'count'.
--- drivers/infiniband/hw/usnic/usnic_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/usnic/usnic_debugfs.c +1 -1
@@ -77,7 +77,7 @@ static ssize_t flowinfo_read(struct file *f, char __user *data, qp_flow = f->private_data; ptr = buf; - left = count; + left =sizeof (buf);if (*ppos >0 )return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2043/2214 dt-bindings: Add Sercomm (Suzhou) Corporation vendor prefix
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Zhilkin <[email protected]>
[ Upstream commit d217c4d968bb590e5aa1ff7d02f680c9ba5c1cec ]
Add "sercomm" vendor prefix for "Sercomm (Suzhou) Corporation".
Company website:
Stable-dep-of: f4ba4f8cc8e8 ("dt-bindings: vendor-prefixes: Add Sensylink")
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1064,6 +1064,8 @@ patternProperties: description: Sensirion AG "^sensortek,.*": description: Sensortek Technology Corporation + "^sercomm,.*": + description: Sercomm (Suzhou) Corporation "^sff,.*": description: Small Form Factor Committee "^sgd,.*":
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2044/2214 dt-bindings: vendor-prefixes: Add Sensylink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Troy Mitchell <[email protected]>
[ Upstream commit f4ba4f8cc8e8df45e57c1754955b3a6b9b089a97 ]
Add the vendor prefix for Sensylink Microelectronics.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1064,6 +1064,8 @@ patternProperties: description: Sensirion AG "^sensortek,.*": description: Sensortek Technology Corporation + "^sensylink,.*": + description: Sensylink Microelectronics Technology Co., Ltd. "^sercomm,.*": description: Sercomm (Suzhou) Corporation "^sff,.*":
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2045/2214 ALSA: pcm: Protect the unregister notifier traversal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 680be9f82d4977d3410c513d3bfe912d100f64fc ]
snd_pcm_free() traverses snd_pcm_notify_list and calls n_unregister without register_mutex, although snd_pcm_notify() takes that mutex to add and remove notifiers. PCM disconnect releases the mutex before the free callback runs, so it does not protect this later traversal.
With no open OSS file, normal snd-pcm-oss removal can overlap PCM card teardown, for example when unbinding snd-dummy:
PCM card teardown snd-pcm-oss unload
----------------- ------------------
snd_pcm_dev_disconnect()
remove PCM under register_mutex
unlock register_mutex
snd_pcm_free()
fetch notifier
snd_pcm_notify(..., 1)
unlink notifier under mutex
free module storage
read notifier->n_unregister
invoke callback
The free path can then read the notifier from released module storage or call its unloaded code.
Hold register_mutex across the unregister traversal and its callbacks. Notifier removal must wait until both have finished. This also protects the traversal if a callback releases the last module reference: module exit cannot unlink its notifier until the free path releases the mutex. Drop the mutex before private_free and the remaining stream cleanup.
--- sound/core/pcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/core/pcm.c +4 -2
@@ -864,8 +864,10 @@ static int snd_pcm_free(struct snd_pcm *pcm) {if (!pcm)return 0 ; -if (!pcm->internal) -pcm_call_notify (pcm, n_unregister); +if (!pcm->internal) { + scoped_guard(mutex, ®ister_mutex) +pcm_call_notify (pcm, n_unregister); + }if (pcm->private_free) pcm->private_free (pcm);snd_pcm_lib_preallocate_free_for_all (pcm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2046/2214 ALSA: oss: Keep emulation modules loaded until object teardown
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f0780cfa6acf72576464dc3b40431db389f46ee8 ]
OSS proc entries and notifier callbacks can remain in use without an open OSS device file. Normal snd-pcm-oss removal can therefore delete an existing PCM's OSS proc entry while late HDA codec binding repeats snd_card_register() on the same live card:
OSS PCM module unload Card registration
--------------------- -----------------
snd_info_free_entry(entry)
proc_remove(entry->p)
clear entry->p
snd_info_card_register()
republish linked entry
unlink and free entry
The new proc node retains a pointer to freed storage. Mixer OSS removal can likewise release an adapter while a card notification still uses it.
Hold a snd-pcm-oss module reference for each PCM registered with its notifier and a snd-mixer-oss reference for each card adapter. Release them at final unregister or FREE, after proc and adapter cleanup. Normal module unload can no longer initiate removal while these objects exist.
Track PCM OSS registration with a separate bool registered. Unlike oss.reg, this state also covers unmapped PCMs and remains set across DISCONNECT until final unregister. BUILD-state and creation-error cleanup must not drop a reference when registration never acquired one. The PCM notifier's register_mutex serialization keeps the final put ahead of notifier removal and module teardown until dispatch has finished.
For mixer OSS, serialize callback publication, dispatch and withdrawal in the core so module exit waits for callbacks, including one dropping the last reference, to return. Keep card enumeration in the OSS module, with card references released after dispatch drops the mutex. Ignore duplicate REGISTER notifications so a delayed registration cannot replace an adapter retained across DISCONNECT and leak its module pin.
Partial HDA codec teardown can still remove an individual PCM while the card remains registered; its object-lifetime handling is separate.
--- include/sound/core.h | 3 ++- include/sound/pcm_oss.h | 1 + sound/core/init.c | 29 +++++++++++++++++++++-------- sound/core/oss/mixer_oss.c | 36 ++++++++++++++++++++---------------- sound/core/oss/pcm_oss.c | 12 ++++++++++++ 5 files changed, 56 insertions(+), 25 deletions(-)
include/sound/core.h +2 -1
@@ -292,7 +292,8 @@ int snd_card_locked(int card);#define SND_MIXER_OSS_NOTIFY_REGISTER 0#define SND_MIXER_OSS_NOTIFY_DISCONNECT 1#define SND_MIXER_OSS_NOTIFY_FREE 2 -extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card,int cmd); +void snd_mixer_oss_set_notify (int (*callback)(struct snd_card *card,int cmd)); +void snd_mixer_oss_notify (struct snd_card *card,int cmd);#endif int snd_card_new(struct device *parent, int idx, const char *xid,
include/sound/pcm_oss.h +1 -0
@@ -70,6 +70,7 @@ struct snd_pcm_oss_stream {struct snd_pcm_oss {int reg;unsigned int reg_mask; +bool registered; };#endif /* __SOUND_PCM_OSS_H */
sound/core/init.c +21 -8
@@ -82,8 +82,24 @@ static int module_slot_match(struct module *module, int idx) }#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -int (*snd_mixer_oss_notify_callback)(struct snd_card *card,int free_flag); -EXPORT_SYMBOL (snd_mixer_oss_notify_callback); +static DEFINE_MUTEX (mixer_oss_notify_mutex); +static int (*mixer_oss_notify_callback)(struct snd_card *card,int cmd); + +void snd_mixer_oss_notify (struct snd_card *card,int cmd) +{ +guard (mutex)(&mixer_oss_notify_mutex); +if (mixer_oss_notify_callback) +mixer_oss_notify_callback (card, cmd); +} +EXPORT_SYMBOL (snd_mixer_oss_notify); + +void snd_mixer_oss_set_notify (int (*callback)(struct snd_card *,int )) +{ +/* Wait for callbacks, including a final module_put(), to return. */ +guard (mutex)(&mixer_oss_notify_mutex); + mixer_oss_notify_callback = callback; +} +EXPORT_SYMBOL (snd_mixer_oss_set_notify);#endif static int check_empty_slot (struct module *module,int slot)
@@ -520,8 +536,7 @@ void snd_card_disconnect(struct snd_card *card)/* at this point, they cannot respond to any calls except release() */ #if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_DISCONNECT ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_DISCONNECT );#endif /* notify all devices that we are disconnected */
@@ -575,8 +590,7 @@ static int snd_card_do_free(struct snd_card *card) card->releasing = true;#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_FREE ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_FREE );#endif snd_device_free_all (card);if (card->private_free)
@@ -922,8 +936,7 @@ int snd_card_register(struct snd_card *card)return err;#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_REGISTER ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_REGISTER );#endif return 0 ; }
sound/core/oss/mixer_oss.c +20 -16
@@ -1371,13 +1371,22 @@ static int snd_mixer_oss_free1(void *private)static int snd_mixer_oss_notify_handler (struct snd_card *card,int cmd) {struct snd_mixer_oss *mixer; +int err;if (cmd ==SND_MIXER_OSS_NOTIFY_REGISTER ) { -int idx, err; +int idx; + +/* Module loading and card registration can both notify us. */ +if (card->mixer_oss) +return 0 ; mixer =kcalloc (2 ,sizeof (*mixer),GFP_KERNEL );if (mixer ==NULL )return -ENOMEM ; +if (!try_module_get (THIS_MODULE )) { +kfree (mixer); +return -ENODEV ; + }mutex_init (&mixer->reg_mutex); err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, card, 0,
@@ -1387,6 +1396,7 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)"unable to register OSS mixer device %i:%i\n" , card->number, 0);kfree (mixer); +module_put (THIS_MODULE );return err; } mixer->oss_dev_alloc =1 ;
@@ -1420,7 +1430,10 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)if (cmd ==SND_MIXER_OSS_NOTIFY_DISCONNECT )return 0 ;snd_mixer_oss_proc_done (mixer); -return snd_mixer_oss_free1 (mixer); + err =snd_mixer_oss_free1 (mixer); +if (!err) +module_put (THIS_MODULE ); +return err; }return 0 ; }
@@ -1429,12 +1442,12 @@ static int __init alsa_mixer_oss_init(void) {struct snd_card *card;int idx; - - snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler; + +snd_mixer_oss_set_notify (snd_mixer_oss_notify_handler);for (idx =0 ; idx <SNDRV_CARDS ; idx++) { card =snd_card_ref (idx);if (card) { -snd_mixer_oss_notify_handler (card,SND_MIXER_OSS_NOTIFY_REGISTER ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_REGISTER );snd_card_unref (card); } }
@@ -1443,17 +1456,8 @@ static int __init alsa_mixer_oss_init(void) static void __exit alsa_mixer_oss_exit(void) { -struct snd_card *card; -int idx; - - snd_mixer_oss_notify_callback =NULL ; -for (idx =0 ; idx <SNDRV_CARDS ; idx++) { - card =snd_card_ref (idx); -if (card) { -snd_mixer_oss_notify_handler (card,SND_MIXER_OSS_NOTIFY_FREE ); -snd_card_unref (card); - } - } +/* Live adapters hold module references and prevent normal unload. */ +snd_mixer_oss_set_notify (NULL ); }module_init (alsa_mixer_oss_init)
sound/core/oss/pcm_oss.c +12 -0
@@ -3144,6 +3144,12 @@ static void register_oss_dsp(struct snd_pcm *pcm, int index)static int snd_pcm_oss_register_minor (struct snd_pcm *pcm) { +if (pcm->oss.registered) +return 0 ; +if (!try_module_get (THIS_MODULE )) +return -ENODEV ; + pcm->oss.registered = true; + pcm->oss.reg =0 ;if (dsp_map[pcm->card->number] == (int )pcm->device) {char name[128 ];
@@ -3198,8 +3204,14 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)static int snd_pcm_oss_unregister_minor (struct snd_pcm *pcm) { +/* BUILD-state and creation-error cleanup need not have registered us. */ +if (!pcm->oss.registered) +return 0 ; +snd_pcm_oss_disconnect_minor (pcm);snd_pcm_oss_proc_done (pcm); + pcm->oss.registered = false; +module_put (THIS_MODULE );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2047/2214 octeontx2-af: Fix CQ enable state tracking after AQ writes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alok Tiwari <[email protected]>
[ Upstream commit 07bd391eb9572e74f073c49acef327611234f9bb ]
Use the CQ context's ena field when updating the CQ enable bitmap. The current code reads rq.ena, which overlaps bit 0 of the CQ base address and can leave the bitmap out of sync with the hardware context. This can cause enabled CQs to be skipped during teardown.
Use sq.ena for the SQ bitmap update as well, so each queue type reads its own context.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +2 -2
@@ -1038,7 +1038,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,__clear_bit (req->qidx, pfvf->rq_bmap); }if (req->ctype ==NIX_AQ_CTYPE_SQ ) { - ena = (req->rq.ena & req->sq_mask.ena) | + ena = (req->sq.ena & req->sq_mask.ena) | (test_bit (req->qidx, pfvf->sq_bmap) & ~req->sq_mask.ena);if (ena)
@@ -1047,7 +1047,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,__clear_bit (req->qidx, pfvf->sq_bmap); }if (req->ctype ==NIX_AQ_CTYPE_CQ ) { - ena = (req->rq.ena & req->cq_mask.ena) | + ena = (req->cq.ena & req->cq_mask.ena) | (test_bit (req->qidx, pfvf->cq_bmap) & ~req->cq_mask.ena);if (ena)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2048/2214 netfilter: nf_conntrack: avoid truncating IPv6 nexthdr offset
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 48d522b65fb0ce2bd54f8f5838d77b48afcf1f3e ]
find_prev_fhdr() returns the offset of the Next Header field before an IPv6 Fragment header through an int pointer, but stores the offset in a u8 local. An extension header chain can put this field beyond byte 255, causing the offset to wrap before it is saved in the fragment queue.
Reassembly later uses the wrapped value to update the preceding Next Header field. This overwrites another byte in the IPv6 header chain and can make conntrack parse a different transport tuple from the one used by IPv6 local delivery. A two-fragment packet can, for example, be recorded as UDP destination port 53 while its payload is delivered to UDP port 9999.
Use int for the working offset, matching the output argument and the other offset variables in this path.
--- net/ipv6/netfilter/nf_conntrack_reasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +1 -1
@@ -395,7 +395,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff) {u8 nexthdr =ipv6_hdr (skb)->nexthdr;const int netoff =skb_network_offset (skb); -u8 prev_nhoff = netoff + offsetof(struct ipv6hdr , nexthdr); +int prev_nhoff = netoff + offsetof(struct ipv6hdr , nexthdr);int start = netoff +sizeof (struct ipv6hdr );int len = skb->len - start;u8 prevhdr =NEXTHDR_IPV6 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2049/2214 ipvs: fix more races around the overload flag
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
[ Upstream commit 3ba20137287f4f34ddbf0afb53c5d1ba03b6a8c2 ]
Sashiko warns that we still have races when the dest overload thresholds are updated. If we narrow the range between thresholds the lockless readers (ip_vs_bind_dest and ip_vs_unbind_dest) may use old threshold values and as result to skip the required flag change.
To solve the problem ip_vs_bind_dest() and ip_vs_unbind_dest() will have the chance as before to change the overload state not only at the exact threshold positions but
at any conn count below the lower and above the upper thresholds. To make it work without entering the locked region for every connection, we introduce l_threshold_val. Together with u_threshold_val we will switch between two states:
1. not overloaded: where l_threshold_val is set to 0 to close the door for more ip_vs_unbind_dest() calls to clear the overload state.
2. overloaded: where u_threshold_val is set to INT_MAX to close the door for more ip_vs_bind_dest() calls to set the overload state.
If a race occurs, multiple CPUs can repeat the state change but this should be for short time window.
With the introduction of l_threshold_val the IP_VS_DEST_F_OVERLOAD flag and the 'flags' field are not needed anymore. We will use the ip_vs_dest_is_overloaded() helper for all places that read the overload state.
Do not check IP_VS_DEST_CF_AVAILABLE in ip_vs_dh.c because we do not hold reference to dest after it is removed and rely on RCU to access the available dests.
To reduce the cacheline accesses while selecting destination, keep the mostly used fields (weight and l_threshold_val) at the first read-mostly cacheline together with the hash nodes.
--- include/net/ip_vs.h | 50 ++++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_conn.c | 8 ++--- net/netfilter/ipvs/ip_vs_ctl.c | 38 ++++++++++++------------ net/netfilter/ipvs/ip_vs_dh.c | 16 ++-------- net/netfilter/ipvs/ip_vs_fo.c | 2 +- net/netfilter/ipvs/ip_vs_lblc.c | 4 +-- net/netfilter/ipvs/ip_vs_lblcr.c | 8 ++--- net/netfilter/ipvs/ip_vs_lc.c | 2 +- net/netfilter/ipvs/ip_vs_mh.c | 2 +- net/netfilter/ipvs/ip_vs_nq.c | 2 +- net/netfilter/ipvs/ip_vs_ovf.c | 2 +- net/netfilter/ipvs/ip_vs_rr.c | 2 +- net/netfilter/ipvs/ip_vs_sed.c | 4 +-- net/netfilter/ipvs/ip_vs_sh.c | 2 +- net/netfilter/ipvs/ip_vs_twos.c | 4 +-- net/netfilter/ipvs/ip_vs_wlc.c | 4 +-- net/netfilter/ipvs/ip_vs_wrr.c | 2 +- 17 files changed, 76 insertions(+), 76 deletions(-)
include/net/ip_vs.h +32 -18
@@ -33,9 +33,6 @@#define IP_VS_HDR_INVERSE 1#define IP_VS_HDR_ICMP 2 -/* Destination Server Flags */ -#define IP_VS_DEST_F_OVERLOAD 0x0002/* server is overloaded */ -/* Destination Server Config Flags */ #define IP_VS_DEST_CF_AVAILABLE 0x0001/* server is available */
@@ -661,32 +658,43 @@ struct ip_vs_dest_dst {* and so on. */ struct ip_vs_dest { +/* Cacheline for hash table nodes - read-mostly */ +struct list_head n_list;/* for the dests in the service */ struct hlist_node d_list;/* for table with all the dests */ -u16 af;/* address family */ -__be16 port;/* port number of the server */ -union nf_inet_addr addr;/* IP address of the server */ -volatile unsigned int flags;/* dest status flags */ -atomic_t conn_flags;/* flags to copy to conn */ atomic_t weight;/* server weight */ -unsigned long cflags;/* config flags */ atomic_t last_weight;/* server latest weight */ + +/* connection thresholds */ +u32 l_threshold_val;/* used lower threshold */ +u32 u_threshold_val;/* used upper threshold */ +/* 32/48 */ +u32 l_threshold;/* lower threshold */ +u32 u_threshold;/* upper threshold */ + +unsigned long cflags;/* config flags */ + +/* 44/64 */ +atomic_t conn_flags;/* flags to copy to conn */ +__u16 tun_type;/* tunnel type */ __be16 tun_port;/* tunnel port */ __u16 tun_flags;/* tunnel flags */ -refcount_t refcnt;/* reference counter */ -struct ip_vs_stats stats;/* statistics */ -unsigned long idle_start;/* start time, jiffies */ +u16 af;/* address family */ +__be16 port;/* port number of the server */ +/* 60/80 */ +union nf_inet_addr addr;/* IP address of the server */ -/* connection counters and thresholds */ -atomic_t activeconns;/* active connections */ +/* connection counters */ atomic_t totalconns;/* total connections */ +atomic_t activeconns;/* active connections */ atomic_t persistconns;/* persistent connections */ -__u32 u_threshold;/* upper threshold */ -__u32 l_threshold;/* lower threshold */ -__u32 l_threshold_val;/* used lower threshold */ + +refcount_t refcnt;/* reference counter */ +struct ip_vs_stats stats;/* statistics */ +unsigned long idle_start;/* start time, jiffies */ /* for destination cache */ spinlock_t dst_lock;/* lock of dst_cache */
@@ -1465,7 +1473,13 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)kfree (dest); } -void ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode); +void ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload); + +/* Check if dest is in overloaded state */ +static inline bool ip_vs_dest_is_overloaded (const struct ip_vs_dest *dest) +{ +return READ_ONCE (dest->l_threshold_val); +}/* IPVS sync daemon data and function prototypes * (from ip_vs_sync.c)
net/netfilter/ipvs/ip_vs_conn.c +4 -4
@@ -633,8 +633,8 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)if (!(flags &IP_VS_CONN_F_INACTIVE ))atomic_inc (&dest->activeconns); tc =atomic_inc_return (&dest->totalconns); -if (tc ==READ_ONCE (dest->u_threshold)) -ip_vs_dest_update_overload (dest,1 ); +if (tc >=READ_ONCE (dest->u_threshold_val)) +ip_vs_dest_update_overload (dest, true); }else {/* It is a persistent connection/template, so increase the persistent connection counter */
@@ -726,8 +726,8 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)if (!(cp->flags &IP_VS_CONN_F_INACTIVE ))atomic_dec (&dest->activeconns); tc =atomic_fetch_dec (&dest->totalconns); -if (tc ==READ_ONCE (dest->l_threshold_val)) -ip_vs_dest_update_overload (dest,-1 ); +if (tc <=READ_ONCE (dest->l_threshold_val)) +ip_vs_dest_update_overload (dest, false); }else {/* It is a persistent connection/template, so decrease the persistent connection counter */
net/netfilter/ipvs/ip_vs_ctl.c +18 -20
@@ -868,32 +868,32 @@ ip_vs_zero_stats(struct ip_vs_stats *stats)* - conns reach u_threshold and exceed it: set the flag * - conns go below l_threshold (or 75% of u_threshold): clear the flag */ -static void __ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode) +static void __ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload) {int conns;u32 l, u;lockdep_assert_held (&dest->dst_lock); u =READ_ONCE (dest->u_threshold); -if (!u) - goto unset; - l =READ_ONCE (dest->l_threshold_val); - conns =atomic_read (&dest->totalconns); -if (conns >= (mode >0 ? l : u)) { - dest->flags |=IP_VS_DEST_F_OVERLOAD ; -return ; +if (u) { +/* Low threshold defaults to 75% of upper threshold */ + l =READ_ONCE (dest->l_threshold) ? : (u - (u >>2 )); + conns =atomic_read (&dest->totalconns); +if (conns >= (overload ? l : u)) { +WRITE_ONCE (dest->u_threshold_val,INT_MAX ); +WRITE_ONCE (dest->l_threshold_val, l); +return ; + } } -if (conns >= (mode <0 ? u : l)) -return ; -unset: - dest->flags &= ~IP_VS_DEST_F_OVERLOAD ; +WRITE_ONCE (dest->u_threshold_val, u ? :INT_MAX ); +WRITE_ONCE (dest->l_threshold_val,0 ); } -void ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode) +void ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload) {spin_lock_bh (&dest->dst_lock); -__ip_vs_dest_update_overload (dest, mode); +__ip_vs_dest_update_overload (dest, overload);spin_unlock_bh (&dest->dst_lock); }
@@ -965,15 +965,13 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,if (READ_ONCE (dest->u_threshold) != udest->u_threshold ||READ_ONCE (dest->l_threshold) != udest->l_threshold) { +bool overload; +spin_lock_bh (&dest->dst_lock);WRITE_ONCE (dest->u_threshold, udest->u_threshold);WRITE_ONCE (dest->l_threshold, udest->l_threshold); -/* Low threshold defaults to 75% of upper threshold */ -WRITE_ONCE (dest->l_threshold_val, - udest->l_threshold ? : - (udest->u_threshold - - (udest->u_threshold >>2 ))); -__ip_vs_dest_update_overload (dest,0 ); + overload =ip_vs_dest_is_overloaded (dest); +__ip_vs_dest_update_overload (dest, overload);spin_unlock_bh (&dest->dst_lock); }
net/netfilter/ipvs/ip_vs_dh.c +2 -14
@@ -196,16 +196,6 @@ static int ip_vs_dh_dest_changed(struct ip_vs_service *svc, } -/* -* If the dest flags is set with IP_VS_DEST_F_OVERLOAD, -* consider that the server is overloaded here. -*/ -static inline int is_overloaded (struct ip_vs_dest *dest) -{ -return dest->flags &IP_VS_DEST_F_OVERLOAD ; -} - -/* * Destination hashing scheduling */
@@ -220,10 +210,8 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, s = (struct ip_vs_dh_state *) svc->sched_data; dest =ip_vs_dh_get (svc->af, s, &iph->daddr); -if (!dest || - !(dest->cflags &IP_VS_DEST_CF_AVAILABLE ) - ||atomic_read (&dest->weight) <=0 - ||is_overloaded (dest)) { +if (!dest ||atomic_read (&dest->weight) <=0 || +ip_vs_dest_is_overloaded (dest)) {ip_vs_scheduler_err (svc,"no destination available" );return NULL ; }
net/netfilter/ipvs/ip_vs_fo.c +1 -1
@@ -30,7 +30,7 @@ ip_vs_fo_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,* Find virtual server with highest weight and send it traffic */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) > hw) { hweight = dest; hw =atomic_read (&dest->weight);
net/netfilter/ipvs/ip_vs_lblc.c +2 -2
@@ -419,7 +419,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)* new connection. */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ;if (atomic_read (&dest->weight) >0 ) { least = dest;
@@ -434,7 +434,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_lblcr.c +4 -4
@@ -167,7 +167,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)/* select the first destination server, whose weight > 0 */ list_for_each_entry_rcu (e, &set->list, list) { least = e->dest; -if (least->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (least))continue ; if ((atomic_read(&least->weight) > 0) &&
@@ -182,7 +182,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) nextstage:list_for_each_entry_continue_rcu (e, &set->list, list) { dest = e->dest; -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
@@ -581,7 +581,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)* new connection. */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ;if (atomic_read (&dest->weight) >0 ) {
@@ -597,7 +597,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_lc.c +1 -1
@@ -39,7 +39,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) || +if (ip_vs_dest_is_overloaded (dest) ||atomic_read (&dest->weight) ==0 )continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_mh.c +1 -1
@@ -81,7 +81,7 @@ static inline void generate_hash_secret(hsiphash_key_t *hash1,static inline bool is_unavailable (struct ip_vs_dest *dest) {return atomic_read (&dest->weight) <=0 || - dest->flags &IP_VS_DEST_F_OVERLOAD ; +ip_vs_dest_is_overloaded (dest); }/* Returns hash value for IPVS MH entry */
net/netfilter/ipvs/ip_vs_nq.c +1 -1
@@ -73,7 +73,7 @@ ip_vs_nq_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD || +if (ip_vs_dest_is_overloaded (dest) || !atomic_read (&dest->weight))continue ;
net/netfilter/ipvs/ip_vs_ovf.c +1 -1
@@ -34,7 +34,7 @@ ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { w =atomic_read (&dest->weight); -if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) || +if (ip_vs_dest_is_overloaded (dest) ||atomic_read (&dest->activeconns) > w || w ==0 )continue ;
net/netfilter/ipvs/ip_vs_rr.c +1 -1
@@ -67,7 +67,7 @@ ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out;
net/netfilter/ipvs/ip_vs_sed.c +2 -2
@@ -76,7 +76,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 ) { least = dest; loh =ip_vs_sed_dest_overhead (least);
@@ -91,7 +91,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_sed_dest_overhead (dest); if ((__s64)loh * atomic_read(&dest->weight) >
net/netfilter/ipvs/ip_vs_sh.c +1 -1
@@ -74,7 +74,7 @@ struct ip_vs_sh_state {static inline bool is_unavailable (struct ip_vs_dest *dest) {return atomic_read (&dest->weight) <=0 || - dest->flags &IP_VS_DEST_F_OVERLOAD ; +ip_vs_dest_is_overloaded (dest); }/*
net/netfilter/ipvs/ip_vs_twos.c +2 -2
@@ -53,7 +53,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc,/* Generate a random weight between [0,sum of all weights) */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD )) { +if (!ip_vs_dest_is_overloaded (dest)) { weight =atomic_read (&dest->weight);if (weight >0 ) { total_weight += weight;
@@ -76,7 +76,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc,/* Pick two weighted servers */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; weight =atomic_read (&dest->weight);
net/netfilter/ipvs/ip_vs_wlc.c +2 -2
@@ -48,7 +48,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 ) { least = dest; loh =ip_vs_dest_conn_overhead (least);
@@ -63,7 +63,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest); if ((__s64)loh * atomic_read(&dest->weight) >
net/netfilter/ipvs/ip_vs_wrr.c +1 -1
@@ -177,7 +177,7 @@ ip_vs_wrr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >= mark->cw) goto found;if (dest == stop)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2050/2214 netfilter: flowtable: use the vlan id, not the full tci, in the tuple key
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangfeng He <[email protected]>
[ Upstream commit c203ecf905745d979de5df28fa657121f2e9342d ]
nf_flow_tuple_encap() stores the skb vlan tag in the encap tuple id using skb_vlan_tag_get(), which returns the unmasked TCI including the 3 PCP priority bits. The flowtable entry, however, is programmed by nf_dev_path_info() with vlan_dev_vlan_id(), a plain 12-bit VID.
When a NIC delivers RX vlan offload skbs with a non-zero priority (an RTL9617C EPON ONU was observed handing over vid 818 skbs with tci 0x6332, PCP 3), the runtime lookup key never matches the programmed entry, so every packet misses the flow table and software flow offload is silently defeated.
Mask both parse sites to the 12-bit VID so the lookup key matches for any priority. The in-header variant has the same problem for frames received with PCP != 0 on a non-offload path.
The egress side is unaffected: nf_flow_encap_push() restores tags from the programmed tuple id, which never carried priority bits.
Measured on an RTL9617C ONU (PPPoE over VLAN 818 WAN, NATed 6-flow download over a 1G EPON line), before -> after:
download throughput 377 Mbps -> 936 Mbps
CPU0 %soft at that rate 91.5% -> 70.9%
--- net/netfilter/nf_flow_table_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -145,14 +145,14 @@ static void nf_flow_tuple_encap(struct sk_buff *skb,int i =0 ;if (skb_vlan_tag_present (skb)) { - tuple->encap[i].id =skb_vlan_tag_get (skb); + tuple->encap[i].id =skb_vlan_tag_get_id (skb); tuple->encap[i].proto = skb->vlan_proto; i++; }switch (skb->protocol) {case htons (ETH_P_8021Q ): veth = (struct vlan_ethhdr *)skb_mac_header (skb); - tuple->encap[i].id =ntohs (veth->h_vlan_TCI); + tuple->encap[i].id =ntohs (veth->h_vlan_TCI) &VLAN_VID_MASK ; tuple->encap[i].proto = skb->protocol;break ;case htons (ETH_P_PPP_SES ):
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2051/2214 netfilter: xt_dccp: handle reserved options as single-byte
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sung Byeongchan <[email protected]>
[ Upstream commit 2edda78aa4eb04cd8f112a81897510ee0cdd7099 ]
The DCCP UAPI defines option numbers 3 through 31 as reserved. Like Padding and Mandatory, these options occupy one byte. dccp_find_option() only treats values below 2 as single-byte and interprets the byte after a reserved option as a TLV length.
This can skip a later option and invert an XT_DCCP_OPTION rule result. A local production-hook fixture installed the same DROP rule for IPv4 and IPv6. In three fresh boots per kernel, a target-only packet was dropped 20/20 times, while adding reserved option 3 before the same target let 20/20 packets reach the protected receiver. The fixed kernel dropped all trigger packets in three fresh boots and preserved the normal controls.
Treat every option up to DCCPO_MAX_RESERVED as single-byte, matching the protocol definition. Triggering requires CONFIG_NETFILTER_XTABLES_LEGACY, CONFIG_NETFILTER_XT_MATCH_DCCP, an option-based rule, and remote protocol-33 reachability. The touched source is unchanged at 0c2669a9f4a1d607e7591ae50ccf3c432a0aff08, where the patch applies and builds cleanly.
--- net/netfilter/xt_dccp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_dccp.c +1 -1
@@ -62,7 +62,7 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 || i == optlen -1 ) +if (op[i] <=DCCPO_MAX_RESERVED || i == optlen -1 ) i++;else i += op[i +1 ] ? :1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2052/2214 nios2: ksyms: Declare __mulsi3 export
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 2180d11e06fb56fd13643ae59964f144896870be ]
GCC may emit libcalls to __mulsi3(). As modpost is not aware that this function is provided through the linked in libgcc, it fails:
ERROR: modpost: kernel/locking/test-ww_mutex.ko: symbol '__mulsi3' undefined!
ERROR: modpost: kernel/time/test_udelay.ko: symbol '__mulsi3' undefined!
ERROR: modpost: kernel/resource_kunit.ko: symbol '__mulsi3' undefined!
ERROR: modpost: fs/fuse/virtiofs.ko: symbol '__mulsi3' undefined! etc.
Make sure modpost can see the symbol from libgcc.
--- arch/nios2/kernel/nios2_ksyms.c | 1 + 1 file changed, 1 insertion(+)
arch/nios2/kernel/nios2_ksyms.c +1 -0
@@ -39,6 +39,7 @@ DECLARE_EXPORT(__udivsi3);DECLARE_EXPORT (__umoddi3);DECLARE_EXPORT (__umodsi3);DECLARE_EXPORT (__muldi3); +DECLARE_EXPORT (__mulsi3);DECLARE_EXPORT (__ucmpdi2);DECLARE_EXPORT (__lshrdi3);DECLARE_EXPORT (__ashldi3);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2053/2214 ALSA: pcm: Remove channel-map controls before freeing substreams
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit d5dd05c1f72a95d8ab06828d7272a185ad2b9185 ]
A late HDA codec bind on an already registered card builds new PCMs before registering them. add_std_chmaps() publishes generic channel-map controls during this BUILD stage. If an earlier chmap succeeds and a later allocation fails, probe cleanup frees the BUILD PCM while the card's control device remains accessible.
These generic controls are added directly by snd_pcm_add_chmap_ctls(); snd_hda_ctls_clear() only removes codec-tracked mixer controls. BUILD devices also skip dev_disconnect. snd_pcm_free_stream() then frees the substreams before free_chmap() withdraws their generic control:
Late HDA codec bind / rollback Control GET on the live card
------------------------------ ----------------------------
hda_codec_driver_probe()
snd_hda_codec_build_pcms()
PCM is BUILD
snd_hda_codec_build_controls()
add_std_chmaps()
publish an earlier chmap
later allocation: -ENOMEM
snd_hda_codec_cleanup_for_unbind()
snd_hda_ctls_clear()
generic chmap remains
codec_release_pcms()
snd_device_free()
BUILD: skip dev_disconnect snd_pcm_free_stream()
kfree(substream)
snd_ctl_elem_read()
down_read(controls_rwsem) pcm_chmap_ctl_get()
walk freed substream
free_chmap()
snd_ctl_remove()
wait for GET
up_read(controls_rwsem)
The control read lock cannot protect a substream already freed before control removal starts. The failure above occurs before snd_card_register(), so the PCM has not transitioned out of BUILD.
Move free_chmap() before the substream free loop. Its snd_ctl_remove() withdraws the control and drains readers under controls_rwsem before any substream is released. Normal registered-device disconnect already removes the control, so the later call remains harmless on that path.
--- sound/core/pcm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/core/pcm.c +3 -1
@@ -830,6 +830,9 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr)/* free all proc files under the stream */ snd_pcm_stream_proc_done (pstr); +/* Drain channel-map callbacks before freeing the substreams. */ +free_chmap (pstr); + substream = pstr->substream;while (substream) { substream_next = substream->next;
@@ -844,7 +847,6 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr) kfree(setup); }#endif -free_chmap (pstr);if (pstr->substream_count)put_device (&pstr->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2054/2214 ALSA: aloop: Keep the timer source alive until card release
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 762ef425cf0ac9c4b9e9e61e0da0950e16e6fbea ]
The timer_source string must remain valid while PCM opens can select and parse it. loopback_set_timer_source() allocates the string with parent-device devres, which can release it while the card is still registered.
A successful nonempty proc replacement after snd_card_register() adds the string allocation after trigger_card_free. Unbinding the platform device while snd_aloop remains loaded releases devres in reverse order. An open for an unused cable can run after the string is freed and before the card-free action disconnects the card:
Device unbind PCM open
devres_release_all()
free replacement string
snd_pcm_open()
snd_card_file_add()
loopback_open()
loopback_snd_timer_open()
loopback_parse_timer_id()
trigger_card_free()
snd_card_free()
snd_card_disconnect()The parser can then read freed memory. KASAN has reported a one-byte use-after-free read in strchr() from loopback_snd_timer_open(). The cable_lock mutex serializes explicit replacements with opens, but implicit devres release does not take it. The card and module references held by PCM open do not retain this separate devres allocation.
Use kstrdup() and release the current string from card->private_free. PCM admission already retains the card until each file is removed, and card disconnect drains proc callbacks before final card release. This keeps the string alive across admitted PCM opens and preserves the cable_lock serialization of replacements. Install the callback before the initial allocation so probe failures also release the string.
--- sound/drivers/aloop.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
sound/drivers/aloop.c +11 -6
@@ -1723,13 +1723,10 @@ static int loopback_cable_proc_new(struct loopback *loopback, int cidx)static void loopback_set_timer_source (struct loopback *loopback,const char *value) { -if (loopback->timer_source) { -devm_kfree (loopback->card->dev, loopback->timer_source); - loopback->timer_source =NULL ; - } +kfree (loopback->timer_source); + loopback->timer_source =NULL ;if (value && *value) - loopback->timer_source =devm_kstrdup (loopback->card->dev, - value,GFP_KERNEL ); + loopback->timer_source =kstrdup (value,GFP_KERNEL ); } static void print_timer_source_info(struct snd_info_entry *entry,
@@ -1762,6 +1759,13 @@ static int loopback_timer_source_proc_new(struct loopback *loopback) change_timer_source_info); } +static void loopback_private_free (struct snd_card *card) +{ +struct loopback *loopback = card->private_data; + +kfree (loopback->timer_source); +} +static int loopback_probe (struct platform_device *devptr) {struct snd_card *card;
@@ -1787,6 +1791,7 @@ static int loopback_probe(struct platform_device *devptr) pcm_substreams[dev] =MAX_PCM_SUBSTREAMS ; loopback->card = card; + card->private_free = loopback_private_free;loopback_set_timer_source (loopback, timer_source[dev]);mutex_init (&loopback->cable_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2055/2214 cgroup/cpuset: use mems_allowed_seq when checking a policy nodemask
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price (Meta) <[email protected]>
[ Upstream commit b0cec62d2867ab3ed27604d5c177b8960c43b17a ]
A cpuset update changes the task's mems_allowed and rebinds its mempolicy in separate steps under mems_allowed_seq, but the check reads both without it. This can cause a spurious numa placement miss under some cpuset/mempolicy combinations.
A reader that loads one mask before the update and the other after it can see a spurious empty intersection and drop the nodemask.
For example, a task with cpuset.mems={0} and MPOL_BIND={0}. If the cpuset moves to mems={1,2}, the policy is rebound to {1}.
The allocator can race and compare the old mems_allowed {0} against the new policy {1} - which will result in a dropped nodemask and a misplaced allocation on node 2.
Simply retry the intersection until mems_allowed_seq is stable.
This covers the task policy, which is rebound under mems_allowed_seq. VMA policies are rebound afterwards by mpol_rebind_mm(), outside mems_allowed_seq, and are not covered by this change.
--- kernel/cgroup/cpuset.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +12 -1
@@ -3571,10 +3571,21 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)* @nodemask: the nodemask to be checked * * Are any of the nodes in the nodemask allowed in current->mems_allowed? +* +* A cpuset update rebinds the task's mempolicy and changes mems_allowed in +* separate steps, so retry if an update raced with the check. */ int cpuset_nodemask_valid_mems_allowed (nodemask_t *nodemask) { -return nodes_intersects (*nodemask, current->mems_allowed); +unsigned int seq; +int ret; + +do { + seq =read_mems_allowed_begin (); + ret =nodes_intersects (*nodemask, current->mems_allowed); + }while (read_mems_allowed_retry (seq)); + +return ret; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2056/2214 net/sched: act_api: reject duplicate actions in a batch
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit f67b3ed1308d7a282e2d6202d61af052ab0da39e ]
tca_action_gd() builds actions[] with one tcf_action_get_1() per nested TCA_ACT_TAB entry. Each successful lookup takes its own reference to the resolved action, so repeated TCA_ACT_INDEX entries in one request yield the same pointer in multiple slots.
For RTM_DELACTION, tcf_action_delete() then consumes two references per
slot: one in tcf_action_put() and one in tcf_idr_delete_index(). A duplicate therefore drives the refcount to zero mid-walk -- the delete frees the action and removes its IDR slot -- and the next slot calls tcf_action_put() on the freed action:
refcount_t: underflow; use-after-free.
WARNING: lib/refcount.c:87 at refcount_dec_not_one refcount_dec_and_mutex_lock __tcf_action_put tca_action_gd
Three duplicate entries are enough. Reject a repeated action while a delete batch is built, dropping the reference the extra lookup took, and return -EINVAL. RTM_GETACTION balances its own references and keeps accepting duplicate entries.
Conditions to recreate the bug:
tc actions add action gact index 100
tc actions delete action gact index 100 action gact index 100 \
action gact index 100
--- net/sched/act_api.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/sched/act_api.c +20 -1
@@ -1461,7 +1461,7 @@ static int tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, u32 portid, int event, struct netlink_ext_ack *extack) { - int i, ret; + int i, j, ret;struct nlattr *tb[TCA_ACT_MAX_PRIO +1 ];struct tc_action *act;size_t attr_size =0 ;
@@ -1486,6 +1486,25 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, ret =PTR_ERR (act); goto err; } + +/* A delete consumes two references per slot (tcf_action_put() +* and tcf_idr_delete_index()) but each entry takes one, so a +* repeated action would hit zero mid-walk. GET balances its +* own references and keeps accepting duplicates. +*/ +if (event ==RTM_DELACTION ) { +for (j =0 ; j < i -1 ; j++) { +if (actions[j] != act) +continue ; + +tcf_action_put (act); +NL_SET_ERR_MSG (extack, +"Duplicate TC action in a delete batch" ); + ret = -EINVAL ; + goto err; + } + } + attr_size +=tcf_action_fill_size (act); actions[i -1 ] = act; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2057/2214 RDMA/mlx5: Fix CQ resize destination index mask
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit 0fe31052d948a3a993bb2f58cd5886f7ec279ea7 ]
In copy_resize_cqes, the destination CQE index is computed as (i + 1) & cq->resize_buf->nent, but resize_buf->nent is produced by roundup_pow_of_two(), so it is a power of two with exactly one bit set. Masking with a single-bit value can only yield 0 or nent itself. The buffer has nent entries, so valid indices are 0 .. nent - 1 and nent is one past the last slot; whenever the masked result is nent the following memcpy writes one entry out of bounds.
Use (nent - 1) as the wrap mask instead. For a power-of-two nent, (i + 1) & (nent - 1) is the correct modulo-nent reduction, keeping the index within [0, nent - 1]. This matches get_sw_cqe(), which addresses the CQ buffer via n & cq->ibcq.cqe, where cq->ibcq.cqe == entries - 1 is exactly the nent - 1 wrap mask.
--- drivers/infiniband/hw/mlx5/cq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/cq.c +1 -1
@@ -1240,7 +1240,7 @@ static int copy_resize_cqes(struct mlx5_ib_cq *cq)while (get_cqe_opcode (scqe64) !=MLX5_CQE_RESIZE_CQ ) { dcqe =mlx5_frag_buf_get_wqe (&cq->resize_buf->fbc, - (i +1 ) & cq->resize_buf->nent); + (i +1 ) & (cq->resize_buf->nent -1 )); dcqe64 = dsize ==64 ? dcqe : dcqe +64 ; sw_own =sw_ownership_bit (i +1 , cq->resize_buf->nent);memcpy (dcqe, scqe, dsize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2058/2214 mptcp: options: mpc: avoid printing uninit data
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
[ Upstream commit a234ee8eb9a20d1a272f0d2ceabdb35165071778 ]
When parsing the MP_CAPABLE suboption, this pr_debug() might read and print uninitialised values.
That's mostly harmless, but that's also confusing. Fixing that also avoids some tools to complain about accessing uninit data.
So read these fields only if they have been set.
Note: this was initially reported by Clashiko as an existing issue. The code has been analysed by a human and confirmed. This is a non-urgent fix.
--- net/mptcp/options.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/options.c +5 -2
@@ -121,8 +121,11 @@ static void mptcp_parse_option(const struct sk_buff *skb, ptr +=2 ; }pr_debug ("MP_CAPABLE version=%x, flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d csum=%u\n" , - version, flags, opsize, mp_opt->sndr_key, - mp_opt->rcvr_key, mp_opt->data_len, mp_opt->csum); + version, flags, opsize, + opsize >=TCPOLEN_MPTCP_MPC_SYNACK ? mp_opt->sndr_key :0 , + opsize >=TCPOLEN_MPTCP_MPC_ACK ? mp_opt->rcvr_key :0 , + opsize >=TCPOLEN_MPTCP_MPC_ACK_DATA ? mp_opt->data_len :0 , + opsize ==TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM ? mp_opt->csum :0 );break ;case MPTCPOPT_MP_JOIN :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2059/2214 mptcp: options: dss: avoid printing uninit csum
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
[ Upstream commit 00e2690c9dad0e09cd2a4435b98de6d8efd5fbc2 ]
When parsing the DSS suboption, this pr_debug() might read and print uninitialised checksum value.
That's mostly harmless, but that's also confusing. Fixing that also avoids some tools to complain about accessing uninit data.
So read this csum field only if it has been set.
Note: this was initially reported by Clashiko as an existing issue. The code has been analysed by a human and confirmed. This is a non-urgent fix.
--- net/mptcp/options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/options.c +1 -1
@@ -254,7 +254,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,pr_debug ("data_seq=%llu subflow_seq=%u data_len=%u csum=%d:%u\n" , mp_opt->data_seq, mp_opt->subflow_seq, mp_opt->data_len, !!(mp_opt->suboptions &OPTION_MPTCP_CSUMREQD ), - mp_opt->csum); + (mp_opt->suboptions &OPTION_MPTCP_CSUMREQD ) ? mp_opt->csum :0 ); }break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2060/2214 net: stmmac: avoid duplicate XSK TX completions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
[ Upstream commit daac93975b8ff0a0a036a5e3562236c0b40c3e36 ]
stmmac_tx_clean() reports completed AF_XDP TX descriptors through xsk_tx_completed(), but leaves their buffer type as STMMAC_TXBUF_T_XSK_TX. The slots retain that type until they are reused for another buffer type.
On interface close or XDP teardown, dma_free_tx_skbufs() walks the entire TX ring, not just the dirty_tx..cur_tx range. stmmac_free_tx_buffer() counts the stale XSK_TX slots again, causing xsk_tx_completed() to advance the completion-ring producer for buffers that have already been returned. This publishes completion entries without matching outstanding TX reservations and corrupts completion accounting for a socket which stays bound across the teardown.
Reset the XSK buffer type after counting the completion in both stmmac_tx_clean() and stmmac_free_tx_buffer(). XSK TX slots have a NULL skb pointer and no per-slot DMA mapping, so the SKB type represents an empty slot. Pending XSK descriptors keep their type until they are completed or released, and a released slot can no longer be counted again by a later cleanup.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -2
@@ -1553,8 +1553,10 @@ static void stmmac_free_tx_buffer(struct stmmac_priv *priv, u32 queue, int i) tx_q->xdpf[i] =NULL ; } -if (tx_q->tx_skbuff_dma[i].buf_type ==STMMAC_TXBUF_T_XSK_TX ) +if (tx_q->tx_skbuff_dma[i].buf_type ==STMMAC_TXBUF_T_XSK_TX ) { tx_q->xsk_frames_done++; + tx_q->tx_skbuff_dma[i].buf_type =STMMAC_TXBUF_T_SKB ; + }if (tx_q->tx_skbuff[i] && tx_q->tx_skbuff_dma[i].buf_type ==STMMAC_TXBUF_T_SKB ) {
@@ -2611,8 +2613,11 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue) tx_q->xdpf[entry] =NULL ; } -if (tx_q->tx_skbuff_dma[entry].buf_type ==STMMAC_TXBUF_T_XSK_TX ) +if (tx_q->tx_skbuff_dma[entry].buf_type ==STMMAC_TXBUF_T_XSK_TX ) { tx_q->xsk_frames_done++; +/* Teardown must not count this slot again. */ + tx_q->tx_skbuff_dma[entry].buf_type =STMMAC_TXBUF_T_SKB ; + }if (tx_q->tx_skbuff_dma[entry].buf_type ==STMMAC_TXBUF_T_SKB ) {if (likely (skb)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2061/2214 rtc: class: Make the time32 hctosys limit configurable
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit b253c2e96a80aac8e2bc67b425bf007ed78d4d8c ]
The RTC_HCTOSYS feature faces an impossible dilemma on 32-bit systems:
a) systemd requires RTC_HCTOSYS=y with the correct timestamp for its intended operation
b) broken RTC hardware can produce random future timestamps beyond 2038 at boot time
c) time32 userspace immediately hangs if the time is set to a date beyond 2038 and requires timestamps to be clamped
d) time64 userspace is intended to survive the actual 2038 date and requires timestamps to not be clamped
Commit b3a5ac42ab18 ("rtc: hctosys: Ensure system time doesn't overflow time_t") introduced this limit to protect time32 userspace from future RTC dates that can break boot and address constraints a), b) and c), but broke d) in the process by limiting RTC_HCTOSYS to the time32 range and falling back to RTC_HCTOSYS=n behavior when the RTC time overflows that.
Make the behavior configurable with a new RTC_HCTOSYS_TIME32_LIMIT option that chooses between breaking c) or d). On systems with COMPAT_32BIT_TIME=n, only RTC_HCTOSYS_TIME32_LIMIT=n is allowed since userspace can be assumed to be fully built for time64. 64-bit kernels running 32-bit userland never had the cutoff and continue to not offer the option.
Warn on rejection with the RTC date and option name so users can identify the cause and find the setting.
[arnd: reword Kconfig text and patch description,
add COMPAT_32BIT_TIME dependency]
----
I ended up rewriting most of the text but kept Karl's ownership as he did the original patch.
--- drivers/rtc/Kconfig | 21 +++++++++++++++++++++ drivers/rtc/class.c | 8 +++++--- 2 files changed, 26 insertions(+), 3 deletions(-)
drivers/rtc/Kconfig +21 -0
@@ -30,6 +30,27 @@ config RTC_HCTOSYS the value read from a specified RTC device. This is useful to avoid unnecessary fsck runs at boot time, and to network better. +config RTC_HCTOSYS_TIME32_LIMIT + bool "Reject RTC dates after the 2038 cutoff" + depends on RTC_HCTOSYS && COMPAT_32BIT_TIME && !64BIT + default y + help + Reject RTC dates after 03:14:07 UTC on 19 January 2038 when + initializing the system clock in order to work around broken + RTC implementations that produce nondeterministic timestamps + without a working backup battery. + + A rejected date leaves system time unchanged, normally near + the Unix epoch, and the RTC's hctosys sysfs attribute reads + 0. Userspace must supply the time if no other source has + initialized it. + + Say Y here if the kernel may have to run old time32 userspace on + hardware that can produce unpredictable RTC timestamps. If the + kernel is intended to only run time64 compatible userspace and + continue working past 2038, you must pick N here in order to + have a working RTC_HCTOSYS functionality. + config RTC_HCTOSYS_DEVICE string "RTC used to set the system time" depends on RTC_HCTOSYS
drivers/rtc/class.c +5 -3
@@ -73,12 +73,14 @@ static void rtc_hctosys(struct rtc_device *rtc) tv64.tv_sec =rtc_tm_to_time64 (&tm); -#if BITS_PER_LONG ==32 -if (tv64.tv_sec >INT_MAX ) { +if (IS_ENABLED (CONFIG_RTC_HCTOSYS_TIME32_LIMIT ) && + tv64.tv_sec >INT_MAX ) { +dev_warn (rtc->dev.parent, +"hctosys: rejecting %ptR UTC due to CONFIG_RTC_HCTOSYS_TIME32_LIMIT=y\n" , + &tm); err = -ERANGE ; goto err_read; } -#endif err =do_settimeofday64 (&tv64);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2062/2214 timers: Move timer sysctl into the timer code
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: tangmeng <[email protected]>
[ Upstream commit efaa0227f6c6a5073951b20cf2f8c63c4155306c ]
This is part of the effort to reduce kernel/sysctl.c to only contain the core logic.
Stable-dep-of: e7cad586d732 ("timers: Clear pending_map on CPU hotplug")
--- include/linux/timer.h | 8 ------- kernel/sysctl.c | 11 --------- kernel/time/timer.c | 53 +++++++++++++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 34 deletions(-)
include/linux/timer.h +0 -8
@@ -217,14 +217,6 @@ extern void init_timers(void);struct hrtimer ;extern enum hrtimer_restart it_real_fn (struct hrtimer *); -#if defined(CONFIG_SMP ) && defined(CONFIG_NO_HZ_COMMON ) -struct ctl_table ; - -extern unsigned int sysctl_timer_migration; -int timer_migration_handler (struct ctl_table *table,int write, -void *buffer,size_t *lenp,loff_t *ppos); -#endif -unsigned long __round_jiffies (unsigned long j,int cpu);unsigned long __round_jiffies_relative (unsigned long j,int cpu);unsigned long round_jiffies (unsigned long j);
kernel/sysctl.c +0 -11
@@ -2588,17 +2588,6 @@ static struct ctl_table kern_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, -#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) - { - .procname = "timer_migration", - .data = &sysctl_timer_migration, - .maxlen = sizeof(unsigned int), - .mode = 0644, - .proc_handler = timer_migration_handler, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, -#endif#ifdef CONFIG_BPF_SYSCALL { .procname = "unprivileged_bpf_disabled",
kernel/time/timer.c +38 -15
77 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2063/2214 timers: Clear pending_map on CPU hotplug
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liang Hao <[email protected]>
[ Upstream commit e7cad586d73276cbd4466de81b2092287d7475c0 ]
CPU hotplug migration leaves pending_map bits set on the outgoing CPU while its wheel vectors are empty. After re-online, a later next_expiry recalc can treat those empty buckets as pending and temporarily pull next_expiry forward until collect drains the bits.
Clear pending_map under the base lock after migration in timers_dead_cpu().
--- kernel/time/timer.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/time/timer.c +2 -0
@@ -45,6 +45,7 @@#include <linux/compat.h> #include <linux/random.h> #include <linux/sysctl.h> +#include <linux/bitmap.h> #include <linux/uaccess.h> #include <asm/unistd.h>
@@ -2244,6 +2245,7 @@ int timers_dead_cpu(unsigned int cpu)for (i =0 ; i <WHEEL_SIZE ; i++)migrate_timer_list (new_base, old_base->vectors + i); +bitmap_zero (old_base->pending_map,WHEEL_SIZE );raw_spin_unlock (&old_base->lock);raw_spin_unlock_irq (&new_base->lock);put_cpu_ptr (&timer_bases);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2064/2214 ASoC: cs42l56: Remove the ADC Mute Switch control
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit ff404ef11b975baf38c4472c51a6674c239e8021 ]
The ADC Mute Switch control writes bits 2 and 3 of the Misc ADC Control register. These are the ADCA Invert and ADCB Invert bits, which have their own controls. The ADC mute bits are bits 0 and 1, and the DAI mute callback already sets them.
So the control has never muted the ADCs, and nobody can be relying on it. Remove it rather than point it at the mute bits, so the ADCs are muted in one place only.
--- sound/soc/codecs/cs42l56.c | 1 - 1 file changed, 1 deletion(-)
sound/soc/codecs/cs42l56.c +0 -1
@@ -387,7 +387,6 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = { CS42L56_PGAB_MUX_VOLUME, 0, 0x34, 0x24, pga_tlv),SOC_DOUBLE_R_TLV ("ADC Volume" ,CS42L56_ADCA_ATTENUATOR ,CS42L56_ADCB_ATTENUATOR ,0 ,0x00 ,1 , adc_tlv), -SOC_DOUBLE ("ADC Mute Switch" ,CS42L56_MISC_ADC_CTL ,2 ,3 ,1 ,1 ),SOC_DOUBLE ("ADC Boost Switch" ,CS42L56_GAIN_BIAS_CTL ,3 ,2 ,1 ,1 ), SOC_DOUBLE_R_SX_TLV("Headphone Volume", CS42L56_HPA_VOLUME,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2065/2214 net: openvswitch: skip IPv4 later fragments on TCP/UDP set actions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 14c0350142ab0a10ebeefed03b779df23749e16a ]
An IPv4 later fragment carries no L4 header, but key extraction leaves ip.proto set to the real protocol and the flow may wildcard the frag field, so validate_set() accepts such packets. set_tcp() and set_udp() then treat the first bytes of the fragment payload as an L4 header, rewrite them as ports and patch the bytes at the checksum offset, corrupting the packet.
Skip these actions for OVS_FRAG_TYPE_LATER. IPv6 later fragments are not affected, since their ip.proto is NEXTHDR_FRAGMENT and validate_set() rejects L4 set actions for them.
--- net/openvswitch/actions.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/openvswitch/actions.c +6 -0
@@ -617,6 +617,9 @@ static int set_udp(struct sk_buff *skb, struct sw_flow_key *flow_key,__be16 src, dst;int err; +if (flow_key->ip.frag ==OVS_FRAG_TYPE_LATER ) +return 0 ; + err =skb_ensure_writable (skb,skb_transport_offset (skb) +sizeof (struct udphdr ));if (unlikely (err))
@@ -660,6 +663,9 @@ static int set_tcp(struct sk_buff *skb, struct sw_flow_key *flow_key,__be16 src, dst;int err; +if (flow_key->ip.frag ==OVS_FRAG_TYPE_LATER ) +return 0 ; + err =skb_ensure_writable (skb,skb_transport_offset (skb) +sizeof (struct tcphdr ));if (unlikely (err))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2066/2214 net: openvswitch: drop IP fragments on SCTP set action
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 4d0d8f491307f22aea34b22f73351e1cd2ede735 ]
The SCTP checksum is a CRC32c over the whole SCTP packet. set_sctp() updates it as old_csum ^ old_correct_csum ^ new_csum, with the two CRCs computed over the bytes of the current skb only. That is correct only when the skb holds the whole SCTP packet. For a first fragment, and for a later fragment, it holds just a part of it, and the CRC delta of a change at the start of the packet depends on how many bytes follow, so the checksum written is wrong. The receiver drops the reassembled packet.
validate_set() accepts SCTP set action for any flow with ip.proto set to SCTP, regardless of the fragmentation bits, as it only receives the masked key. As the checksum cannot be fixed up without the whole datagram, fail the action for packets that are IP fragments of either family, so the packet is dropped with OVS_DROP_ACTION_ERROR instead of being forwarded with modified ports and an invalid checksum.
--- net/openvswitch/actions.c | 3 +++ 1 file changed, 3 insertions(+)
net/openvswitch/actions.c +3 -0
@@ -696,6 +696,9 @@ static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key,__le32 old_correct_csum, new_csum, old_csum;int err; +if (flow_key->ip.frag !=OVS_FRAG_TYPE_NONE ) +return -EINVAL ; + err =skb_ensure_writable (skb, sctphoff +sizeof (struct sctphdr ));if (unlikely (err))return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2067/2214 tcp_metrics: use dst_dev_net_rcu()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 50c127a69cd6285300931853b352a1918cfa180f ]
Replace three dst_dev() with a lockdep enabled helper.
Stable-dep-of: 504bdcb8c156 ("tcp: tcp_metrics: use the socket netns, not the dst device netns")
--- net/ipv4/tcp_metrics.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv4/tcp_metrics.c +3 -3
@@ -170,7 +170,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,struct net *net;spin_lock_bh (&tcp_metrics_lock); - net =dev_net_rcu (dst_dev (dst)); + net =dst_dev_net_rcu (dst);/* While waiting for the spin-lock the cache might have been populated * with this entry and so we have to check again.
@@ -273,7 +273,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,return NULL ; } - net =dev_net_rcu (dst_dev (dst)); + net =dst_dev_net_rcu (dst); hash ^=net_hash_mix (net); hash =hash_32 (hash, tcp_metrics_hash_log);
@@ -318,7 +318,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,else return NULL ; - net =dev_net_rcu (dst_dev (dst)); + net =dst_dev_net_rcu (dst); hash ^=net_hash_mix (net); hash =hash_32 (hash, tcp_metrics_hash_log);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2068/2214 tcp: tcp_metrics: use the socket netns, not the dst device netns
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 504bdcb8c1566a6f887f9accebe1aa99b502ae97 ]
tcp_get_metrics(), __tcp_get_metrics_req() and tcpm_new() look up and create metrics entries in the netns of the cached dst device rather than in the netns of the socket.
These usually match, but not after the device has been moved to another netns or unregistered: a socket can keep a stale dst in sk_dst_cache until it is checked again, and tcp_update_metrics() reads it with __sk_dst_get() without any dst_check(). Once dst_dev_put() has run, the dst device is blackhole_netdev and the entry is created in init_net. Before that, for instance for routes through nexthop objects whose cached dsts are released from a nested RCU callback, it is the netns the device has just been moved to.
A TCP socket of netns A that enters TIME_WAIT in that window then creates or updates an entry carrying A's addresses and RTT in another netns, where TCP_METRICS_CMD_GET can dump it and where new connections to the same peer inherit those metrics.
The metrics belong to the netns of the socket, so use sock_net() for full sockets and request sockets, and pass it to tcpm_new().
Kernel sockets that do not hold a netns reference can still reach tcp_time_wait() after tcp_net_metrics_exit_batch() has flushed the entries of their dismantling netns, and an entry created then would never be flushed and would keep a dangling tcpm_net. Make tcpm_new() refuse to create entries when check_net() fails. Its callers are in an RCU read-side section, and cleanup_net() waits for a grace period between the refcount reaching zero and the flush, so an entry added after a successful check is always seen by the flush.
--- net/ipv4/tcp_metrics.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
net/ipv4/tcp_metrics.c +15 -5
@@ -161,16 +161,26 @@ static void tcpm_check_stamp(struct tcp_metrics_block *tm, rcu_dereference_protected(p, lockdep_is_held(&tcp_metrics_lock))static struct tcp_metrics_block *tcpm_new (struct dst_entry *dst, +struct net *net,struct inetpeer_addr *saddr,struct inetpeer_addr *daddr,unsigned int hash) {struct tcp_metrics_block *tm;bool reclaim = false; -struct net *net;spin_lock_bh (&tcp_metrics_lock); - net =dst_dev_net_rcu (dst); + +/* Do not add entries to a dismantling netns: they would not be +* flushed again. Callers are in an RCU read-side section, and +* cleanup_net() waits for a grace period after the netns refcount +* reached zero and before tcp_metrics_flush_all(NULL) runs, so an +* entry added after a successful check_net() is seen by the flush. +*/ +if (unlikely (!check_net (net))) { + tm =NULL ; + goto out_unlock; + }/* While waiting for the spin-lock the cache might have been populated * with this entry and so we have to check again.
@@ -273,7 +283,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,return NULL ; } - net =dst_dev_net_rcu (dst); + net =sock_net (req_to_sk (req)); hash ^=net_hash_mix (net); hash =hash_32 (hash, tcp_metrics_hash_log);
@@ -318,7 +328,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,else return NULL ; - net =dst_dev_net_rcu (dst); + net =sock_net (sk); hash ^=net_hash_mix (net); hash =hash_32 (hash, tcp_metrics_hash_log);
@@ -326,7 +336,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,if (tm ==TCP_METRICS_RECLAIM_PTR ) tm =NULL ;if (!tm && create) - tm =tcpm_new (dst, &saddr, &daddr, hash); + tm =tcpm_new (dst, net, &saddr, &daddr, hash);else tcpm_check_stamp (tm, dst);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2069/2214 tls: device: protect async RX resync state during device-down
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rishikesh Jethwani <[email protected]>
[ Upstream commit f89a228125238f8d4c7e2b8161e2a85fe35307b6 ]
tls_device_rx_resync_new_rec() can run in process context with the socket lock held, but without an RCU read lock: from the strparser work item (tls_strp_work()) and from the receive paths (tls_rx_rec_wait(), tls_rx_rec_done()). The resync_async pointer belongs to the driver RX context, which tls_device_down() tears down from the netdev notifier without taking the socket lock; only the softirq entry to the parser is implicitly inside an RCU section.
If the parser passes the TLS_RX_DEV_DEGRADED check before device-down sets it, tls_device_down() can complete synchronize_net() and delete the driver context before the parser accesses resync_async->req or its record log. In the asynchronous stage the parser also writes the record log, so this is a write to freed memory, not only a stale read. The RCU section in tls_device_resync_rx() starts after those accesses and therefore does not prevent the use-after-free.
Found by code inspection; not reproduced. Hitting the window requires the parser to be preempted between the DEGRADED check and the resync_async access across the device-down grace period and the driver's teardown.
--- net/tls/tls_device.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
net/tls/tls_device.c +15 -6
@@ -753,8 +753,15 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)if (tls_ctx->rx_conf !=TLS_HW )return ; + +/* The parser also runs in process context, without an RCU read lock. +* Protect the driver's resync_async state before checking the flags: +* device-down sets DEGRADED and waits for synchronize_net() before +* freeing it, without taking the socket lock. +*/ +rcu_read_lock ();if (unlikely (test_bit (TLS_RX_DEV_DEGRADED , &tls_ctx->flags))) -return ; + goto out; prot = &tls_ctx->prot_info; rx_ctx =tls_offload_ctx_rx (tls_ctx);
@@ -769,11 +776,11 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)if (likely (!is_req_pending) || req_seq != seq || !atomic64_try_cmpxchg (&rx_ctx->resync_req, &resync_req,0 )) -return ; + goto out;break ;case TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT :if (likely (!rx_ctx->resync_nh_do_now)) -return ; + goto out;/* head of next rec is already in, note that the sock_inq will * include the currently parsed message when called from parser
@@ -782,7 +789,7 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)if (sock_data > rcd_len) {trace_tls_device_rx_resync_nh_delay (sk, sock_data, rcd_len); -return ; + goto out; } rx_ctx->resync_nh_do_now =0 ;
@@ -793,16 +800,18 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) resync_req =atomic64_read (&rx_ctx->resync_async->req); is_req_pending = resync_req;if (likely (!is_req_pending)) -return ; + goto out;if (!tls_device_rx_resync_async (rx_ctx->resync_async, resync_req, &seq, &rcd_delta)) -return ; + goto out;tls_bigint_subtract (rcd_sn, rcd_delta);break ; }tls_device_resync_rx (tls_ctx, sk, seq, rcd_sn); +out: +rcu_read_unlock (); } static void tls_device_core_ctrl_rx_resync(struct tls_context *tls_ctx,
Signature · 1 line
2.53.0