6.12.118-rc1 review
Greg Kroah-Hartman
maintainerPATCH 365/670 ALSA: cs46xx: Handle SCB creation failures before dereferencing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Kazinsky <[email protected]>
[ Upstream commit 023d3e1176202339cd94a3d732e3aec74e36ba22 ]
With CONFIG_PM_SLEEP enabled, cs46xx_dsp_create_scb() can return NULL if kmemdup() fails to allocate the SCB data saved for resume. cs46xx_dsp_scb_and_task_init() and _dsp_create_generic_scb() dereference the returned pointer without checking it, causing a NULL pointer dereference on allocation failure.
Check both return values before accessing the SCB descriptors. Return -ENOMEM when creating the null SCB fails and propagate NULL from _dsp_create_generic_scb().
Found by Linux Verification Center (linuxtesting.org) with SVACE static analysis tool.
--- sound/pci/cs46xx/dsp_spos.c | 2 ++ sound/pci/cs46xx/dsp_spos_scb_lib.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
sound/pci/cs46xx/dsp_spos.c +2 -0
@@ -1110,6 +1110,8 @@ int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip) null_scb.entry_point = null_algorithm->address; ins->the_null_scb =cs46xx_dsp_create_scb (chip,"nullSCB" , (u32 *)&null_scb,NULL_SCB_ADDR ); +if (!ins->the_null_scb) +return -ENOMEM ; ins->the_null_scb->task_entry = null_algorithm; ins->the_null_scb->sub_list_ptr = ins->the_null_scb; ins->the_null_scb->next_scb_ptr = ins->the_null_scb;
sound/pci/cs46xx/dsp_spos_scb_lib.c +2 -1
@@ -285,7 +285,8 @@ _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, udev_dbg (chip->card->dev,"dsp_spos: creating SCB <%s>\n" , name); scb =cs46xx_dsp_create_scb (chip,name,scb_data,dest); - +if (!scb) +return NULL ; scb->sub_list_ptr = ins->the_null_scb; scb->next_scb_ptr = ins->the_null_scb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/670 ALSA: bcd2000: Fix use-after-free of MIDI URBs on file close
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: YuanZhe Liu <[email protected]>
[ Upstream commit f6c7bb1f0799591a62be75b9bcf84245b4f208b7 ]
bcd2000_disconnect() calls snd_card_disconnect(), which only prevents new opens, and then frees the MIDI URBs. A rawmidi file that was already open can still be closed afterwards, and its close callback, bcd2000_midi_output_close(), calls usb_kill_urb() on midi_out_urb.
The URB pointers are cleared on disconnect and their accesses are serialized with midi_lock, but bcd2000_midi_output_close() reads midi_out_urb without that lock. The check can therefore pass just before the pointer is cleared, and usb_kill_urb() then runs on the URB that has already been freed:
BUG: KASAN: slab-use-after-free in usb_kill_urb+0x74/0x80 Read of size 8 at addr ffff8880078e7d40 usb_kill_urb bcd2000_midi_output_close close_substream rawmidi_release_priv snd_rawmidi_release
Allocated by: usb_alloc_urb <- bcd2000_init_midi <- bcd2000_probe
Freed by: usb_free_urb <- bcd2000_midi_free
<- bcd2000_disconnect
Take the lock in bcd2000_midi_output_close() and reference the URB with usb_get_urb() before releasing it. The URB then stays valid until usb_put_urb() after usb_kill_urb() has returned, even if a disconnect frees it in the meantime. usb_kill_urb() itself cannot run under midi_lock, as the completion handler takes the same lock.
--- sound/usb/bcd2000/bcd2000.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
sound/usb/bcd2000/bcd2000.c +17 -3
@@ -183,10 +183,24 @@ static int bcd2000_midi_output_open(struct snd_rawmidi_substream *substream)static int bcd2000_midi_output_close (struct snd_rawmidi_substream *substream) {struct bcd2000 *bcd2k = substream->rmidi->private_data; +struct urb *urb =NULL ; -if (bcd2k->midi_out_active && bcd2k->midi_out_urb) { -usb_kill_urb (bcd2k->midi_out_urb); - bcd2k->midi_out_active =0 ; +/* +* Reference the URB under the lock so that it stays valid until +* usb_kill_urb() returns, even if a disconnect frees it in the +* meantime. usb_kill_urb() cannot run under the lock, as the +* completion handler takes the same lock. +*/ + scoped_guard(spinlock_irqsave, &bcd2k->midi_lock) { +if (bcd2k->midi_out_active && bcd2k->midi_out_urb) { + urb =usb_get_urb (bcd2k->midi_out_urb); + bcd2k->midi_out_active =0 ; + } + } + +if (urb) { +usb_kill_urb (urb); +usb_put_urb (urb); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/670 ALSA: usx2y: Refuse a retried DSP load after a failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: YuanZhe Liu <[email protected]>
[ Upstream commit 1f8101b6adc87a3ddbd51fcb6609251591758026 ]
snd_usx2y_hwdep_dsp_load() sets up the asynchronous sequence URBs and the interrupt URB when the FPGA firmware image with index 1 is loaded, and then creates the ALSA devices. If usx2y_in04_init() or usx2y_create_alsa_devices() fails, the URBs that were already set up are left in place.
The core keeps the index unloaded when the callback fails, so user space may issue the same request again. The second attempt then enters usx2y_async_seq04_init() or usx2y_in04_init() with the URBs still allocated and trips WARN_ON(usx2y->as04.buffer) or WARN_ON(usx2y->in04_urb).
The URBs cannot be released at this point: the card may already have registered PCM devices that user space can still open, and the disconnect handler accesses the URBs without holding the DSP lock. Mark the chip as hung instead, so that a retried request is refused with -ENODEV and the assertions keep their meaning. The URBs are released by snd_usx2y_card_private_free() when the card is freed.
A failing usx2y_async_seq04_init() still releases its own URBs, so that path remains retryable.
--- sound/usb/usx2y/usX2Yhwdep.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/usb/usx2y/usX2Yhwdep.c +5 -0
@@ -179,6 +179,9 @@ static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw,int lret, err;char *buf; +if (priv->chip_status &USX2Y_STAT_CHIP_HUP ) +return -ENODEV ; + buf =memdup_user (dsp->image, dsp->length);if (IS_ERR (buf))return PTR_ERR (buf);
@@ -201,11 +204,13 @@ static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw, err =usx2y_in04_init (priv);if (err) {dev_err (&dev->dev,"usx2y_in04_init error\n" ); + priv->chip_status |=USX2Y_STAT_CHIP_HUP ;return err; } err =usx2y_create_alsa_devices (hw->card);if (err) {dev_err (&dev->dev,"usx2y_create_alsa_devices error %i\n" , err); + priv->chip_status |=USX2Y_STAT_CHIP_HUP ;return err; } priv->chip_status |=USX2Y_STAT_CHIP_INIT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/670 ALSA: line6: Reject capture buffers smaller than two packets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit db51425c9eb038a8e40e09b837afde015ae9e3ec ]
line6_capture_copy() splits the copy into the ALSA ring buffer once at the buffer end and wraps pos_done once, which is only correct when one packet holds at most buffer_size frames. The packet size comes from the device's endpoint, and the per-device hw structs allow 64-byte periods with periods_min 1, so a packet can be larger than the whole buffer. audio_in_callback() logs an oversized packet and then copies it anyway.
The packet size is known at probe time, so constrain SNDRV_PCM_HW_PARAM_BUFFER_BYTES in snd_line6_capture_open() to at least twice the larger of the two endpoints' packet sizes. Two rather than one, because pos_done advances by the packet and wraps once, so a buffer of exactly one packet leaves the position unchanged after every packet. hw_params then rejects a buffer that cannot hold two packets, and the single wrap is valid for every configuration that gets through. Keep a guard in line6_capture_copy() that drops an oversized packet with a ratelimited error, for the case that should no longer be reachable.
Reproduced on 7.3-rc7 with a USB/IP device presenting the GuitarPort interface layout and 1024-byte packets into a 128-byte buffer: ALSA logged "invalid position: pos = 224, buffer size = 32" and the driver logged "driver bug: len" on every following packet. With this patch a 1024-byte buffer is refused at hw_params, and a 2048-byte buffer streams for 30 s with no report and with the position moving inside the buffer.
--- sound/usb/line6/capture.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
sound/usb/line6/capture.c +29 -0
@@ -94,6 +94,18 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)if (runtime ==NULL )return ; +/* +* snd_line6_capture_open() constrains the buffer to hold at least +* two packets, so this cannot happen for a conforming device. Drop +* the packet rather than overrun the single wrap below. +*/ +if (unlikely (frames > runtime->buffer_size)) { +dev_err_ratelimited (line6pcm->line6->ifcdev, +"packet of %d frames exceeds %lu-frame buffer, dropping\n" , + frames, runtime->buffer_size); +return ; + } +if (line6pcm->in.pos_done + frames > runtime->buffer_size) {/* The transferred area goes over buffer boundary,
@@ -228,6 +240,23 @@ static int snd_line6_capture_open(struct snd_pcm_substream *substream)if (err <0 )return err; +/* +* line6_capture_copy() wraps the ring buffer once per packet and +* advances pos_done by the packet, which only works when the buffer +* holds more than one packet: with exactly one, pos_done gains a +* buffer and loses it again on every packet. The packet size comes +* from the device, so bound the buffer by two packets here. The +* impulse-response path copies a playback URB into this ring, so +* take the larger of the two endpoints. +*/ + err =snd_pcm_hw_constraint_minmax (runtime, +SNDRV_PCM_HW_PARAM_BUFFER_BYTES , +2 *max (line6pcm->max_packet_size_in, + line6pcm->max_packet_size_out), +UINT_MAX ); +if (err <0 ) +return err; +line6_pcm_acquire (line6pcm,LINE6_STREAM_CAPTURE_HELPER , false); runtime->hw = line6pcm->properties->capture_hw;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/670 ALSA: caiaq: free the EP4 URB when input setup fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit d21746bafdb8e1a5fc9bdcb86f603d827a500a62 ]
The three controllers that use the EP4 input URB allocate it before checking the endpoint type and before registering the input device. On failure they jump to exit_free_idev, which clears cdev->input_dev but leaves cdev->ep4_in_urb set. The card teardown then calls snd_usb_caiaq_input_free(), which returns early because input_dev is NULL, so the URB is never freed.
Release the URB before dropping the input device on the error path.
--- sound/usb/caiaq/input.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/caiaq/input.c +2 -0
@@ -830,6 +830,8 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)return 0 ; exit_free_idev: +usb_free_urb (cdev->ep4_in_urb); + cdev->ep4_in_urb =NULL ;input_free_device (input); cdev->input_dev =NULL ;return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/670 ALSA: usx2y: Require a buffer of two URBs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit 4cbb826b3b36df6c275454287ba1df4564a5370b ]
usx2y_urb_capt_retire() wraps the ring buffer once per packet and usx2y_urb_play_prepare() once per URB of nr_of_packs() packets of up to 50 frames. Both assume that the data fits in the buffer, and the hw constraints only require about two 1 ms periods, so a packet larger than the buffer on capture, or a URB larger than the buffer on playback, violates that assumption.
Constrain SNDRV_PCM_HW_PARAM_BUFFER_SIZE in snd_usx2y_pcm_open() to at least two URBs, 2 * nr_of_packs() * 50 frames, for both directions. The bound is in frames and derived from the driver's own packet limit, so it does not read the endpoint, whose altsetting is only selected in prepare. Two URBs rather than one, because the position advances by a URB on playback and only moves when a URB is less than the whole buffer. Keep a guard in usx2y_urb_capt_retire() that drops a packet larger than the buffer, for the case the constraint makes unreachable.
With nrpacks above about 163 (S16_LE) or 109 (S24_3LE) the bound exceeds the 64 KiB buffer the substream preallocates (twice that with the preallocation raised to its 128 KiB maximum), so hw_params fails for those module settings. That is intended: the driver cannot be safe with a URB larger than half the largest buffer.
Reproduced on 7.3-rc7 with a USB/IP device presenting the US-122 interface layout and 1024-byte packets into a 512-byte capture buffer:
BUG: KASAN: out-of-bounds in i_usx2y_urb_complete+0x1285/0x1ac0 Read of size 18446744073709551104 at addr ffff88800e448800 by task vhci_rx/83
Tested on 7.3-rc7 with the same device, S16_LE at 44100 Hz, nrpacks 4, so the bound is 400 frames. A 128-frame capture buffer and a 200-frame playback buffer are refused at hw_params with EINVAL. A 400-frame buffer streams for 30 s in each direction with the position advancing inside the buffer and no KASAN report; the capture guard did not fire. The same 400-frame capture buffer with S24_3LE, which selects altsetting 2 in prepare, streams for 30 s with the same result.
--- sound/usb/usx2y/usbusx2yaudio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
sound/usb/usx2y/usbusx2yaudio.c +24 -0
@@ -51,6 +51,18 @@ static int usx2y_urb_capt_retire(struct snd_usx2y_substream *subs)dev_dbg (&usx2y->dev->dev,"%s: 0 == len ERROR!\n" , __func__);continue ; } +/* +* snd_usx2y_pcm_open() constrains the buffer to hold at least +* two URBs, so this cannot happen for a device that keeps its +* packets at 50 frames. Drop the packet rather than exceed the +* single wrap below. +*/ +if (unlikely (len > runtime->buffer_size)) { +dev_err_ratelimited (&usx2y->dev->dev, +"%s: packet of %i frames exceeds %lu-frame buffer, dropping\n" , + __func__, len, runtime->buffer_size); +continue ; + }/* copy a data chunk */ if ((hwptr_done + len) > runtime->buffer_size) {
@@ -897,6 +909,18 @@ static int snd_usx2y_pcm_open(struct snd_pcm_substream *substream) runtime->private_data = subs; subs->pcm_substream = substream;snd_pcm_hw_constraint_minmax (runtime,SNDRV_PCM_HW_PARAM_PERIOD_TIME ,1000 ,200000 ); +/* +* Capture wraps the ring buffer once per packet and playback once +* per URB of nr_of_packs() packets of at most 50 frames (see +* usx2y_urb_play_prepare()). Playback needs the buffer to hold more +* than one URB and capture more than one packet; use the URB bound +* for both, and two URBs rather than one, because the position only +* advances when a URB is less than the whole buffer. The bound is in +* frames and does not depend on the altsetting, which is selected +* in prepare. +*/ +snd_pcm_hw_constraint_minmax (runtime,SNDRV_PCM_HW_PARAM_BUFFER_SIZE , +2 *nr_of_packs () *50 ,UINT_MAX );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/670 ALSA: usx2y: Guard the playback copy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit e2c6de52ffacb2c0f4076884ee3fdb744735a4cb ]
usx2y_urb_play_prepare() sums the packet lengths of a whole URB, copies that many frames with a single wrap, and sizes each playback packet from the capture packet's actual_length. Three things are unchecked: that the URB fits in the ring buffer, that a packet fits in the playback endpoint's maxpacksize, from which tmpbuf is allocated, and that actual_length is a whole number of frames. The ISO descriptors take the raw actual_length while transfer_buffer_length and the copies take count * stride, so a packet that is not a multiple of the stride makes the descriptors add up to more than the buffer, by up to stride - 1 bytes per packet.
Return -EPIPE, as the existing packet-size check does, when the URB is larger than the buffer or a packet is larger than maxpacksize, and size each descriptor from whole frames, so the descriptors add up to transfer_buffer_length and each stays within maxpacksize. The buffer case is prevented by the previous patch and this is the guard for it; the other two depend only on the device.
The first case is reachable on the unpatched driver with ordinary
packets: on 7.3-rc7, a USB/IP device presenting the US-122 interface layout and sending 48-frame packets, with a 100-frame playback buffer (two 50-frame periods, inside the stock constraints), KASAN reports:
BUG: KASAN: out-of-bounds in i_usx2y_urb_complete+0x79b/0x1ac0 Read of size 18446744073709551280 at addr ffff88800e6b02e0 by task vhci_rx/80
With both patches, the same device and a 200-frame playback buffer is refused at hw_params with EINVAL, and a 400-frame buffer plays for 30 s with the position advancing inside the buffer, no KASAN report and neither guard message. The maxpacksize check is not exercised: the emulated device reports the same wMaxPacketSize on both endpoints.
The descriptor case is visible with capture packets of 195 bytes at stride 4 (48 frames and 3 bytes): without this change the four descriptors add up to 780 bytes for 768 bytes of data, and USB/IP's completion check refuses the URB ("total length of iso packets 780 not equal to actual length of buffer 768", -EPROTO), after which the driver stops the streams. With this patch every descriptor is 192 bytes, the descriptors add up to the data in every URB for 30 s, the position advances inside the buffer and KASAN reports nothing. The 48-frame playback run above is unchanged.
--- sound/usb/usx2y/usbusx2yaudio.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
sound/usb/usx2y/usbusx2yaudio.c +18 -1
@@ -118,14 +118,31 @@ static int usx2y_urb_play_prepare(struct snd_usx2y_substream *subs, __func__, counts);return -EPIPE ; } +if (counts * usx2y->stride > subs->maxpacksize) { +dev_err_ratelimited (&usx2y->dev->dev, +"%s: packet of %i bytes exceeds maxpacksize %u\n" , + __func__, counts * usx2y->stride, + subs->maxpacksize); +return -EPIPE ; + }/* set up descriptor */ urb->iso_frame_desc[pack].offset = pack ? urb->iso_frame_desc[pack -1 ].offset + urb->iso_frame_desc[pack -1 ].length :0 ; - urb->iso_frame_desc[pack].length = cap_urb->iso_frame_desc[pack].actual_length; + urb->iso_frame_desc[pack].length = counts * usx2y->stride; }if (atomic_read (&subs->state) >=STATE_PRERUNNING ) { +/* +* The copy below wraps once, which needs count <= buffer_size. +* snd_usx2y_pcm_open() guarantees it; guard anyway. +*/ +if (unlikely (count > runtime->buffer_size)) { +dev_err_ratelimited (&usx2y->dev->dev, +"%s: URB of %i frames exceeds %lu-frame buffer, stopping\n" , + __func__, count, runtime->buffer_size); +return -EPIPE ; + }if (subs->hwptr + count > runtime->buffer_size) {/* err, the transferred area goes over buffer boundary. * copy the data to the temp buffer.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/670 ext2: preserve IOMAP_F_DIRTY for extending direct writes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 4f91b042af212ca0b610e43f9a975ddc7f0d0923 ]
ext2_iomap_begin() sets IOMAP_F_DIRTY for writes that may extend i_size, but clears the flag after ext2_get_blocks(). When the write uses an existing mapped block, iomap can then use FUA and skip generic_write_sync(), even though ext2_dio_write_end_io() updates the inode size. An O_DSYNC write can therefore return without persisting the new size.
For example, on a FUA-capable device, a 512-byte O_DIRECT|O_DSYNC write at offset 512 into a fsynced one-byte file returns successfully and extends the in-memory size to 1024, while an immediate read of the on-disk inode still shows size 1. An explicit fsync persists the new size.
Move setting of IOMAP_F_DIRTY after the initialization.
--- fs/ext2/inode.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/ext2/inode.c +6 -7
@@ -824,6 +824,12 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, (first_block << blkbits) < i_size_read(inode)) create =0 ; + ret =ext2_get_blocks (inode, first_block, max_blocks, + &bno, &new, &boundary, create); +if (ret <0 ) +return ret; + + iomap->flags =0 ;/* * Writes that span EOF might trigger an IO size update on completion, * so consider them to be dirty for the purposes of O_DSYNC even if
@@ -831,13 +837,6 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,*/ if ((flags &IOMAP_WRITE ) && offset + length >i_size_read (inode)) iomap->flags |=IOMAP_F_DIRTY ; - - ret =ext2_get_blocks (inode, first_block, max_blocks, - &bno, &new, &boundary, create); -if (ret <0 ) -return ret; - - iomap->flags =0 ; iomap->offset = (u64 )first_block << blkbits;if (flags &IOMAP_DAX ) iomap->dax_dev = sbi->s_daxdev;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/670 net/smc: dont spin in smc_rx_recvmsg() while a pipe holds spliced data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit 8288ba942cfd20621c05e16978b7c3da91513ae1 ]
While bytes spliced off the RMB are still in a pipe, recvmsg() waits for the pipe to release them before it copies the data behind them. The path to that wait skips the timeout and signal checks, and smc_rx_wait() returns at once on RCV_SHUTDOWN. With a signal pending, after SHUT_RD, or once the peer closes or shuts down writing, recvmsg() spins on a CPU until the pipe is drained, and SIGKILL cannot stop it. MSG_DONTWAIT and an expired SO_RCVTIMEO wait there too instead of returning -EAGAIN.
Check the timeout and signals before that wait, and end it when the pipe releases the data or the connection is killed, not on RCV_SHUTDOWN. A zero-length read returns 0 without waiting for the pipe; a non-blocking one returns -EAGAIN while poll() still reports the socket readable (splice() can still take those bytes). The wait sets SOCKWQ_ASYNC_WAITDATA like smc_rx_wait(), so a byte arriving behind the pipe raises no SIGIO on a reader already asleep for it, and a full barrier orders its wait queue entry before its read of splice_pending, so no wake is lost.
--- net/smc/smc_rx.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
net/smc/smc_rx.c +38 -1
@@ -286,6 +286,27 @@ int smc_rx_wait(struct smc_sock *smc, long *timeo, size_t peeked,return rc; } +/* Wait for the pipe to release the spliced data. Unlike smc_rx_wait() +* it does not end on shutdown or sk_err, the data is already in the +* RMB; smc_conn_kill() wakes it and the caller checks conn->killed. +*/ +static void smc_rx_wait_splice (struct smc_sock *smc,long *timeo) +{ +DEFINE_WAIT_FUNC (wait, woken_wake_function); +struct smc_connection *conn = &smc->conn; +struct sock *sk = &smc->sk; + +sk_set_bit (SOCKWQ_ASYNC_WAITDATA , sk); +add_wait_queue (sk_sleep (sk), &wait); +/* pairs with the smp_mb() in wq_has_sleeper(): the release drops +* splice_pending, then looks for a sleeper +*/ +smp_mb (); +sk_wait_event (sk, timeo, !atomic_read (&conn->splice_pending), &wait); +remove_wait_queue (sk_sleep (sk), &wait); +sk_clear_bit (SOCKWQ_ASYNC_WAITDATA , sk); +} +static int smc_rx_recv_urg (struct smc_sock *smc,struct msghdr *msg,int len,int flags) {
@@ -443,7 +464,23 @@ int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,/* could be just 1 byte, even after waiting on data above */ readable =smc_rx_data_available (conn, peeked_bytes); splbytes =atomic_read (&conn->splice_pending); -if (!readable || (msg && splbytes)) { +if (msg && splbytes) { +/* a pipe holds bytes ahead of these; the copy path +* skips the timeout and signal checks +*/ +if (!read_remaining) +break ; +if (!timeo ||signal_pending (current)) { +if (!read_done) + read_done = timeo ? +sock_intr_errno (timeo) : + -EAGAIN ; +break ; + } +smc_rx_wait_splice (smc, &timeo); +continue ; + } +if (!readable) {if (splbytes) func = smc_rx_data_available_and_no_splice_pend;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/670 net: count last skb of each sk_backlog pass in __release_sock()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ray Zhang <[email protected]>
[ Upstream commit c4e4056b21355356f6a95bcdf03a850edd9f49e7 ]
Running 500 concurrent TCPv6 streams (neper "tcp_stream -6 -T 1 -F 500") on a 2-core Cortex-A53 (CONFIG_PREEMPT_NONE=y, HZ=1000, LATENCY_WARN) triggers resched_latency_warn() in __release_sock():
[ 3655.311821] sched: CPU 0 need_resched set for > 100006892 ns (100 ticks) without schedule [ 3655.311889] Call trace: ... [ 3655.311944] resched_latency_warn+0x7c/0x88 [ 3655.311958] sched_tick+0x1c0/0x418 ... [ 3655.312578] net_rx_action+0x238/0x438 ... [ 3655.312641] do_softirq+0x4c/0x90 [ 3655.312651] __local_bh_enable_ip+0x84/0x90 [ 3655.312663] local_bh_enable+0x1c/0x28 [ 3655.312674] __dev_queue_xmit+0x4a8/0xb00 ... [ 3655.312782] tcp_v6_do_rcv+0x240/0x5f8 [ 3655.312793] __release_sock+0x9c/0x188 [ 3655.312806] release_sock+0x150/0x168 [ 3655.312817] tcp_sendmsg+0x4c/0x70
__release_sock() can loop past 100 ms without calling cond_resched():
- Each outer-loop pass drains sk_backlog, but "if (!skb) break;" runs before "++nb", so a pass of B skbs only adds B - 1 to nb (0 for 1 skb).
- With 500 TCPv6 streams and NAPI sharing two Cortex-A53 cores, runnable tasks keep TIF_NEED_RESCHED set on CPU 0.
- During spin_unlock_bh() and TX softirqs (__dev_queue_xmit() -> local_bh_enable()), tcp_add_backlog() coalesces arriving pure ACKs into a single tail skb.
- Repeated 1-skb passes never advance nb or call cond_resched(), triggering resched_latency_warn() after 100 ticks.
Restore the do-while loop and drop "if (!skb) break;" so every skb increments nb across passes and calls cond_resched() every 16 skbs.
Reproduced the issue and verified the fix on two 2-core Cortex-A53 hosts (CONFIG_PREEMPT_NONE=y, HZ=1000, LATENCY_WARN, latency_warn_once=0) with a userspace reproducer over /dev/net/tun:
- CPU 0 runs a TCPv6 sender and a second runnable task while CPU 1 writes pure ACKs to /dev/net/tun (~30k TCPBacklogCoalesce/run), sustaining 1-skb sk_backlog refills in __release_sock() for ~400 ms (ftrace).
- Before: CPU 0 stayed unscheduled in __release_sock(), hitting resched_latency_warn() 293 and 275 times on the two hosts (> 100.9 ms).
- After: cond_resched() yielded CPU 0 inside __release_sock(), with 0 resched_latency_warn() hits on both hosts.
- Also observed no regression with the workload from
commit 16c610162d1f ("net: call cond_resched() less often in __release_sock()"), "super_netperf 4 -H srv -T,10 -l 3000 &".
--- net/core/sock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/sock.c +2 -4
@@ -3131,7 +3131,7 @@ void __release_sock(struct sock *sk)spin_unlock_bh (&sk->sk_lock.slock); -while (1 ) { + do { next = skb->next; prefetch(next); DEBUG_NET_WARN_ON_ONCE(skb_dst_is_noref(skb));
@@ -3139,12 +3139,10 @@ void __release_sock(struct sock *sk)sk_backlog_rcv (sk, skb); skb = next; -if (!skb) -break ;if (!(++nb &15 ))cond_resched (); - } + }while (skb);spin_lock_bh (&sk->sk_lock.slock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/670 net: ethernet: ti: am65-cpsw-nuss: Enable timestamping of unicast PTP packets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 6887a8f98244ba4c0fbe2d2461b9b8f8a300e326 ]
On a BeagleY-AI (J722S), ptp4l as a unicast master (unicast_listen) logs "received DELAY_REQ without timestamp" for each unicast Delay_Req, and its port goes to FAULTY after "timed out while polling for tx timestamp" for the first unicast Sync.
am65_cpsw_nuss_hwtstamp_set() does not set the TS_UNI_EN bit (bit 24) of the port's TS_CTL_LTYPE2 register. According to the TRM (J722S TRM SPRUJB3D, 12.2.1.4.7.13.5.1 Ethernet Port Receive Event and 12.2.1.4.7.13.5.2 Ethernet Port Transmit Event), this bit must be set for the port to timestamp PTP event messages over UDP sent to a unicast address; without it, only messages sent to the PTP multicast addresses selected by the TS_107 and TS_129 to TS_132 bits are timestamped. TI's netcp_ethss driver for the Keystone 2 Ethernet switch, which has the same timestamping registers, always sets TS_UNI_EN.
Set TS_UNI_EN along with the other bits. With this change, ptp4l in the same setup gets timestamps for the unicast Delay_Req and Sync messages.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3 -1
@@ -121,6 +121,7 @@#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_319 BIT(21)#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_320 BIT(22)#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO BIT(23) +#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_UNI_EN BIT(24)/* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */ #define AM65_CPSW_TS_EVENT_MSG_TYPE_BITS (BIT(0) | BIT(1) | BIT(2) | BIT(3))
@@ -1830,7 +1831,8 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev,AM65_CPSW_PN_TS_CTL_LTYPE2_TS_132 |AM65_CPSW_PN_TS_CTL_LTYPE2_TS_319 |AM65_CPSW_PN_TS_CTL_LTYPE2_TS_320 | -AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO ; +AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO | +AM65_CPSW_PN_TS_CTL_LTYPE2_TS_UNI_EN ; ts_ctrl =AM65_CPSW_TS_EVENT_MSG_TYPE_BITS <<AM65_CPSW_PN_TS_CTL_MSG_TYPE_EN_SHIFT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/670 drm/etnaviv: Flush the tile status cache through both the PE and BLT
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Gmeiner <[email protected]>
[ Upstream commit c1a757f8df1363032623fa9b1baaba0dcf34de6d ]
Since commit f232d9ec029c ("drm/etnaviv: fix TS cache flushing on GPUs with BLT engine"), jobs on GPUs with a BLT engine use a BLT command to flush the tile status cache instead of TS_FLUSH_CACHE, which is broken on most of these GPUs.
GC7000 r6008/r6009 and GC8200 r6401 are the other way around:TS_FLUSH_CACHE works, but the BLT command does not flush the cache. The vendor driver handles these GPUs using TS_FLUSH_CACHE, but the etnaviv kernel driver has no way to identify them.
As a result, dirty tile status cache lines survive the end of a job. They are written back by the next cache flush, using the page table of the job issuing it. If that job belongs to another process, the write goes to the wrong address space.
On GC7000 r6009 this causes MMU faults and GPU recoveries blamed on an innocent process. I see around 1100 per run of a multisample depth/stencil test running alongside two other GPU clients.
Emit both flushes at the end of every job on GPUs with a BLT engine. Whichever does not work on a given GPU is a no-op. Since dirty lines are only written back once, this costs one additional state load per job.
--- drivers/gpu/drm/etnaviv/etnaviv_buffer.c | 40 +++++++++++------------- 1 file changed, 18 insertions(+), 22 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_buffer.c +18 -22
@@ -230,6 +230,17 @@ u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id)return buffer->user_size /8 ; } +static void etnaviv_cmd_flush_ts (struct etnaviv_cmdbuf *buffer,bool has_blt) +{ +CMD_LOAD_STATE (buffer,VIVS_TS_FLUSH_CACHE ,VIVS_TS_FLUSH_CACHE_FLUSH ); + +if (has_blt) { +CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x1 ); +CMD_LOAD_STATE (buffer,VIVS_BLT_SET_COMMAND ,0x1 ); +CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); + } +} +void etnaviv_buffer_end (struct etnaviv_gpu *gpu) {struct etnaviv_cmdbuf *buffer = &gpu->buffer;
@@ -253,7 +264,7 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)unsigned int dwords =7 ;if (has_blt) - dwords +=10 ; + dwords +=11 ; link_target =etnaviv_buffer_reserve (gpu, buffer, dwords);
@@ -266,16 +277,8 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); }CMD_LOAD_STATE (buffer,VIVS_GL_FLUSH_CACHE , flush); -if (gpu->exec_state ==ETNA_PIPE_3D ) { -if (has_blt) { -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_SET_COMMAND ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); - }else { -CMD_LOAD_STATE (buffer,VIVS_TS_FLUSH_CACHE , -VIVS_TS_FLUSH_CACHE_FLUSH ); - } - } +if (gpu->exec_state ==ETNA_PIPE_3D ) +etnaviv_cmd_flush_ts (buffer, has_blt);CMD_SEM (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );CMD_STALL (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );if (has_blt) {
@@ -462,12 +465,12 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state, return_dwords =7 ;/* -* When the BLT engine is present we need 6 more dwords in the return +* When the BLT engine is present we need 7 more dwords in the return * target: 3 enable/flush/disable + 4 enable/semaphore stall/disable, -* but we don't need the normal TS flush state. +* on top of the normal TS flush state. */ if (has_blt) - return_dwords +=6 ; + return_dwords +=7 ; return_target =etnaviv_buffer_reserve (gpu, buffer, return_dwords);CMD_LINK (cmdbuf, return_dwords, return_target);
@@ -484,14 +487,7 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,VIVS_GL_FLUSH_CACHE_DEPTH |VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_SHADER_L1); -if (has_blt) { -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_SET_COMMAND ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); - }else { -CMD_LOAD_STATE (buffer,VIVS_TS_FLUSH_CACHE , -VIVS_TS_FLUSH_CACHE_FLUSH ); - } +etnaviv_cmd_flush_ts (buffer, has_blt); }CMD_SEM (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );CMD_STALL (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/670 mptcp: pm: kernel: use RCU to free endpoint listeners
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 49b09ae0bf57b4230187d4cdd0a370558e44a6e8 ]
mptcp_pm_nl_create_listen_socket() starts the TCP listener directly instead of going through mptcp_listen(). It consequently misses setting SOCK_RCU_FREE on the parent MPTCP socket.
tcp_child_process() can invoke the listener's subflow_data_ready() callback without holding the MPTCP parent lock or a reference to the parent. An authenticated MP_JOIN racing with endpoint teardown can therefore access the parent after its last reference has been dropped. The ADD_ADDR error path can also close an already published listener.
Set SOCK_RCU_FREE before __inet_listen_sk() publishes the TCP listener, matching mptcp_listen(). This protects the parent on every subsequent close path, including a failed endpoint addition.
--- net/mptcp/pm_kernel.c | 1 + 1 file changed, 1 insertion(+)
net/mptcp/pm_kernel.c +1 -0
@@ -1270,6 +1270,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,* old status is known (TCP_CLOSE). */ inet_sk_state_store (newsk,TCP_LISTEN ); +sock_set_flag (newsk,SOCK_RCU_FREE );lock_sock (ssk);WRITE_ONCE (mptcp_subflow_ctx (ssk)->pm_listener, true); err =__inet_listen_sk (ssk, backlog);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/670 udf: dont let the extent type hide an exhausted free-space table extent
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit da582d84fcf5f2f0c1d7760e1a899ca7cedb80fc ]
udf_table_new_block() takes the first block of the free-space table extent closest to the goal. It keeps that extent's type and length together in goal_elen, subtracts one block, and deletes the extent only if goal_elen then reaches zero. UDF 2.60 section 2.3.7.1 requires the free-space extents of an Unallocated Space Entry to be of type 1 (allocated but not recorded), and mkudffs writes them that way. For such an extent the type bits keep goal_elen non-zero, so taking its last block leaves a type-1 extent of length zero behind, starting at the block after the extent, which is in use.
The next allocation that picks this empty extent returns that in-use block. Subtracting a block from 0x40000000 then borrows from the type bits, and the extent becomes type 0 with a length of 2^30 - blocksize:
about a gigabyte of "free" space overlapping live metadata, the other table extents and whatever lies behind the partition. From then on blocks are handed out twice, or past the end of the partition.
Extents that udf_table_free_blocks() adds are type 0, where the check works, so only tables written by mkudffs or by another implementation are affected. Nothing more than filling such a filesystem is needed:
on a fresh 1 MiB "mkudffs --space=unalloctable" image, creating empty files until the partition is full writes file entries over the reserve volume descriptor sequence and the backup anchor, and df then reports a negative amount of used space.
On syzbot's images the same double allocation is what the two reports below trip over. In the first, ftruncate() extends a new file with enough hole extents to need a chain of allocation extent descriptors; one AED is placed on another inode's file entry, and a later one is placed on the block of the AED currently being filled, which udf_setup_indirect_aext() zeroes, so __udf_add_aext() finds lengthAllocDescs out of step with its cursor. In the second, an AED is placed past the end of the device, sb_getblk() fails, and the error path of udf_do_extend_file() calls udf_truncate_extents() on an extent list that no longer covers i_size.
Keep the type separately from the length, as udf_table_prealloc_blocks() already does.
--- fs/udf/balloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/udf/balloc.c +5 -3
@@ -572,7 +572,7 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb,uint32_t elen, goal_elen =0 ;struct kernel_lb_addr eloc, goal_eloc;struct extent_position epos, goal_epos; -int8_t etype; +int8_t etype, goal_etype =0 ;struct udf_inode_info *iinfo =UDF_I (table);int ret =0 ;
@@ -623,7 +623,8 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, goal_epos.block = epos.block; goal_epos.offset = epos.offset - adsize; goal_eloc = eloc; - goal_elen = (etype <<30 ) | elen; + goal_elen = elen; + goal_etype = etype; } }
@@ -647,7 +648,8 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, goal_elen -= sb->s_blocksize;if (goal_elen) -udf_write_aext (table, &goal_epos, &goal_eloc, goal_elen,1 ); +udf_write_aext (table, &goal_epos, &goal_eloc, + (goal_etype <<30 ) | goal_elen,1 );else udf_delete_aext (table, goal_epos, &freed);brelse (goal_epos.bh);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/670 udf: check the unallocated space table when it is loaded
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit e614c3e35a6699ed691b4d17e1ec4230e34aa3eb ]
udf_table_new_block() hands out the first block of the extent closest to its goal and trusts that the extent covers at least one whole block inside the partition. Nothing checks that. A zero-length extent makes it return the block the extent points at, which need not be free, and the subtraction of one block then underflows the length into the type bits, turning the entry into a bogus continuation. An extent running past the end of the partition makes it return blocks behind the partition.
Such tables are not only found on crafted images: until the previous commit, udf_table_new_block() itself left zero-length extents behind in tables written by mkudffs, and then converted them into extents running past the partition.
Check every extent once when the table is loaded, and refuse read-write access if one is empty, is not a whole number of blocks, or does not lie inside the partition, in the same way as for other allocation information the kernel cannot use. Check first that the table is an Unallocated Space Entry at all: the walk starts at the offset of the allocation descriptors in one, and for a file entry that offset lies before the inode's in-memory copy of the descriptors. Treat a chain of allocation extent descriptors that leads back to itself the same way: the walk would otherwise return the same extents forever, and the mount would never finish. Let a fatal signal interrupt the walk and fail the mount.
Refusing read-write access to an empty extent is deliberate. It shows that an old kernel took the last block but left the entry behind. If consumed again, the entry returns an in-use block and turns into a huge bogus extent. Refusing the table before that
happens avoids this second allocation; the filesystem can still be mounted read-only. The check cannot detect every overlap that may already exist in a damaged table.
This patch should be backported together with the previous one: that patch stops creating new empty extents, and this one rejects existing ones before they are consumed again.
--- fs/udf/super.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-)
fs/udf/super.c +79 -1
@@ -1105,6 +1105,73 @@ static int check_partition_desc(struct super_block *sb,return 0 ; } +/* +* Check the Unallocated Space Table once when it is loaded: the allocator +* hands out blocks from the start of each extent and trusts that every +* extent covers at least one whole block inside the partition. +*/ +static int udf_check_unalloc_table (struct super_block *sb, +struct inode *table,u32 partition_len) +{ +struct extent_position epos = { + .block =UDF_I (table)->i_location, + .offset =sizeof (struct unallocSpaceEntry ), + }; +struct kernel_lb_addr eloc; +uint32_t elen, blocks; +struct kernel_lb_addr seen_block = {}; +uint32_t seen_offset =0 ; +u64 steps =0 , period =1 ; +int8_t etype; +int ret; + +/* The walk below assumes the layout of an Unallocated Space Entry */ +if (!UDF_I (table)->i_use) { +udf_err (sb,"unallocated space table is not an unallocated space entry\n" ); +return -EFSCORRUPTED ; + } + +while ((ret =udf_next_aext (table, &epos, &eloc, &elen, &etype,1 )) >0 ) { + blocks = elen >> sb->s_blocksize_bits; +if (!blocks || (elen & (sb->s_blocksize -1 )) || + eloc.logicalBlockNum >= partition_len || + blocks > partition_len - eloc.logicalBlockNum) { +udf_err (sb,"invalid unallocated space table extent (block %u, length %u)\n" , + eloc.logicalBlockNum, elen); + ret = -EFSCORRUPTED ; +break ; + } +/* +* A chain of allocation extents can lead back to itself, and +* then the walk returns the same extents forever. Remember a +* position at doubling intervals; a walk that comes back to it +* is in a loop. +*/ +if (epos.block.logicalBlockNum == seen_block.logicalBlockNum && + epos.block.partitionReferenceNum == + seen_block.partitionReferenceNum && + epos.offset == seen_offset) { +udf_err (sb,"unallocated space table loops back on itself\n" ); + ret = -EFSCORRUPTED ; +break ; + } +if (++steps == period) { + seen_block = epos.block; + seen_offset = epos.offset; + steps =0 ; + period <<=1 ; + } +if (fatal_signal_pending (current)) { +udf_err (sb,"interrupted while checking the unallocated space table\n" ); + ret = -EINTR ; +break ; + } +cond_resched (); + } +brelse (epos.bh); +return ret; +} +static int udf_fill_partdesc_info (struct super_block *sb,struct partitionDesc *p,int p_index) {
@@ -1165,6 +1232,16 @@ static int udf_fill_partdesc_info(struct super_block *sb, p_index);return PTR_ERR (inode); } + err =udf_check_unalloc_table (sb, inode, map->s_partition_len); +if (err) { +iput (inode); +if (err == -EINTR ) +return err; +if (!sb_rdonly (sb)) +return -EACCES ; +UDF_SET_FLAG (sb,UDF_FLAG_RW_INCOMPAT ); +return 0 ; + } map->s_uspace.s_table = inode; map->s_partition_flags |=UDF_PART_FLAG_UNALLOC_TABLE ; udf_debug("unallocSpaceTable (part %d) @ %lu\n",
@@ -2228,8 +2305,9 @@ static int udf_fill_super(struct super_block *sb, struct fs_context *fc)/* * EACCES is special - we want to propagate to * upper layers that we cannot handle RW mount. +* EINTR means that a fatal signal is pending. */ -if (ret == -EACCES ) +if (ret == -EACCES || ret == -EINTR )break ; }else break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/670 udf: fix preallocation discarding before an empty allocation extent
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 0c52750caaaccee8b0e929450fe6538ec4985722 ]
udf_discard_prealloc() finds the last extent of a file by peeking at the next one with udf_next_aext() and stopping when that returns 0. The peek reads into eloc and elen, and the code then uses them as the last extent. But when udf_next_aext() returns 0 they hold no defined
value: if the extent list ends in a continuation descriptor that leads to an empty allocation extent, they describe that continuation, i.e. the block of the empty allocation extent, one block long.
The kernel creates such lists itself: when udf_delete_aext() removes the only descriptor of the last allocation extent in a list, it leaves that allocation extent empty and the continuation to it in place.
If the last extent is a preallocation, udf_discard_prealloc() deletes it with udf_delete_aext(), which finds the following allocation extent empty, so it also removes the continuation and frees that allocation extent's block. udf_discard_prealloc() then frees eloc and elen: that block a second time, instead of the preallocated blocks. On a space bitmap the preallocated blocks leak and the free block count drifts. On an unallocated space table the second free adds a second free extent for the same block, which is later handed out twice: fsx as run by generic/091 and generic/263 ends up with two parts of its test file in one block and reads back bad data.
Peek into separate variables, so that eloc and elen keep the last extent that udf_next_aext() returned with 1.
--- fs/udf/truncate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/udf/truncate.c +4 -3
@@ -124,8 +124,8 @@ void udf_discard_prealloc(struct inode *inode) {struct extent_position epos = {};struct extent_position prev_epos = {}; -struct kernel_lb_addr eloc; -uint32_t elen; +struct kernel_lb_addr eloc, tmpeloc; +uint32_t elen, tmpelen;uint64_t lbcount =0 ;int8_t etype =-1 ;struct udf_inode_info *iinfo =UDF_I (inode);
@@ -141,7 +141,8 @@ void udf_discard_prealloc(struct inode *inode)/* Find the last extent in the file */ while (1 ) { - ret =udf_next_aext (inode, &epos, &eloc, &elen, &tmpetype,0 ); + ret =udf_next_aext (inode, &epos, &tmpeloc, &tmpelen, + &tmpetype,0 );if (ret <0 ) goto out;if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/670 udf: dont use eloc after the end of the unallocated space table
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 94401199df90e1c2a50c6e4b73618ac5a4ba83ba ]
When udf_next_aext() returns 0, its eloc, elen and etype outputs hold no defined value. Two walks of the unallocated space table still use eloc after the walk has reached the end of the table.
udf_table_prealloc_blocks() looks for a free extent starting at first_block and decides whether it found one by comparing eloc with first_block after the walk. If the table's list ends in a continuation descriptor that leads to an empty allocation extent, eloc is then the block of that allocation extent, which is in use, and if that is first_block, the block is handed out as preallocation. Once udf_discard_prealloc() no longer frees the wrong block, this is what still makes fsx in generic/091 and generic/263 read back bad data on a table, in about one run in four. Only take the extent if the walk stopped at it.
When udf_table_free_blocks() cannot merge the freed blocks into an existing extent, it appends a new one and sets only its block number, so the partition reference comes from whatever eloc held after the walk, and with long allocation descriptors it is written to disk. For a table without extents, eloc was never set. Take the partition reference from the freed blocks instead. Short allocation descriptors do not store the partition reference, which is why this half remains a latent long-descriptor fix rather than a reproduced failure.
--- fs/udf/balloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/udf/balloc.c +2 -1
@@ -457,6 +457,7 @@ static void udf_table_free_blocks(struct super_block *sb,int adsize; + eloc.partitionReferenceNum = bloc->partitionReferenceNum; eloc.logicalBlockNum = start; elen =EXT_RECORDED_ALLOCATED | (count << sb->s_blocksize_bits);
@@ -532,7 +533,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb, eloc.logicalBlockNum, elen, first_block); } -if (first_block == eloc.logicalBlockNum) { +if (ret >0 && first_block == eloc.logicalBlockNum) { epos.offset -= adsize; alloc_count = (elen >> sb->s_blocksize_bits);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/670 MIPS: mm: Fix the cache error vector jump for XKPHYS kernels
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit 30b76362f80d39d80f1197c88b284d9fa7952356 ]
except_vec2_generic jumps to cache_parity_error with a j, which cannot leave the vector's 256MB region. An XKPHYS kernel such as IP30's, linked at 512MB, is outside it, so the j targets an unbacked address and its speculative fetch raises bus errors on unrelated fetches. Jump to the handler's uncached XKPHYS address instead.
--- arch/mips/mm/cex-gen.S | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/mips/mm/cex-gen.S +16 -0
@@ -8,6 +8,7 @@ * * Cache error handler */ +#include <asm/addrspace.h> #include <asm/asm.h> #include <asm/regdef.h> #include <asm/mipsregs.h>
@@ -37,6 +38,21 @@ nop nop +#if defined(CONFIG_64BIT) && VMLINUX_LOAD_ADDRESS >= XKPHYS && \ + VMLINUX_LOAD_ADDRESS < XKSEG + /* + * An XKPHYS kernel may lie outside the 256MB region a j from the + * vector reaches, so jump to the handler's uncached XKPHYS address. + */ + PTR_LA k0, cache_parity_error + PTR_LI k1, TO_PHYS_MASK + and k0, k0, k1 + PTR_LI k1, UNCAC_BASE + or k0, k0, k1 + jr k0 + nop +#else j cache_parity_error nop +#endif END(except_vec2_generic)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/670 MIPS: sgi-ip32: Mask MACE PCI interrupts in CRIME only
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit 4e65c502b8975e7c3c3d84aba59cd04af1dd6b8a ]
Masking PCI interrupts in the MACE PCI control register overwrites the error and arbitration enables set at init, and a read-modify-write can hang CRIME 1.1 machines under DMA load. Enable the slot interrupts once and mask them in CRIME.
--- arch/mips/pci/pci-ip32.c | 7 ++++-- arch/mips/sgi-ip32/ip32-irq.c | 45 +++-------------------------------- 2 files changed, 8 insertions(+), 44 deletions(-)
arch/mips/pci/pci-ip32.c +5 -2
@@ -125,10 +125,13 @@ static int __init mace_init(void) {PCIBIOS_MIN_IO =0x1000 ; -/* Clear any outstanding errors and enable interrupts */ +/* +* Clear any outstanding errors and enable interrupts. PCI interrupts +* are masked in CRIME, so the per-slot enables stay on. +*/ mace->pci.error_addr =0 ; mace->pci.error =0 ; - mace->pci.control =0xff008500 ; + mace->pci.control =0xff0085ff ;printk ("MACE PCI rev %d\n" , mace->pci.rev);
arch/mips/sgi-ip32/ip32-irq.c +3 -42
69 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/670 MIPS: sgi-ip32: Leave MACE PCI control alone in config accesses
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit a55a7df2cf788234850d9053ecc25a5470175929 ]
mace_pci_read_config() clears the master abort interrupt enable in the MACE PCI control register around each config read. A register read followed by two register writes can hang CRIME 1.1 under DMA load.
Ack master aborts in the error register instead, and follow every write with a read so back-to-back accesses cannot form that sequence.
--- arch/mips/pci/ops-mace.c | 26 +++++++++++++++++++------- arch/mips/pci/pci-ip32.c | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
arch/mips/pci/ops-mace.c +19 -7
@@ -35,15 +35,27 @@ static inline int mkaddr(struct pci_bus *bus, unsigned int devfn, (reg &0xfc ); } +/* +* On CRIME 1.1, a MACE PCI register read followed by two register writes +* can hang the machine under DMA load, so every register write in this +* file is followed by a read. Config cycles to empty slots end in a +* master abort; ack it with interrupts still off so the bridge error +* interrupt does not report it. +*/ +static void mace_pci_ack_abort (void ) +{ +u32 error = mace->pci.error; + +if (error &MACEPCI_ERROR_MASTER_ABORT ) { + mace->pci.error = error & ~MACEPCI_ERROR_MASTER_ABORT ; + mace->pci.error; + } +}static int mace_pci_read_config (struct pci_bus *bus,unsigned int devfn,int reg,int size,u32 *val) { -u32 control = mace->pci.control; - -/* disable master aborts interrupts during config read */ - mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT ; mace->pci.config_addr =mkaddr (bus, devfn, reg);switch (size) {case 1 :
@@ -56,9 +68,7 @@ mace_pci_read_config(struct pci_bus *bus, unsigned int devfn, *val = mace->pci.config_data.l;break ; } -/* ack possible master abort */ - mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT ; - mace->pci.control = control; +mace_pci_ack_abort ();/* * someone forgot to set the ultra bit for the onboard * scsi chips; we fake it here
@@ -77,6 +87,7 @@ mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 val) { mace->pci.config_addr = mkaddr(bus, devfn, reg); + mace->pci.error;switch (size) {case 1 : mace->pci.config_data.b[(reg &3 ) ^3 ] = val;
@@ -88,6 +99,7 @@ mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, mace->pci.config_data.l = val;break ; } +mace_pci_ack_abort ();DPRINTK ("write%d: reg=%08x,val=%02x\n" , size *8 , reg, val);
arch/mips/pci/pci-ip32.c +2 -0
@@ -77,6 +77,8 @@ static irqreturn_t macepci_error(int irq, void *dev) } mace->pci.error = flags; +/* follow the write with a read, see mace_pci_ack_abort() */ + mace->pci.error;return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/670 srcu: Add list_splice_init_srcu()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit d06917d0ba226206dbd606330d73a8eb1e3029c1 ]
list_splice_init_rcu() makes a list look empty to new readers, waits for the current ones with the given sync function, and only then links the entries into the new list. The sync function takes no argument, so it can wait for RCU readers but not for the readers of an srcu_struct.
Passing synchronize_rcu() for a list read under SRCU still builds, but leaves SRCU readers on the entries while the last one's next pointer is moved onto the new list head. nvme_remove_namespaces() does this today.
Add list_splice_init_srcu(), which waits for the readers of the given srcu_struct instead.
--- include/linux/srcu.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
include/linux/srcu.h +36 -0
@@ -18,6 +18,7 @@#include <linux/mutex.h> #include <linux/rcupdate.h> +#include <linux/rculist.h> #include <linux/workqueue.h> #include <linux/rcu_segcblist.h>
@@ -58,6 +59,41 @@ int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp); void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp);void synchronize_srcu (struct srcu_struct *ssp); +/** +* list_splice_init_srcu - splice an SRCU-protected list into an existing list +* @list: the SRCU-protected list to splice +* @head: the place in the existing list to splice the first list into +* @ssp: the srcu_struct that readers of @list use +* +* Like list_splice_init_rcu(), but wait for the SRCU readers of @list +* instead of RCU ones, so that none of them can follow a next pointer +* onto @head. +* +* Note that this function blocks, and that the caller must prevent any +* other updates to @list. +*/ +static inline void list_splice_init_srcu (struct list_head *list, +struct list_head *head, +struct srcu_struct *ssp) +{ +struct list_head *first = list->next; +struct list_head *last = list->prev; +struct list_head *next = head->next; + +if (list_empty (list)) +return ; + +INIT_LIST_HEAD_RCU (list); +synchronize_srcu (ssp); +ASSERT_EXCLUSIVE_ACCESS (*first); +ASSERT_EXCLUSIVE_ACCESS (*last); + + last->next = next; +rcu_assign_pointer (list_next_rcu (head), first); + first->prev = head; + next->prev = last; +} +#define SRCU_GET_STATE_COMPLETED 0x1/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/670 nvme: wait for SRCU readers before splicing the namespace list
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 8a0449832b50cd4f99f2d2952cfc1476e5f26d0f ]
Readers walk ctrl->namespaces under ctrl->srcu, and some of them sleep there, e.g. nvme_wait_freeze() waiting for I/O to drain.
nvme_remove_namespaces() moves the list onto its on-stack ns_list with list_splice_init_rcu(), which only waits for RCU readers before relinking the entries. A reader still on the last namespace then follows its next pointer to ns_list instead of ctrl->namespaces and treats the stack as a namespace. Deleting a controller while a Format NVM passthrough waits for a delayed read on the last namespace gives:
BUG: KASAN: stack-out-of-bounds in nvme_wait_freeze+0x102/0x120 Read of size 8 at addr ff110001d2f3fc38 by task nvme/4413 Call Trace: nvme_wait_freeze nvme_passthru_start nvme_submit_user_cmd nvme_user_cmd nvme_dev_ioctl BUG: unable to handle page fault for address: ffffffff8af04850
Use list_splice_init_srcu() instead, which waits for the SRCU readers. This also takes the RCU grace period out of every controller deletion. Deleting 64 tcp controllers with one namespace each, median of 3 runs on each of two boots per kernel:
before after nvme disconnect-all (ms) 3491 / 3509 2996 / 3165 nvme_remove_namespaces() avg (ms) 39.0 / 40.5 31.9 / 34.7
--- drivers/nvme/host/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvme/host/core.c +1 -2
@@ -4375,9 +4375,8 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl)nvme_change_ctrl_state (ctrl,NVME_CTRL_DELETING_NOIO );mutex_lock (&ctrl->namespaces_lock); -list_splice_init_rcu (&ctrl->namespaces, &ns_list, synchronize_rcu); +list_splice_init_srcu (&ctrl->namespaces, &ns_list, &ctrl->srcu);mutex_unlock (&ctrl->namespaces_lock); -synchronize_srcu (&ctrl->srcu);list_for_each_entry_safe (ns, next, &ns_list, list)nvme_ns_remove (ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/670 nvmet: bound the traddr and trsvcid configfs writes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shao Mingyin <[email protected]>
[ Upstream commit cf399d4abbeddc317f8160a79fefb4016c469862 ]
nvmet_addr_traddr_store() and nvmet_addr_trsvcid_store() reject a write only when count is larger than NVMF_TRADDR_SIZE (256) respectively NVMF_TRSVCID_SIZE (32). A write of exactly that many characters is accepted, and the following
sscanf(page, "%s\n", port->disc_addr.traddr)
has no field width. configfs terminates the buffer at page[count], so the scan writes 256 characters plus the trailing NUL, i.e. 257 bytes, into traddr[256]. The extra byte lands in the following tsas field of the discovery log entry, silently clearing the first TSAS byte (the RDMA queue type, or the TLS section type for TCP). trsvcid has the same off-by-one with a 32-byte write; there the extra byte lands in the reserved bytes that follow trsvcid.
Limit the scans to one byte less than the destination arrays. The count checks can stay as they are so that a normal newline-terminated write is still accepted.
--- drivers/nvme/target/configfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/configfs.c +2 -2
@@ -148,7 +148,7 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item,if (nvmet_is_port_enabled (port, __func__))return -EACCES ; -if (sscanf (page,"%s\n" , port->disc_addr.traddr) !=1 ) +if (sscanf (page,"%255s" , port->disc_addr.traddr) !=1 )return -EINVAL ;return count; }
@@ -240,7 +240,7 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item,if (nvmet_is_port_enabled (port, __func__))return -EACCES ; -if (sscanf (page,"%s\n" , port->disc_addr.trsvcid) !=1 ) +if (sscanf (page,"%31s" , port->disc_addr.trsvcid) !=1 )return -EINVAL ;return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/670 perf/core: Dont send SIGTRAP after exec removed the event
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit 6f083fbccd5f06889bc08e1182bd02c0383b9121 ]
A sigtrap event must also set remove_on_exec, so that its SIGTRAP never reaches a program after exec. But the signal is sent from task work, which only runs on the way back to user space. If the event overflows shortly before execve(), the task work can still be pending when the task enters execve(), and then runs when execve() returns. By then perf_event_exec() has removed the event and the new program has default signal handlers, so the SIGTRAP kills it.
The exec_stress test in the remove_on_exec selftest catches this and fails about half the time in a VM. A process that opens a sigtrap event on itself and then calls execve() is killed by SIGTRAP in 15% to 50% of runs, both on an AMD machine running v7.2 and in a VM, with or without close-on-exec on the event fd.
Commit ffb684f2aa14 ("perf: Fix race between perf_event_exit_task() and perf_pending_task()") made perf_sigtrap() return once perf_event_exit_task() has set ctx->task to TASK_TOMBSTONE. Exec only calls perf_event_exit_task() when the new program is not dumpable, such as a setuid one. An ordinary exec keeps the context and only removes the remove_on_exec events, so the SIGTRAP is still sent.
perf_event_exit_event() sets PERF_EVENT_STATE_EXIT when exec removes the event. If the event fd is close-on-exec and was the last reference to the file, exec also queues the file release as task work. Task work runs newest first, so perf_release() runs before the SIGTRAP work and moves the event on to PERF_EVENT_STATE_DEAD. So don't send the signal when the event state is PERF_EVENT_STATE_EXIT or lower, which means the event has been removed. That also covers PERF_EVENT_STATE_REVOKED, where the PMU is gone.
--- kernel/events/core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
kernel/events/core.c +9 -0
@@ -6916,6 +6916,15 @@ static void perf_sigtrap(struct perf_event *event)if (event->ctx->task ==TASK_TOMBSTONE )return ; +/* +* The event was removed after this signal was queued, e.g. by exec() +* (remove_on_exec), which may also have closed its fd (close-on-exec). +* The new program has default signal handlers, so a SIGTRAP would +* kill it. +*/ +if (READ_ONCE (event->state) <=PERF_EVENT_STATE_EXIT ) +return ; +/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/670 x86/nmi: Ignore negative NMI handler durations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit ade63af6cfb7b3ca19ced28730fd6461e8d1d410 ]
I am seeing NMI handlers in the Meta fleet reported as running for about 584 years. Over 30 days, 11 AMD and Intel machines logged 637 such lines, for example:
AMD EPYC 9D25 (family 0x1a, model 0x11, stepping 0x0):
[ 1650.616627] INFO: NMI handler (nmi_cpu_backtrace_handler.llvm.9643156322683129580) took too long to run: 18446744073709.551 msecs
Intel Xeon Platinum 8321HC (family 0x6, model 0x55, stepping 0xb):
[360448.230129] INFO: NMI handler (perf_event_nmi_handler) took too long to run: 18446744071018.936 msecs
Intel Xeon D-2191A (family 0x6, model 0x55, stepping 0x4):
[81787.188959] INFO: NMI handler (ghes_notify_nmi) took too long to run: 18446744073709.545 msecs
nmi_handle() times each handler with two sched_clock() reads. When the second read is lower than the first, the u64 subtraction wraps, and nmi_check_duration() treats the result as a duration. In the three examples, the clock went back by less than 1 us, by 2.7 s and by about 6 us.
The wrapped value is also stored in action->max_duration. Every later real duration is smaller, so the handler is never reported again until the next boot.
Whatever makes the clock read lower, a negative difference is not a duration, so return before it is stored or reported. A clock that steps forward is not covered, since that cannot be told from a real stall.
A backwards clock is still worth knowing about, so print the size of the step once per boot. This uses pr_warn_once() rather than WARN, as a stack trace says nothing about the clock and panic_on_warn machines should not go down for it.
--- arch/x86/kernel/nmi.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/kernel/nmi.c +8 -0
@@ -120,6 +120,14 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration) {int remainder_ns, decimal_msecs; +/* sched_clock() went backwards? */ +if ((s64 )duration <0 ) { +pr_warn_once ("NMI handler (%ps): sched_clock() went backwards by %lld ns on CPU%d\n" , + action->handler, -(s64 )duration, +smp_processor_id ()); +return ; + } +if (duration < nmi_longest_ns || duration < action->max_duration)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/670 iommu/amd: Skip non-IVMD entries when parsing IVRS memory definitions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akshay Jindal <[email protected]>
[ Upstream commit e62df37e0eff4d670e78bbd415be2c1675883c15 ]
init_memory_definitions() walks every top-level subtable including the IVHD blocks (type 0x10/0x11/0x40) in the IVRS ACPI table. It interprets each one as a 'struct ivmd_header', solely on m->flags, without first checking that the subtable's type actually is one of the IVMD types (ACPI_IVMD_TYPE, ACPI_IVMD_TYPE_ALL, ACPI_IVMD_TYPE_RANGE).
if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE))
init_unity_map_range(m, table);IVMD_FLAG_UNITY_MAP (0x01) occupies the same bit position as the IVHD flags field's HtTunEn bit. Unlike real hardware, QEMU's AMD IOMMU emulation sets HtTunEn unconditionally (flags=0xD1 for type 0x10, 0x11 for type 0x11), so every QEMU-emitted IVHD block is misidentified as a unity-map/exclusion-range IVMD entry, which subsequently results in the creation of a bogus pci segment. Eg:
AMD-Vi: PCI segment : 0x4000, last bdf : 0x0000
Fix by checking the subtable's type before treating it as IVMD.
--- drivers/iommu/amd/init.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/amd/init.c +12 -2
@@ -2570,6 +2570,15 @@ static int __init init_unity_map_range(struct ivmd_header *m,return 0 ; } +static bool ivrs_block_type_ivmd (u8 type) +{ +if (type ==ACPI_IVMD_TYPE || + type ==ACPI_IVMD_TYPE_ALL || + type ==ACPI_IVMD_TYPE_RANGE ) +return true; +return false; +} +/* iterates over all memory definitions we find in the ACPI table */ static int __init init_memory_definitions (struct acpi_table_header *table) {
@@ -2581,10 +2590,11 @@ static int __init init_memory_definitions(struct acpi_table_header *table)while (p < end) { m = (struct ivmd_header *)p; + p += m->length; +if (!ivrs_block_type_ivmd (m->type)) +continue ;if (m->flags & (IVMD_FLAG_UNITY_MAP |IVMD_FLAG_EXCL_RANGE ))init_unity_map_range (m, table); - - p += m->length; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/670 arm64: kexec_file: Fix elf_headers memory leak in retry loop
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
[ Upstream commit ac302aea3d824ccc99f29b8e499c365cb9a684a9 ]
A retry allocates new elf headers and overwrites image->elf_headers, leaking the previous buffer.
Free it before assigning.
--- arch/arm64/kernel/machine_kexec_file.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kernel/machine_kexec_file.c +2 -0
@@ -128,6 +128,8 @@ int load_other_segments(struct kimage *image,vfree (headers); goto out_err; } + +vfree (image->elf_headers); image->elf_headers = headers; image->elf_load_addr = kbuf.mem; image->elf_headers_sz = headers_sz;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/670 x86/boot: Fix off-by-one error in sme_clear_pgd()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit cb319926808b1cca522d2087a13205e840beb45b ]
The mapping helpers __sme_map_range_pmd() and __sme_map_range_pte(), and therefore sme_encrypt_kernel(), use exclusive end addresses and stop before vaddr reaches vaddr_end.
However, sme_clear_pgd() treats vaddr_end as inclusive when calculating the last PGD entry to clear. If vaddr_end is PGD-aligned, the first PGD entry outside the range is cleared too.
Use vaddr_end - 1 to calculate the last PGD entry within the range.
--- arch/x86/mm/mem_encrypt_identity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/mem_encrypt_identity.c +1 -1
@@ -101,7 +101,7 @@ static void __head sme_clear_pgd(struct sme_populate_pgd_data *ppd)pgd_t *pgd_p; pgd_start = ppd->vaddr &PGDIR_MASK ; - pgd_end = ppd->vaddr_end &PGDIR_MASK ; + pgd_end = (ppd->vaddr_end -1 ) &PGDIR_MASK ; pgd_size = (((pgd_end - pgd_start) /PGDIR_SIZE ) +1 ) *sizeof (pgd_t);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/670 ata: libata-pmp: disable the SEMB port on Marvell 88SM9705
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Ziliani <[email protected]>
[ Upstream commit 6b67cdb463b006e57f15e3fe4ea03b00f0ac9ee5 ]
The Marvell 88SM9705 is a 1-to-5 SATA port multiplier with one additional SEMB (SATA Enclosure Management Bridge) port [1]. Ports 0-4 are device ports and port 5 is the SEMB. The number of fan-out ports in GSCR[2] is 6 when the SEMB is enabled and 5 when it is not, so on boards without the SEMB there is no link 5 and this quirk does nothing. That includes the common 8-port PCIe cards that pair an 88SE9215 with an 88SM9705, which report 5 ports.
The SEMB port never answers SRST. libata probes it like a device port, and every EH round on the PMP ends in a retry loop that lasts about a minute before EH gives up, then starts over:
ata19.15: Port Multiplier 1.2, 0x1b4b:0x9705 r160, 6 ports, feat 0x1/0x1f ata19.05: hard resetting link
ata19.05: failed to resume link (SControl 0)
ata19.05: softreset failed (1st FIS failed)
ata19.05: hard resetting link
...
ata20.05: reset failed, giving up
Disk discovery waits for this, including disks on other controllers.
libata.force only partly works around it. The "disable" horkage only takes effect after IDENTIFY, which the SEMB link never reaches. "norst" on port 5 stops the retry loop, but the disks still come up about a minute later than with this change (see below).
Treat port 5 the same way as port 4 of the Marvell 88SM4140 and mark the link ATA_LFLAG_DISABLED.
Tested on a Synology DX1222 expansion unit (four 88SM9705 r160 behind a Marvell 88SE9235, passed through to a KVM guest, 6 disks), 7.4-rc1 with and without this change, one boot each:
softreset reset failed, last disk
failed giving up attached
7.4-rc1, no libata.force 60 12 197 s
7.4-rc1, libata.force=N.05:norst 0 0 70 s
7.4-rc1 + this patch, no force 0 0 11 sThe problem was first found on a Synology DX1215 with the same chain, where this change brought the disks up after about 20 s instead of about 200 s, including a disk on a separate AHCI controller.
Each PMP still logs one "failed to resume link (SControl 0)" for port 5 at probe time.
--- drivers/ata/libata-pmp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/ata/libata-pmp.c +14 -0
@@ -482,6 +482,20 @@ static void sata_pmp_quirks(struct ata_port *ap)if (link->pmp ==4 ) link->flags |=ATA_LFLAG_DISABLED ; } + }else if (vendor ==0x1b4b && devid ==0x9705 ) { +/* +* Marvell 88SM9705 quirks +* +* 1-to-5 PMP with an extra SEMB port. It reports 6 ports and +* port 5 is the SEMB, which never answers SRST: EH spends about +* a minute per round retrying it, and disk discovery waits for +* that. Seen behind a Marvell 88SE9235 in the Synology DX1215 +* and DX1222. +*/ +ata_for_each_link (link, ap,EDGE ) { +if (link->pmp ==5 ) + link->flags |=ATA_LFLAG_DISABLED ; + } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/670 can: replace ARPHRD_CAN type checks with can_get_ml_priv()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 962947b69589881167054bae5accc8abfd5aa4b6 upstream.
Commit 4e096a18867a ("net: introduce CAN specific pointer in the struct net_device") introduced an explicit way to assign the midlayer private pointer (dev->ml_priv) to named users like ML_PRIV_CAN. A valid pointer returned by can_get_ml_priv() therefore identifies a real CAN device.
The referenced commit only converted the j1939 and proc code to this check, while the other parts of the CAN subsystem still rely on dev->type == ARPHRD_CAN.
The TUNSETLINK ioctl allows a down TUN/TAP device to set its hardware type to ARPHRD_CAN while dev->ml_priv remains NULL. Such a repurposed netdevice passes the ARPHRD_CAN checks.
Commit 8aa59e355949 ("can: af_can: fix NULL pointer dereference in can_rx_register()") already made can_rx_register() reject such devices. But can_rx_unregister() still only checks dev->type and dereferences the NULL ml_priv when it walks the receive lists of the device.
CAN_ISOTP reaches this path: isotp_bind() ignores the return values of can_rx_register() and binds the socket anyway. When the socket is released or the device is unregistered, isotp_release() and isotp_notify() remove the filters that have never been registered and trigger the NULL pointer dereference in can_rx_unregister(). This only requires owning a TUN/TAP device or CAP_NET_ADMIN in an unprivileged user namespace.
Convert the remaining ARPHRD_CAN checks in af_can, bcm, gw, isotp and raw to can_get_ml_priv().
[ backport to 6.12: This tree has no can_skb_ext, so only the ARPHRD_CAN
check is removed from the conditions in can_rcv(), canfd_rcv() and canxl_rcv(). Add the <linux/can/can-ml.h> include to raw.c, which upstream got with commit faba5860fcf9 ("can: raw: instantly reject disabled CAN frames"). ]
--- net/can/af_can.c | 12 ++++++------ net/can/bcm.c | 7 ++++--- net/can/gw.c | 7 ++++--- net/can/isotp.c | 5 +++-- net/can/raw.c | 5 +++-- 5 files changed, 20 insertions(+), 16 deletions(-)
net/can/af_can.c +6 -6
@@ -224,7 +224,7 @@ int can_send(struct sk_buff *skb, int loop) goto inval_skb; } -if (unlikely (skb->dev->type !=ARPHRD_CAN )) { +if (unlikely (!can_get_ml_priv (skb->dev))) { err = -EPERM ; goto inval_skb; }
@@ -450,7 +450,7 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id,/* insert new receiver (dev,canid,mask) -> (func,data) */ -if (dev && (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev))) +if (dev && !can_get_ml_priv (dev))return -ENODEV ;if (dev && !net_eq (net,dev_net (dev)))
@@ -517,7 +517,7 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;struct can_dev_rcv_lists *dev_rcv_lists; -if (dev && dev->type !=ARPHRD_CAN ) +if (dev && !can_get_ml_priv (dev))return ;if (dev && !net_eq (net,dev_net (dev)))
@@ -683,7 +683,7 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev)static int can_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) { -if (unlikely (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev) || !can_is_can_skb (skb))) { +if (unlikely (!can_get_ml_priv (dev) || !can_is_can_skb (skb))) {pr_warn_once ("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n" , dev->type, skb->len);
@@ -698,7 +698,7 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,static int canfd_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) { -if (unlikely (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev) || !can_is_canfd_skb (skb))) { +if (unlikely (!can_get_ml_priv (dev) || !can_is_canfd_skb (skb))) {pr_warn_once ("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n" , dev->type, skb->len);
@@ -713,7 +713,7 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,static int canxl_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) { -if (unlikely (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev) || !can_is_canxl_skb (skb))) { +if (unlikely (!can_get_ml_priv (dev) || !can_is_canxl_skb (skb))) {pr_warn_once ("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n" , dev->type, skb->len);
net/can/bcm.c +4 -3
@@ -54,6 +54,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/skb.h> #include <linux/can/bcm.h>
@@ -1710,7 +1711,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) goto out_release; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) {dev_put (dev); ret = -ENODEV ; goto out_release;
@@ -1858,7 +1859,7 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg, {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg !=NETDEV_UNREGISTER && msg !=NETDEV_DOWN )return NOTIFY_DONE ;
@@ -2014,7 +2015,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len, ret = -ENODEV ; goto fail; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) {dev_put (dev); ret = -ENODEV ; goto fail;
net/can/gw.c +4 -3
@@ -52,6 +52,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/skb.h> #include <linux/can/gw.h>
@@ -603,7 +604,7 @@ static int cgw_notifier(struct notifier_block *nb,struct net_device *dev =netdev_notifier_info_to_dev (ptr);struct net *net =dev_net (dev); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg ==NETDEV_UNREGISTER ) {
@@ -1154,7 +1155,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,if (!gwj->src.dev) goto out; -if (gwj->src.dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (gwj->src.dev)) goto out; gwj->dst.dev =__dev_get_by_index (net, gwj->ccgw.dst_idx);
@@ -1162,7 +1163,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,if (!gwj->dst.dev) goto out; -if (gwj->dst.dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (gwj->dst.dev)) goto out;/* is sending the skb back to the incoming interface intended? */
net/can/isotp.c +3 -2
@@ -65,6 +65,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/skb.h> #include <linux/can/isotp.h>
@@ -1591,7 +1592,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) err = -ENODEV ; goto out; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) { err = -ENODEV ; goto out_put_dev; }
@@ -1891,7 +1892,7 @@ static int isotp_notifier(struct notifier_block *nb, unsigned long msg, {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg !=NETDEV_UNREGISTER && msg !=NETDEV_DOWN )return NOTIFY_DONE ;
net/can/raw.c +3 -2
@@ -49,6 +49,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/dev.h> /* for can_is_canxl_dev_mtu() */ #include <linux/can/skb.h>
@@ -341,7 +342,7 @@ static int raw_notifier(struct notifier_block *nb, unsigned long msg, {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg !=NETDEV_UNREGISTER && msg !=NETDEV_DOWN )return NOTIFY_DONE ;
@@ -481,7 +482,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len) err = -ENODEV ; goto out; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) { err = -ENODEV ; goto out_put_dev; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/670 can: protect the receive lists with a per-device lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 0f3ad9ab40e3dad06d5c0693806e07935ceedbc3 upstream.
The receive lists of a CAN device are located in the device's can_ml_priv and travel with the device when it is moved to another network namespace. But they are protected by the per-netns rcvlists_lock. So can_rx_unregister() needs dev_net(dev) to pick the right lock and silently returns when the passed namespace does not match dev_net(dev) anymore.
isotp_release() and bcm_release() leave their notifier list before they take any lock that serializes against the netdev notifier, which runs under RTNL. When the bound device is moved to another namespace in this window, the notifier skips the socket and the release path has to remove the filters itself. isotp_release() passes the socket's namespace, which does not match dev_net(dev) anymore. bcm_rx_unreg() passes dev_net(dev), which can_rx_unregister() reads again for its check, so a namespace change between both reads makes the check fail as well. In both cases can_rx_unregister() silently returns. As can_rx_register() stores rcv->sk without a reference, the remaining receivers point to the freed socket (isotp) or the freed op (bcm):
BUG: KASAN: use-after-free in isotp_rcv+0x1570/0x24d0 Read of size 1 at addr ffff888118130552 by task isotp_ns_uaf/578 can_rcv_filter+0x4af/0x8c0 can_receive+0x28d/0x3c0 can_rcv+0x2a9/0x310 __netif_receive_skb_one_core+0x21a/0x260 process_backlog+0x210/0x760
Besides this, the lists of a device are protected by the rcvlists_lock of the namespace that is passed in. Callers which pass dev_net(dev) read it at different times, so the same lists may be modified under the locks of different namespaces while the device is moved.
Taking RTNL in these release paths is no option: raw_bind(), raw_setsockopt() and raw_release() already hold RTNL while adding and removing up to CAN_RAW_FILTER_MAX filters per socket, which unprivileged users can trigger repeatedly and which makes RTNL a global bottleneck.
Instead fix the root cause and add a spinlock to struct can_dev_rcv_lists, which protects the receive lists of a CAN device or the 'any' CAN device lists of a namespace. It is initialized in can_set_ml_priv(), which is used by all CAN network devices. With this, can_rx_unregister() finds the subscription independently of the current namespace of the device. The protocols keep the device valid with their tracked references. The per-netns rcvlists_lock only protects the receive list statistics anymore, and CAN_RAW, CAN_BCM and CAN_ISOTP pass the namespace that has been used for can_rx_register().
So isotp_release() and bcm_release() now remove their filters correctly without RTNL, and raw_release(), raw_setsockopt(), raw_bind() and isotp_bind() do not need RTNL anymore and add and remove their filters under lock_sock(). To serialize bind() with NETDEV_UNREGISTER, bind() publishes the device inside the RCU section of its lookup, and raw_notify() and isotp_notify() recheck the bound device under lock_sock(). As RTNL does not keep NETDEV_DOWN out of bind() anymore, bind() checks IFF_UP after publishing the bound device, with a barrier pair against raw_notify() and isotp_notify(), so a down transition during bind() is still reported with ENETDOWN.
[ backport to 6.12: Adapt the can_pernet_init() context to kzalloc() as
this tree has no kzalloc_obj(). so->dev holds an untracked reference with dev_hold() in this tree. raw_setsockopt() has no raw_setsockopt_locked() split from commit 1e5185c09058 ("can: raw: add locking for raw flags bitfield") in this tree, so remove the RTNL locking from the CAN_RAW_FILTER and CAN_RAW_ERR_FILTER cases directly. Use sock_net(sk) in raw_release(). ]
--- include/linux/can/can-ml.h | 3 ++ include/net/netns/can.h | 2 +- net/can/af_can.c | 39 +++++++++----- net/can/bcm.c | 43 +++++---------- net/can/isotp.c | 89 +++++++++++++++++++------------ net/can/raw.c | 106 +++++++++++++++++++++++++------------ 6 files changed, 166 insertions(+), 116 deletions(-)
include/linux/can/can-ml.h +3 -0
@@ -45,6 +45,7 @@#include <linux/can.h> #include <linux/list.h> #include <linux/netdevice.h> +#include <linux/spinlock.h> #define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS)#define CAN_EFF_RCV_HASH_BITS 10
@@ -53,6 +54,7 @@enum {RX_ERR ,RX_ALL ,RX_FIL ,RX_INV ,RX_MAX };struct can_dev_rcv_lists { +spinlock_t lock;/* protects the receive lists and entries */ struct hlist_head rx[RX_MAX ];struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ ];struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ ];
@@ -74,6 +76,7 @@ static inline struct can_ml_priv *can_get_ml_priv(struct net_device *dev)static inline void can_set_ml_priv (struct net_device *dev,struct can_ml_priv *ml_priv) { +spin_lock_init (&ml_priv->dev_rcv_lists.lock);netdev_set_ml_priv (dev, ml_priv,ML_PRIV_CAN ); }
include/net/netns/can.h +1 -1
@@ -29,7 +29,7 @@ struct netns_can {/* receive filters subscribed for 'all' CAN devices */ struct can_dev_rcv_lists *rx_alldev_list; -spinlock_t rcvlists_lock; +spinlock_t rcvlists_lock;/* protects the rcv_entries(_max) stats */ struct timer_list stattimer;/* timer for statistics update */ struct can_pkg_stats *pkg_stats;struct can_rcv_lists_stats *rcv_lists_stats;
net/can/af_can.c +25 -14
@@ -460,9 +460,10 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id,if (!rcv)return -ENOMEM ; -spin_lock_bh (&net->can.rcvlists_lock); - dev_rcv_lists =can_dev_rcv_lists_find (net, dev); + +spin_lock_bh (&dev_rcv_lists->lock); + rcv_list =can_rcv_list_find (&can_id, &mask, dev_rcv_lists); rcv->can_id = can_id;
@@ -476,6 +477,9 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id,hlist_add_head_rcu (&rcv->list, rcv_list); dev_rcv_lists->entries++; +spin_unlock_bh (&dev_rcv_lists->lock); + +spin_lock_bh (&net->can.rcvlists_lock); rcv_lists_stats->rcv_entries++; rcv_lists_stats->rcv_entries_max =max (rcv_lists_stats->rcv_entries_max, rcv_lists_stats->rcv_entries);
@@ -507,6 +511,14 @@ static void can_rx_delete_receiver(struct rcu_head *rp)* * Description: * Removes subscription entry depending on given (subscription) values. +* The receive lists of a CAN device are protected by a per-device lock, +* so the subscription is found even when the device has been moved to +* another network namespace after can_rx_register(). The caller has to +* ensure that @dev stays valid, e.g. by holding a reference to @dev or +* RTNL. @net should be the namespace that has been used for +* can_rx_register(). It selects the 'any' CAN device lists for +* @dev == NULL and is otherwise only used for the receive list +* statistics, which become imprecise when another namespace is passed. */ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, canid_t mask, void (*func)(struct sk_buff *, void *),
@@ -520,12 +532,10 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,if (dev && !can_get_ml_priv (dev))return ; -if (dev && !net_eq (net,dev_net (dev))) -return ; + dev_rcv_lists =can_dev_rcv_lists_find (net, dev); -spin_lock_bh (&net->can.rcvlists_lock); +spin_lock_bh (&dev_rcv_lists->lock); - dev_rcv_lists =can_dev_rcv_lists_find (net, dev); rcv_list =can_rcv_list_find (&can_id, &mask, dev_rcv_lists);/* Search the receiver list for the item to delete. This should
@@ -545,26 +555,26 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,* a warning here. */ if (!rcv) { +spin_unlock_bh (&dev_rcv_lists->lock);pr_warn ("can: receive list entry not found for dev %s, id %03X, mask %03X\n" ,DNAME (dev), can_id, mask); - goto out; +return ; }hlist_del_rcu (&rcv->list); dev_rcv_lists->entries--; +spin_unlock_bh (&dev_rcv_lists->lock); + +spin_lock_bh (&net->can.rcvlists_lock);if (rcv_lists_stats->rcv_entries >0 ) rcv_lists_stats->rcv_entries--; - - out:spin_unlock_bh (&net->can.rcvlists_lock);/* schedule the receiver item for deletion */ -if (rcv) { -if (rcv->sk) -sock_hold (rcv->sk); -call_rcu (&rcv->rcu, can_rx_delete_receiver); - } +if (rcv->sk) +sock_hold (rcv->sk); +call_rcu (&rcv->rcu, can_rx_delete_receiver); }EXPORT_SYMBOL (can_rx_unregister);
@@ -795,6 +805,7 @@ static int can_pernet_init(struct net *net)kzalloc (sizeof (*net->can.rx_alldev_list),GFP_KERNEL );if (!net->can.rx_alldev_list) goto out; +spin_lock_init (&net->can.rx_alldev_list->lock); net->can.pkg_stats =kzalloc (sizeof (*net->can.pkg_stats),GFP_KERNEL );if (!net->can.pkg_stats) goto out_free_rx_alldev_list;
net/can/bcm.c +12 -31
75 lines not on this page · raw message
net/can/isotp.c +54 -35
186 lines not on this page · raw message
net/can/raw.c +71 -35
247 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/670 ceph: clamp the inline data length in ceph_fill_inline_data()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanglei Zhu <[email protected]>
[ Upstream commit 9c1d14d3b66b3e1dd96ee664c0dd2548f2b77a52 ]
The MDS decides how much inline data to attach to a reply, and the client parses inline_len without any upper bound: ceph_decode_need() only verifies that the message actually carries that many bytes. ceph_fill_inline_data() then copies the data into a single page with no length check, so a malicious or buggy MDS returning more inline data than the page can hold writes past its end.
Clamp the length to PAGE_SIZE so both callers, handle_cap_grant() and fill_inode(), are covered.
--- fs/ceph/addr.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ceph/addr.c +6 -0
@@ -2173,6 +2173,12 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,doutc (cl,"%p %llx.%llx len %zu locked_page %p\n" , inode,ceph_vinop (inode), len, locked_page); +if (len >PAGE_SIZE ) { +pr_warn_ratelimited_client (cl,"oversized inline data %zu\n" , + len); + len =PAGE_SIZE ; + } +if (len >0 ) {void *kaddr =kmap_atomic (page);memcpy (kaddr, data, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/670 Revert "mm/page_owner: fix memory leak in page_owner_stack_fops->release()"
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hamid Nassiby <[email protected]>
This reverts commit 7fbea59f737eb3a47368ee5253e708cb342faf8b, which is commit a76a5ae2c6c6 upstream.
The upstream change is only correct on top of commit 156c0c5d1463 ("mm/page_owner: introduce struct stack_print_ctx"), which first appeared in v6.19. That commit makes page_owner_stack_open() allocate a struct stack_print_ctx through seq_open_private() and moves the stack_list cursor into it, so ->release() must free it with seq_release_private(). 6.12 does not have that commit: page_owner_stack_open() passes a size of 0 to seq_open_private(), so there is nothing to leak, and stack_start()/stack_next() store the current struct stack node directly in m->private.
The upstream commit was backported because it is tagged for stable and carries a Fixes tag for 765973a09803 ("mm,page_owner: display all stacks and their count"), but the leak it fixes only exists since 156c0c5d1463.
seq_release_private() kfree()s m->private. Closing show_stacks before EOF therefore frees a struct stack node that is still linked in stack_list, and the next reader of show_stacks walks into freed memory. On v6.12.115 (x86_64 QEMU, KASAN, page_owner=on), a single 4 KiB read() and close() followed by a full read gives:
BUG: KASAN: slab-use-after-free in stack_print+0x165/0x170 Read of size 8 at addr ff11000005259d40 by task init/1 ... Allocated by task 1: __kasan_kmalloc+0x7f/0x90 __set_page_owner+0x45c/0x6c0 ... Freed by task 1: kfree+0x1a0/0x390 seq_release_private+0x58/0x110 full_proxy_release+0xe3/0x290 __fput+0x35c/0xac0 __x64_sys_close+0x79/0xc0 ... The buggy address belongs to the object at ff11000005259d40 which belongs to the cache kmalloc-16 of size 16
Without KASAN, a partial read followed by a full read
("head -12 show_stacks; cat show_stacks") panics arm64 hardware running a 6.12.108-based kernel:
Unable to handle kernel paging request at virtual address 0030206235376d88 pc : stack_print+0x20/0xd0 lr : seq_read_iter+0x340/0x470 Call trace: stack_print+0x20/0xd0 seq_read_iter+0x340/0x470 seq_read+0xf0/0x140 full_proxy_read+0x54/0xa0 vfs_read+0xc8/0x348 ksys_read+0x6c/0x118 Kernel panic - not syncing: Oops: Fatal exception
With this revert applied, the QEMU reproducer completes 20 partial-read/full-read cycles without a KASAN report. mm/page_owner.c is unchanged between v6.12.115 and v6.12.116.
Backporting 156c0c5d1463 instead is not proposed: it prepares for the new show_handles and show_stacks_handles debugfs files rather than fixing anything, so reverting the backport is the minimal change for stable.
--- mm/page_owner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_owner.c +1 -1
@@ -937,7 +937,7 @@ static const struct file_operations page_owner_stack_operations = { .open = page_owner_stack_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = seq_release, };static int page_owner_threshold_get (void *data,u64 *val)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/670 arm64: sdei: Run the event handler on the kernel vectors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
[ Upstream commit 9bf6ee7952c7ee151c30e0fffcfc61b58127c899 ]
With KPTI, VBAR_EL1 holds the trampoline vectors from the return to EL0 until the next exception from EL0 maps the kernel and installs the kernel vectors. The trampoline vectors only handle exceptions from EL0; their current-EL half is zero-filled.
An SDEI event is dispatched regardless of PSTATE.DAIF, so it lands there whenever the CPU is in user space. The SDEI entry trampoline maps the kernel but leaves VBAR_EL1 alone. An exception taken by the handler then executes the zeros, takes an undefined instruction exception to the same vector, and loops there forever. The event never completes and the CPU is lost; RCU stall reports are the first sign of it.
RAS notifications land in user space whenever a task consumes the error, and NMI backtraces land wherever the CPU happens to be. The GHES handler takes no exception on its own, but any exception in the handler path does it: a WARN, a kprobe hit, or a fault fixed up by a _nofault() accessor.
Install the kernel vectors in __sdei_handler() when VBAR_EL1 holds the trampoline vectors, and restore it before returning to firmware. The switch covers irqentry_nmi_enter() and irqentry_nmi_exit() too, as Usama Arif pointed out: their tracepoints and context tracking WARNs can take an exception as well.
The IRQ-like resume into user space must still go through the trampoline to map the kernel. do_sdei_event() takes the interrupted VBAR_EL1 and keeps basing the resume address on it.
--- arch/arm64/include/asm/sdei.h | 3 ++- arch/arm64/kernel/entry-common.c | 21 ++++++++++++++++++++- arch/arm64/kernel/sdei.c | 6 ++++-- 3 files changed, 26 insertions(+), 4 deletions(-)
arch/arm64/include/asm/sdei.h +2 -1
@@ -44,7 +44,8 @@ asmlinkage unsigned long __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg);unsigned long do_sdei_event (struct pt_regs *regs, -struct sdei_registered_event *arg); +struct sdei_registered_event *arg, +unsigned long vbar);unsigned long sdei_arch_get_entry_point (int conduit);#define sdei_arch_get_entry_point (x) sdei_arch_get_entry_point(x)
arch/arm64/kernel/entry-common.c +20 -1
@@ -27,6 +27,7 @@#include <asm/stacktrace.h> #include <asm/sysreg.h> #include <asm/system_misc.h> +#include <asm/vectors.h> /* * Handle IRQ/context state management when entering from kernel mode.
@@ -1087,6 +1088,7 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs) asmlinkage noinstr unsigned long__sdei_handler (struct pt_regs *regs,struct sdei_registered_event *arg) { +unsigned long vbar;unsigned long ret;/*
@@ -1111,10 +1113,27 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) else if (cpu_has_pan()) set_pstate_pan(0); +/* +* With KPTI, VBAR_EL1 holds the trampoline vectors from the return to +* EL0 until the next exception from EL0 maps the kernel. They only +* handle exceptions from EL0: an exception taken here would run their +* empty current-EL half and never come back. Switch to the kernel +* vectors. The IRQ-like resume keeps using the interrupted VBAR, so it +* still goes through the trampoline. +*/ + vbar =read_sysreg (vbar_el1); +if (arm64_kernel_unmapped_at_el0 () && + vbar == (unsigned long )raw_cpu_read (this_cpu_vector)) { +write_sysreg ((unsigned long )vectors, vbar_el1); +isb (); + } +arm64_enter_nmi (regs); - ret =do_sdei_event (regs, arg); + ret =do_sdei_event (regs, arg, vbar);arm64_exit_nmi (regs); +write_sysreg (vbar, vbar_el1); + return ret; }#endif /* CONFIG_ARM_SDE_INTERFACE */
arch/arm64/kernel/sdei.c +4 -2
@@ -208,16 +208,18 @@ unsigned long sdei_arch_get_entry_point(int conduit)* SDEI_EV_HANDLED - success, return to the interrupted context. * SDEI_EV_FAILED - failure, return this error code to firmare. * virtual-address - success, return to this address. +* +* vbar is the interrupted context's VBAR_EL1, for the IRQ-like resume. */ unsigned long __kprobes do_sdei_event (struct pt_regs *regs, -struct sdei_registered_event *arg) +struct sdei_registered_event *arg, +unsigned long vbar) {u32 mode;int i, err =0 ;int clobbered_registers =4 ;u64 elr =read_sysreg (elr_el1);u32 kernel_mode =read_sysreg (CurrentEL) |1 ;/* +SPSel */ -unsigned long vbar =read_sysreg (vbar_el1);if (arm64_kernel_unmapped_at_el0 ()) clobbered_registers++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/670 arm64: sdei: Preserve the interrupted contexts exception registers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
[ Upstream commit 58c1eb84e97701c583605ba2fd553b69afba2245 ]
An SDEI event is dispatched by firmware regardless of PSTATE.DAIF, so it can interrupt the kernel where the exception registers are live:
- exception entry, before kernel_entry has saved ELR_EL1/SPSR_EL1 and before the C handler has read ESR_EL1/FAR_EL1;
- exception return, after kernel_exit has loaded ELR_EL1/SPSR_EL1 and before the ERET.
An IRQ or pseudo-NMI cannot arrive there with PSTATE.I set. Firmware saves only x0-x17, PC and PSTATE around an SDEI event, so a synchronous exception taken by the handler overwrites the interrupted context's ELR, SPSR, ESR and FAR. do_sdei_event() only notices that ELR changed, and warns.
The interrupted context then carries on with the handler's state. A task interrupted on its way into the kernel can be sent SIGILL for the handler's kernel data abort. A task interrupted on its way back to user space ERETs to EL1, at the handler's fixup address, with user registers loaded.
With SDEI delivering NMI backtraces, this happens in normal operation. The handler runs show_regs(), which reads through possibly-NULL pointers with the _nofault() accessors. print_worker_info() faults this way for a kworker that is not running a work item, and a single sysrq-l warned once per such kworker.
Save ELR, SPSR, ESR and FAR in __sdei_handler() before irqentry_nmi_enter(), which can take an exception too, and restore them after irqentry_nmi_exit().
Once they are restored, a nested exception is harmless if its handler is safe in NMI context. That holds for EL1 data aborts on translation, permission and access-flag faults, which never take the mmap lock in NMI context, and for BRK. Warn once, with the syndrome, about any other exception class.
--- arch/arm64/kernel/entry-common.c | 21 ++++++++++++- arch/arm64/kernel/sdei.c | 53 ++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 10 deletions(-)
arch/arm64/kernel/entry-common.c +20 -1
@@ -1088,7 +1088,7 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs) asmlinkage noinstr unsigned long__sdei_handler (struct pt_regs *regs,struct sdei_registered_event *arg) { -unsigned long vbar; +unsigned long elr, spsr, esr, far, vbar;unsigned long ret;/*
@@ -1113,6 +1113,17 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)else if (cpu_has_pan ())set_pstate_pan (0 ); +/* +* Nothing saved the interrupted context's exception registers on the +* way in, and it may be in the middle of exception entry or return +* (SDEI ignores DAIF). Save them before anything can take an exception +* and overwrite them. +*/ + elr =read_sysreg (elr_el1); + spsr =read_sysreg (spsr_el1); + esr =read_sysreg (esr_el1); + far =read_sysreg (far_el1); +/* * With KPTI, VBAR_EL1 holds the trampoline vectors from the return to * EL0 until the next exception from EL0 maps the kernel. They only
@@ -1132,6 +1143,14 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) ret =do_sdei_event (regs, arg, vbar);arm64_exit_nmi (regs); +/* +* Put them back unconditionally. An unchanged ELR does not rule out a +* nested exception: one may have returned to the same address. +*/ +write_sysreg (elr, elr_el1); +write_sysreg (spsr, spsr_el1); +write_sysreg (esr, esr_el1); +write_sysreg (far, far_el1);write_sysreg (vbar, vbar_el1);return ret;
arch/arm64/kernel/sdei.c +44 -9
74 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/670 microblaze: restore the ABI argument home area below pt_regs (PTO)
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ramin Moussavi <[email protected]>
commit c35d40a3efd2e575ef51a761e983f2bf7113be6c upstream.
The MicroBlaze ABI has the caller reserve stack space for the arguments it passes in registers: REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1 in the gcc backend, so a callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C functions from entry.S with r1 pointing at pt_regs, handing the callee license to spill its incoming arguments over the saved registers -- the syscall dispatch is the worst case, where the first argument slot is PT_R1, the saved user stack pointer.
This was latent until GCC 15: since 3b9b8d6cfdf5 ("ira: Scale save/restore costs of callee save registers with block frequency") the allocator prefers spilling incoming arguments over copying them into callee-saved registers, and a kernel built with gcc >= 15 (without the TARGET_CALLEE_SAVE_COST workaround some distributions carry) corrupts PT_R1 on the first syscall: init takes SIGSEGV and the kernel panics.
The kernel had exactly this reservation until 2011:
commit 6e83557c38b4 ("microblaze: Remove r0_ram pointer and PTO alignment") removed STATE_SAVE_ARG_SPACE and with it the PTO offset, as part of cleaning up what was thought to be copied-from-v850 leftovers. Restore
it: the frame is STATE_SAVE_SIZE = PT_SIZE + PTO, r1 stays at the frame base through every asm-to-C call, and the saved registers are reached at r1 + PTO + PT_*. PTO is 28 rather than the historic 24, which was one word short: FIRST_PARM_OFFSET is 4 and REG_PARM_STACK_SPACE is 24, so the area spans [sp+4, sp+28) and needs 28 bytes. With 24 the last argument slot overlapped pt_regs' r0 -- harmless only because r0 is the constant-zero register. STACK_BOUNDARY is 32 bits, so 28 needs no further rounding.
Two places deliberately keep their mainline addressing. hw_exception_handler.S needs no offset change: its real-mode handler saves into the standalone pt_pool_space buffer rather than a stack frame, and _unaligned_data_exception works through a pointer to pt_regs in r7, where plain PT_* offsets are already right. And the user-SP reload after popping the frame keeps PT_R1 - PT_SIZE because PTO cancels there: (PTO + PT_R1) - (PT_SIZE + PTO) = PT_R1 - PT_SIZE. Both are exactly as the pre-2011 code had them.
The instruction count is unchanged -- the same instructions with different immediates, no per-call reservation and no trampolines. The cost is 28 bytes more kernel stack per saved frame.
--- arch/microblaze/include/asm/entry.h | 13 + arch/microblaze/include/asm/processor.h | 2 +- arch/microblaze/kernel/entry.S | 329 +++++++++--------- arch/microblaze/kernel/hw_exception_handler.S | 5 + arch/microblaze/kernel/process.c | 5 +- 5 files changed, 189 insertions(+), 165 deletions(-)
arch/microblaze/include/asm/entry.h +13 -0
@@ -21,6 +21,19 @@#define PER_CPU (var) var +/* +* The MicroBlaze ABI has the caller reserve an argument home area: +* REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1, so a +* callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C +* with r1 at the frame base, so reserve that area below pt_regs and reach +* the saved registers through PTO. This restores what 6e83557c38b4 +* ("microblaze: Remove r0_ram pointer and PTO alignment") removed; the old +* value of 24 was one word short and left the last argument slot +* overlapping pt_regs' r0. +*/ +#define PTO 28 +#define STATE_SAVE_SIZE (PT_SIZE + PTO) +# ifndef __ASSEMBLY__ DECLARE_PER_CPU(unsigned int, KSP); /* Saved kernel stack pointer */ DECLARE_PER_CPU(unsigned int, KM); /* Kernel/user mode */
arch/microblaze/include/asm/processor.h +1 -1
@@ -73,7 +73,7 @@ unsigned long __get_wchan(struct task_struct *p);# define task_regs (task) ((struct pt_regs *)task_tos(task) - 1)# define task_pt_regs_plus_args (tsk) \ - ((void *)task_pt_regs(tsk)) + (((void *)task_pt_regs(tsk)) - PTO)# define task_sp (task) (task_regs(task)->r1)# define task_pc (task) (task_regs(task)->pc)
arch/microblaze/kernel/entry.S +167 -162
675 lines not on this page · raw message
arch/microblaze/kernel/hw_exception_handler.S +5 -0
@@ -313,6 +313,11 @@ _MB_HW_ExceptionVectorTable: .align 4 .ent _hw_exception_handler _hw_exception_handler: + /* + * This handler saves into the static pt_pool_space buffer, not into a + * stack frame, so the plain PT_* offsets are right here -- do not add + * the PTO of entry.S's frames. + */ swi r1, r0, TOPHYS(pt_pool_space + PT_R1); /* GET_SP */ /* Save date to kernel memory. Here is the problem * when you came from user space */
arch/microblaze/kernel/process.c +3 -2
@@ -19,6 +19,7 @@#include <linux/bitops.h> #include <linux/ptrace.h> #include <asm/cacheflush.h> +#include <asm/entry.h> void show_regs (struct pt_regs *regs) {
@@ -65,7 +66,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)* the registers. That's OK for a brand new thread.*/ memset (childregs,0 ,sizeof (struct pt_regs ));memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; ti->cpu_context.r20 = (unsigned long )args->fn; ti->cpu_context.r19 = (unsigned long )args->fn_arg; childregs->pt_mode =1 ;
@@ -79,7 +80,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) childregs->r1 = usp;memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; childregs->msr |=MSR_UMS ;/* we should consider the fact that childregs is a copy of the parent
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/670 vxlan: Stop rejecting dynamic FDB entries with a nexthop ID
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 7308ef8b4a6779a39f68d053c19b53a5c584a663 ]
Commit 98fc57d16744 ("vxlan: reject dynamic fdb entries that reference a nexthop id") started rejecting FDB entries that point to FDB nexthops unless they are configured as "permanent" or "static". The intent was to prevent such entries from being aged out by vxlan_cleanup(), which runs without RTNL and can therefore race with other VXLAN devices that modify the same per-nexthop FDB list.
However, FRR installs remote MACs that are behind a multihomed Ethernet Segment (EVPN-MH) as dynamic FDB entries that point to an FDB nexthop group. Since the above commit, these entries are rejected and traffic towards the corresponding MACs is flooded to all the remote VTEPs.
These entries are also marked as externally learned ("extern_learn") and are therefore skipped by vxlan_cleanup(), but exempting externally learned entries from the checks is not enough: vxlan_cleanup() reads the state and flags of an entry without the hash lock, so an entry that is concurrently changed from dynamic and externally learned to static can still be aged out.
Instead, remove the checks added by the above commit and make vxlan_cleanup() skip FDB entries that point to FDB nexthops. Such entries can only be configured from user space, cannot be learned and cannot roam, so there is no reason to age them out. The nexthop pointer of an FDB entry is set before the entry is linked and is only cleared after it was unlinked and an RCU grace period has passed, so it can be checked without the hash lock.
Adjust the test cases added by the above commit and add a test case that checks that dynamic FDB entries that point to FDB nexthops are not aged out. Without the fix:
# ./fib_nexthops.sh -t "ipv4_fdb_grp_fcnal ipv6_fdb_grp_fcnal"
IPv4 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [FAIL] TEST: Fdb mac add with nexthop group and extern_learn [FAIL] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [FAIL]
[...]
IPv6 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [FAIL] TEST: Fdb mac add with nexthop group and extern_learn [FAIL] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [FAIL]
[...]
Tests passed: 44
Tests failed: 6
Tests skipped: 0
With the fix:
# ./fib_nexthops.sh -t "ipv4_fdb_grp_fcnal ipv6_fdb_grp_fcnal"
IPv4 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [ OK ] TEST: Fdb mac add with nexthop group and extern_learn [ OK ] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [ OK ]
[...]
IPv6 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [ OK ] TEST: Fdb mac add with nexthop group and extern_learn [ OK ] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [ OK ]
[...]
Tests passed: 50
Tests failed: 0
Tests skipped: 0
[ idosch: fixed a small conflict in vxlan_fdb_add() and adjusted the
vxlan_cleanup() hunk to the per-bucket FDB iteration in this tree ]
--- drivers/net/vxlan/vxlan_core.c | 14 ++------ tools/testing/selftests/net/fib_nexthops.sh | 40 ++++++++++++++------- 2 files changed, 31 insertions(+), 23 deletions(-)
drivers/net/vxlan/vxlan_core.c +3 -11
@@ -1006,12 +1006,6 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,return -EOPNOTSUPP ; } -if (rcu_access_pointer (f->nh) && - !(state & (NUD_PERMANENT |NUD_NOARP ))) { -NL_SET_ERR_MSG (extack,"Cannot make a nexthop fdb dynamic" ); -return -EOPNOTSUPP ; - } -/* Do not allow an externally learned entry to take over an entry added * by the user. */
@@ -1279,11 +1273,6 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],if (err)return err; -if (nhid && !(ndm->ndm_state & (NUD_PERMANENT |NUD_NOARP ))) { -NL_SET_ERR_MSG (extack,"A nexthop fdb cannot be dynamic" ); -return -EINVAL ; - } -if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)return -EAFNOSUPPORT ;
@@ -2896,6 +2885,9 @@ static void vxlan_cleanup(struct timer_list *t)if (f->flags &NTF_EXT_LEARNED )continue ; +if (rcu_access_pointer (f->nh)) +continue ; + timeout =READ_ONCE (f->used) + vxlan->cfg.age_interval *HZ ;if (time_before_eq (timeout, jiffies)) { netdev_dbg(vxlan->dev,
tools/testing/selftests/net/fib_nexthops.sh +28 -12
@@ -421,6 +421,14 @@ stop_ip_monitor() return $rc } +fdb_entry_aged() +{ + local mac=$1 + local dev=$2 + + ! $BRIDGE fdb get to $mac dev $dev self &> /dev/null +} + check_nexthop_fdb_support() { $IP nexthop help 2>&1 | grep -q fdb
@@ -505,14 +513,18 @@ ipv6_fdb_grp_fcnal() log_test $? 0 "Fdb mac add with nexthop group and static state" run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic" - log_test $? 255 "Fdb mac add with nexthop group and dynamic state" + log_test $? 0 "Fdb mac add with nexthop group and dynamic state" + + run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self dynamic extern_learn" + log_test $? 0 "Fdb mac add with nexthop group and extern_learn" - run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self" - run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic" - log_test $? 255 "Fdb mac replace with nexthop group and dynamic state" + run_cmd "$IP link set dev vx10 up type vxlan ageing 1" + run_cmd "$BRIDGE fdb add 02:02:00:00:00:18 dev vx10 dst 2001:db8:91::11 self dynamic" + slowwait 20 fdb_entry_aged 02:02:00:00:00:18 vx10 + log_test $? 0 "Fdb mac without nexthop group aged out" - run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic" - log_test $? 255 "Fdb mac append with nexthop group and dynamic state" + run_cmd "$BRIDGE fdb get to 02:02:00:00:00:16 dev vx10 self" + log_test $? 0 "Fdb mac with nexthop group not aged out" run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 66" log_test $? 2 "Route add with fdb nexthop"
@@ -599,14 +611,18 @@ ipv4_fdb_grp_fcnal() log_test $? 0 "Fdb mac add with nexthop group and static state" run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic" - log_test $? 255 "Fdb mac add with nexthop group and dynamic state" + log_test $? 0 "Fdb mac add with nexthop group and dynamic state" + + run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self dynamic extern_learn" + log_test $? 0 "Fdb mac add with nexthop group and extern_learn" - run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self" - run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic" - log_test $? 255 "Fdb mac replace with nexthop group and dynamic state" + run_cmd "$IP link set dev vx10 up type vxlan ageing 1" + run_cmd "$BRIDGE fdb add 02:02:00:00:00:18 dev vx10 dst 10.0.0.3 self dynamic" + slowwait 20 fdb_entry_aged 02:02:00:00:00:18 vx10 + log_test $? 0 "Fdb mac without nexthop group aged out" - run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic" - log_test $? 255 "Fdb mac append with nexthop group and dynamic state" + run_cmd "$BRIDGE fdb get to 02:02:00:00:00:16 dev vx10 self" + log_test $? 0 "Fdb mac with nexthop group not aged out" run_cmd "$IP ro add 172.16.0.0/22 nhid 16" log_test $? 2 "Route add with fdb nexthop"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/670 mm/damon/core: move static variable last_nr_regions to damon_ctx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
[ Upstream commit 26ae50a0901a44f7d50053f87dc38abd9f9a269c ]
kdamond_split_regions() uses a static variable last_nr_regions, to infer if the region boundaries are too stable. If it looks too stable, it does a more aggressive region split because it might be a fake stability coming from non-aggressive split. Because the variable is static, the inference can be racy and wrong when multiple kdamonds are running in parallel.
The user impact is not critical. No crash, no leak. DAMON's best-effort monitoring accuracy can be degraded when multiple kdamonds are used in parallel and the workload has certain access patterns. Still it is a bug that is better to fix.
Move the variable into the damon_ctx struct to fix the problem.
--- include/linux/damon.h | 6 ++++++ mm/damon/core.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-)
include/linux/damon.h +6 -0
@@ -641,6 +641,12 @@ struct damon_ctx {struct list_head adaptive_targets;struct list_head schemes; +/* private: */ +/* +* number of regions after last merge. Read kdamond_split_regions() +* for more details. +*/ +unsigned long last_nr_regions; };static inline struct damon_region *damon_next_region (struct damon_region *r)
mm/damon/core.c +2 -3
@@ -1971,7 +1971,6 @@ static void kdamond_split_regions(struct damon_ctx *ctx) {struct damon_target *t;unsigned int nr_regions =0 ; -static unsigned int last_nr_regions;int nr_subregions =2 ;damon_for_each_target (t, ctx)
@@ -1981,14 +1980,14 @@ static void kdamond_split_regions(struct damon_ctx *ctx)return ;/* Maybe the middle of the region has different access frequency */ -if (last_nr_regions == nr_regions && +if (ctx->last_nr_regions == nr_regions && nr_regions < ctx->attrs.max_nr_regions /3 ) nr_subregions =3 ;damon_for_each_target (t, ctx)damon_split_regions_of (t, nr_subregions); - last_nr_regions = nr_regions; + ctx->last_nr_regions = nr_regions; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/670 can: raw, isotp: copy socket options outside of lock_sock()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 43c973a0887d3d7b2ee0a446603c97bf0f38c58e upstream.
The CAN_RAW and CAN_ISOTP specific socket options are copied from and to user space while holding lock_sock(). A copy that faults or stalls, e.g. on a userfaultfd or FUSE backed mapping, holds lock_sock() for its whole duration.
raw_notify() and isotp_notify() take lock_sock() of a socket that is bound to the vanishing device while holding RTNL. As the CAN_RAW options can also be changed on a bound socket, a stalled copy can block RTNL on an unregistration or namespace change of the bound device. Before "can: protect the receive lists with a per-device lock", raw_setsockopt() even held RTNL itself during the copy. CAN_ISOTP only copies its options for unbound sockets, which isotp_notify() skips without taking lock_sock().
Keep the user space copies out of the locked sections: Check the option name and length and copy the option values, including the CAN_RAW_FILTER filters, to kernel memory before lock_sock(). raw_setsockopt_locked() and isotp_setsockopt_locked() get the copied values directly and drop their now redundant length checks and copies. As a side effect, a failing copy can not leave partially overwritten options behind anymore. In raw_getsockopt() duplicate the filters under lock_sock() and copy them to user space after release_sock().
As the option name and length are now checked before lock_sock(), the order of the checks in isotp_setsockopt() and accordingly the order of the returned error values changes. This is in line with POSIX, which does not define an order in which multiple error conditions are detected and reported.
The generic SOL_SOCKET options in sk_setsockopt() are not affected by this patch.
[ backport to 6.12: This tree has no raw_setsockopt_locked() from commit
1e5185c09058 ("can: raw: add locking for raw flags bitfield"). raw_setsockopt() already copies all option values from user space before lock_sock() here, so only the raw_getsockopt() and isotp parts apply. raw_getsockopt() uses copy_to_user() and put_user() instead of the getsockopt_iter interface in this tree. Duplicate the filters under lock_sock() and copy them with copy_to_user() after release_sock(). Also move the put_user() of the needed filter space for -ERANGE behind release_sock(), which upstream writes to the kernel side opt->optlen. ]
--- net/can/isotp.c | 100 +++++++++++++++++++++++++++--------------------- net/can/raw.c | 21 +++++++--- 2 files changed, 73 insertions(+), 48 deletions(-)
net/can/isotp.c +57 -43
@@ -1683,8 +1683,8 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)return ISOTP_MIN_NAMELEN ; } -static int isotp_setsockopt_locked (struct socket *sock,int level,int optname, -sockptr_t optval,unsigned int optlen) +static int isotp_setsockopt_locked (struct socket *sock,int optname, +const void *val) {struct sock *sk = sock->sk;struct isotp_sock *so =isotp_sk (sk);
@@ -1695,11 +1695,7 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,switch (optname) {case CAN_ISOTP_OPTS : -if (optlen !=sizeof (struct can_isotp_options )) -return -EINVAL ; - -if (copy_from_sockptr (&so->opt, optval, optlen)) -return -EFAULT ; +memcpy (&so->opt, val,sizeof (so->opt));/* no separate rx_ext_address is given => use ext_address */ if (!(so->opt.flags &CAN_ISOTP_RX_EXT_ADDR ))
@@ -1724,55 +1720,37 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,break ;case CAN_ISOTP_RECV_FC : -if (optlen !=sizeof (struct can_isotp_fc_options )) -return -EINVAL ; - -if (copy_from_sockptr (&so->rxfc, optval, optlen)) -return -EFAULT ; +memcpy (&so->rxfc, val,sizeof (so->rxfc));break ;case CAN_ISOTP_TX_STMIN : -if (optlen !=sizeof (u32)) -return -EINVAL ; - -if (copy_from_sockptr (&so->force_tx_stmin, optval, optlen)) -return -EFAULT ; + so->force_tx_stmin = *(const u32 *)val;break ;case CAN_ISOTP_RX_STMIN : -if (optlen !=sizeof (u32)) -return -EINVAL ; - -if (copy_from_sockptr (&so->force_rx_stmin, optval, optlen)) -return -EFAULT ; + so->force_rx_stmin = *(const u32 *)val;break ; -case CAN_ISOTP_LL_OPTS : -if (optlen ==sizeof (struct can_isotp_ll_options )) { -struct can_isotp_ll_options ll; - -if (copy_from_sockptr (&ll, optval, optlen)) -return -EFAULT ; +case CAN_ISOTP_LL_OPTS : { +const struct can_isotp_ll_options *ll = val; -/* check for correct ISO 11898-1 DLC data length */ -if (ll.tx_dl !=padlen (ll.tx_dl)) -return -EINVAL ; +/* check for correct ISO 11898-1 DLC data length */ +if (ll->tx_dl !=padlen (ll->tx_dl)) +return -EINVAL ; -if (ll.mtu !=CAN_MTU && ll.mtu !=CANFD_MTU ) -return -EINVAL ; +if (ll->mtu !=CAN_MTU && ll->mtu !=CANFD_MTU ) +return -EINVAL ; -if (ll.mtu ==CAN_MTU && - (ll.tx_dl >CAN_MAX_DLEN || ll.tx_flags !=0 )) -return -EINVAL ; +if (ll->mtu ==CAN_MTU && + (ll->tx_dl >CAN_MAX_DLEN || ll->tx_flags !=0 )) +return -EINVAL ; -memcpy (&so->ll, &ll,sizeof (ll)); +memcpy (&so->ll, ll,sizeof (*ll)); -/* set ll_dl for tx path to similar place as for rx */ - so->tx.ll_dl = ll.tx_dl; - }else { -return -EINVAL ; - } +/* set ll_dl for tx path to similar place as for rx */ + so->tx.ll_dl = ll->tx_dl;break ; + }default : ret = -ENOPROTOOPT ;
@@ -1786,13 +1764,49 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname, {struct sock *sk = sock->sk; +union { +struct can_isotp_options opt; +struct can_isotp_fc_options rxfc; +struct can_isotp_ll_options ll; +u32 stmin; + } val; +unsigned int size;int ret;if (level !=SOL_CAN_ISOTP )return -EINVAL ; +/* copy the option values from user space before lock_sock() */ +switch (optname) { +case CAN_ISOTP_OPTS : + size =sizeof (val.opt); +break ; + +case CAN_ISOTP_RECV_FC : + size =sizeof (val.rxfc); +break ; + +case CAN_ISOTP_TX_STMIN : +case CAN_ISOTP_RX_STMIN : + size =sizeof (val.stmin); +break ; + +case CAN_ISOTP_LL_OPTS : + size =sizeof (val.ll); +break ; + +default : +return -ENOPROTOOPT ; + } + +if (optlen != size) +return -EINVAL ; + +if (copy_from_sockptr (&val, optval, size)) +return -EFAULT ; +lock_sock (sk); - ret =isotp_setsockopt_locked (sock, level, optname, optval, optlen); + ret =isotp_setsockopt_locked (sock, optname, &val);release_sock (sk);return ret; }
net/can/raw.c +16 -5
@@ -812,29 +812,40 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,switch (optname) {case CAN_RAW_FILTER : { +struct can_filter *filter =NULL ; +int fsize =0 ;int err =0 ;lock_sock (sk);if (ro->count >0 ) { -int fsize = ro->count *sizeof (struct can_filter ); + fsize = ro->count *sizeof (struct can_filter );/* user space buffer to small for filter list? */ if (len < fsize) {/* return -ERANGE and needed space in optlen */ err = -ERANGE ; -if (put_user (fsize, optlen)) - err = -EFAULT ; }else {if (len > fsize) len = fsize; -if (copy_to_user (optval, ro->filter, len)) - err = -EFAULT ; +/* copy to user space after release_sock() */ + filter =kmemdup (ro->filter, len,GFP_KERNEL ); +if (!filter) + err = -ENOMEM ; } }else { len =0 ; }release_sock (sk); +if (err == -ERANGE ) { +if (put_user (fsize, optlen)) + err = -EFAULT ; + }else if (filter) { +if (copy_to_user (optval, filter, len)) + err = -EFAULT ; +kfree (filter); + } +if (!err) err =put_user (len, optlen);return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/670 sched_ext: Reset runnable_at when a task leaves its scheduler
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Blaszczyk <[email protected]>
[ Upstream commit 993e8fbfecbbf284b9644c6f10741b28fb914094 ]
The watchdog measures how long a task has been waiting from p->scx.runnable_at, which set_task_runnable() resets when the task becomes runnable after it last ran. ops_dequeue() never asks for a reset, as the dequeue of a waiting task is temporary, e.g. for a migration or an attribute change.
Leaving the scheduler isn't temporary. A task which is switched out of SCHED_EXT while it's waiting keeps its runnable_at. When it's switched back and becomes runnable, its wait appears to have started before it left, and the time it spent in another class counts towards the timeout. If the watchdog checks before the task runs, it aborts the scheduler:
sched_ext: class_switch_stall: runner[418] failed to run for 3.010s
Here, the task waited for a few milliseconds before it was switched to SCHED_OTHER, slept outside of SCHED_EXT for three seconds, and was charged for all of it as soon as it woke up on SCHED_EXT again.
The same happens when scx_sub_enable_workfn() hands a waiting task over to a new sub-scheduler, which can then be blamed for time the task waited under the parent. scx_rehome_task() isn't affected, as it moves the task through SCX_TASK_INIT, which resets runnable_at. The stale runnable_at also skews the default core-sched ordering in scx_prio_less().
Reset runnable_at in scx_disable_task(), when the task leaves the control of its scheduler.
[ michalblk: applied to kernel/sched/ext.c, where the function is
scx_ops_disable_task() and has no @sch; adjusted the comments and context accordingly ]
--- kernel/sched/ext.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/sched/ext.c +13 -1
@@ -2173,7 +2173,11 @@ static void ops_dequeue(struct task_struct *p, u64 deq_flags) {unsigned long opss; -/* dequeue is always temporary, don't reset runnable_at */ +/* +* Don't reset runnable_at. If @p is waiting, the wait continues across +* temporary dequeues, e.g. for a migration or an attribute change. +* scx_ops_disable_task() ends it if @p leaves its scheduler. +*/ clr_task_runnable (p, false);/* acquire ensures that we see the preceding updates on QUEUED */
@@ -3794,6 +3798,14 @@ static void scx_ops_disable_task(struct task_struct *p)if (SCX_HAS_OP (disable))SCX_CALL_OP_TASK (SCX_KF_REST , disable, p);scx_set_task_state (p,SCX_TASK_READY ); + +/* +* If @p is runnable but not running, its wait started at runnable_at, +* which ops_dequeue() didn't reset. Leaving the BPF scheduler ends the +* wait. Reset runnable_at the next time @p is enqueued on SCX, so that +* the watchdog doesn't count the time @p spends elsewhere. +*/ + p->scx.flags |=SCX_TASK_RESET_RUNNABLE_AT ; }static void scx_ops_exit_task (struct task_struct *p)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/670 ata: libata-scsi: reject data-in commands with a data-out buffer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Gongyi <[email protected]>
[ Upstream commit a4845f077415ef32fe672c841e2fc58ae9e28273 ]
SG_IO can submit a data-in SCSI command with DMA_TO_DEVICE. The scatterlist can then contain pages pinned without write access. ata_scsi_rbuf_fill() writes simulated replies to that scatterlist; in the reported case, the copy tried to write the shared zero page and faulted in the kernel.
The same mismatch can affect SG_IO commands translated by libata. ZBC IN and GET PHYSICAL ELEMENT STATUS completion handlers can modify the receive buffer even if the drive aborts the command. For ATAPI, the successful INQUIRY completion also rewrites the buffer in atapi_fixup_inquiry().
Reject these mismatched commands before the buffer is written or the command is issued. Report ABORTED COMMAND / DATA IN BUFFER ERROR because the CDB itself can be valid; the supplied transfer direction is wrong.
Backport notes: Use the older five-argument ata_scsi_set_sense() interface and spell DATA IN BUFFER ERROR as ASC/ASCQ 0x4b/0x0a.
--- drivers/ata/libata-scsi.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/ata/libata-scsi.c +25 -0
@@ -1989,6 +1989,18 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,if (xlat_func (qc)) goto done; +/* +* A data-out request may contain pages pinned without write access. +* Reject a translated data-in command before issuing it, since its +* completion handler may write to the buffer even if the device fails. +*/ +if (unlikely (cmd->sc_data_direction ==DMA_TO_DEVICE && +ata_is_data (qc->tf.protocol) && + !(qc->tf.flags &ATA_TFLAG_WRITE ))) { +ata_scsi_set_sense (dev, cmd,ABORTED_COMMAND ,0x4b ,0x0a ); + goto done; + } +return ata_scsi_qc_issue (ap, qc); done:
@@ -2020,6 +2032,12 @@ static void ata_scsi_rbuf_fill(struct ata_device *dev, struct scsi_cmnd *cmd,unsigned long flags;unsigned int len; +/* A data-out request may contain pages pinned without write access. */ +if (cmd->sc_data_direction ==DMA_TO_DEVICE ) { +ata_scsi_set_sense (dev, cmd,ABORTED_COMMAND ,0x4b ,0x0a ); +return ; + } +spin_lock_irqsave (&ata_scsi_rbuf_lock, flags);memset (ata_scsi_rbuf,0 ,ATA_SCSI_RBUF_SIZE );
@@ -3077,6 +3095,13 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) qc->complete_fn = atapi_qc_complete; +/* atapi_fixup_inquiry() writes to the buffer on successful completion. */ +if (scmd->sc_data_direction ==DMA_TO_DEVICE && + scmd->cmnd[0 ] ==INQUIRY ) { +ata_scsi_set_sense (dev, scmd,ABORTED_COMMAND ,0x4b ,0x0a ); +return 1 ; + } + qc->tf.flags |=ATA_TFLAG_ISADDR |ATA_TFLAG_DEVICE ;if (scmd->sc_data_direction ==DMA_TO_DEVICE ) { qc->tf.flags |=ATA_TFLAG_WRITE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/670 mm/gup: check folio->mapping under folio lock in memfd_pin_folios()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samiullah Khawaja <[email protected]>
[ Upstream commit 71555ae8c7572fd99158013ca2e29187c5d2508d ]
memfd_pin_folios() pins folios from the page cache without taking the folio lock. khugepaged or MADV_COLLAPSE can therefore replace a folio after checking its refcount while memfd_pin_folios() still pins the old folio. The caller then receives a folio which is no longer part of the memfd.
For udmabuf and iommufd, this can cause data corruption: DMA accesses the detached folio rather than the live memfd contents. DMA reads can return stale data, while DMA writes update the detached copy and are lost from the live memfd. The detached folio remains pinned, so these accesses do not constitute a use-after-free or target another application's memory. For memfd live update, the stale contents can reappear in the memfd after handover.
Lock the folio and recheck folio->mapping before pinning it, like other page cache users do. If the folio was removed, retry the folio lookup from the index that was removed.
--- mm/gup.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
mm/gup.c +21 -8
@@ -3706,7 +3706,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, {unsigned int flags, nr_folios, nr_found;unsigned int i, pgshift =PAGE_SHIFT ; -pgoff_t start_idx, end_idx, next_idx; +pgoff_t start_idx, end_idx, next_idx, retry_idx;struct folio *folio =NULL ;struct folio_batch fbatch;struct hstate *h;
@@ -3747,6 +3747,7 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,* reason, we try to allocate them and add them to the * page cache. */ + retry_idx = start_idx; nr_found = filemap_get_folios_contig(memfd->f_mapping, &start_idx, end_idx,
@@ -3771,7 +3772,21 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end, folio =page_folio (&fbatch.folios[i]->page); +/* +* The folio might have been removed from the +* page cache (e.g., truncated or collapsed) +* after the lookup. Recheck under the folio +* lock. +*/ +folio_lock (folio); +if (unlikely (folio->mapping != memfd->f_mapping)) { +folio_unlock (folio); + start_idx = retry_idx; +break ; + } +if (try_grab_folio (folio,1 ,FOLL_PIN )) { +folio_unlock (folio);folio_batch_release (&fbatch); ret = -EINVAL ; goto err;
@@ -3782,14 +3797,12 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,* page cache that were never cleared. */ if (!folio_test_uptodate (folio)) { -folio_lock (folio); -if (!folio_test_uptodate (folio)) { -folio_zero_range (folio,0 ,folio_size (folio)); -flush_dcache_folio (folio); -folio_mark_uptodate (folio); - } -folio_unlock (folio); +folio_zero_range (folio,0 ,folio_size (folio)); +flush_dcache_folio (folio); +folio_mark_uptodate (folio); } + retry_idx =folio_next_index (folio); +folio_unlock (folio);if (nr_folios ==0 ) *offset =offset_in_folio (folio, start);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/670 iommu/amd: Force device table to maximum size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches pci_seg->dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround.
--- arch/x86/include/asm/cpufeatures.h | 5 +++++ arch/x86/kernel/cpu/amd.c | 6 ++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- tools/arch/x86/include/asm/cpufeatures.h | 5 +++++ 4 files changed, 38 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +5 -0
@@ -483,6 +483,11 @@#define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* Clear branch history at vmexit using SW loop */ #define X86_FEATURE_FAST_CPPC (21*32 + 5)/* AMD Fast CPPC */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 6)/* Use thunk for indirect branches in lower half of cacheline */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* CPU based on Zen6 microarchitecture */ #define X86_FEATURE_TSA_SQ_NO (21*32+11)/* AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* AMD CPU not vulnerable to TSA-L1 */
arch/x86/kernel/cpu/amd.c +6 -0
@@ -531,6 +531,12 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) case 0xd0 ... 0xd7:setup_force_cpu_cap (X86_FEATURE_ZEN5 );break ; + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ;default : goto warn; }
drivers/iommu/amd/init.c +22 -1
@@ -1579,6 +1579,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,return 0 ; } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment (u16 id,struct acpi_table_header *ivrs_base)
@@ -1601,7 +1616,13 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf;DUMP_printk ("PCI segment : 0x%0x, last bdf : 0x%04x\n" , id, last_bdf); - pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , last_bdf); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + pci_seg->dev_table_size =SZ_2M ; + }else { + pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , + last_bdf); + } pci_seg->alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE , last_bdf); pci_seg->rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE , last_bdf);
tools/arch/x86/include/asm/cpufeatures.h +5 -0
@@ -473,6 +473,11 @@#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3)/* BHI_DIS_S HW control enabled */ #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* Clear branch history at vmexit using SW loop */ #define X86_FEATURE_FAST_CPPC (21*32 + 5)/* AMD Fast CPPC */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* CPU based on Zen6 microarchitecture */ /* * BUG word(s)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/670 powerpc/bpf: fix buffer overflow in JIT for large BPF programs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abhishek Dubey <[email protected]>
[ Upstream commit 78ce55b7913a78e1687306668e078b86bc6508ee ]
During size calculation in pass-0, exit_addr is 0 since addrs[fp->len] is not yet populated. bpf_jit_emit_exit_insn() treats a zero exit_addr as in-range and skips bpf_jit_build_epilogue(), so the alternate inline epilogue instructions are not counted in alloclen.
In later passes, if the real exit_addr falls outside the 32MB branch range, the full inline epilogue is emitted into the already-allocated buffer, writing past its end and corrupting adjacent memory.
Fix by ensuring exit_addr is non-zero before treating it as in-range, so pass-0 always falls through to bpf_jit_build_epilogue() and conservatively accounts for all epilogue instructions in alloclen. Also range check alt_exit_addr directly in the else-if condition.
Since exit_addr handling now falls through to the epilogue, two related issues in bpf_int_jit_compile() must also be addressed:
1. Reset cgctx.alt_exit_addr before the second size-calculation pass. Without this, a stale alt_exit_addr from the first pass causes the second pass to emit a single jump instead of the full epilogue, undercounting alloclen and reintroducing the overflow.
2. Recompute addrs[fp->len] at the end of each code-generation pass. The larger pass-0 body can shrink in later passes as out-of-range exits settle into in-range jumps; a stale addrs[fp->len] would leave exit branches targeting past the real (shrunken) epilogue.
Because shrinkage in a later pass can move the epilogue offset, the fixed two-pass loop is no longer sufficient: an exit that was out of range in an earlier pass may fall in range once the epilogue offset shrinks, shrinking the body further and overwriting the start of the epilogue. Convert the code-generation loop to iterate until the program size converges, bounded by CODEGEN_MAX_PASSES, and fail the JIT if it does not converge.
--- arch/powerpc/net/bpf_jit.h | 7 +++++++ arch/powerpc/net/bpf_jit_comp.c | 35 +++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-)
arch/powerpc/net/bpf_jit.h +7 -0
@@ -13,6 +13,13 @@#include <asm/types.h> #include <asm/ppc-opcode.h> +/* +* We need at least 2 passes for proper code generation, and may need +* additional passes if code size changes between passes. +*/ +#define CODEGEN_MIN_PASSES 2 +#define CODEGEN_MAX_PASSES 3 +#ifdef CONFIG_PPC64_ELF_ABI_V1 #define FUNCTION_DESCR_SIZE 24#else
arch/powerpc/net/bpf_jit_comp.c +27 -8
@@ -29,11 +29,10 @@ static void bpf_jit_fill_ill_insns(void *area, unsigned int size)int bpf_jit_emit_exit_insn (u32 *image,struct codegen_context *ctx,int tmp_reg,long exit_addr) { -if (!exit_addr ||is_offset_in_branch_range (exit_addr - (ctx->idx *4 ))) { +if (exit_addr &&is_offset_in_branch_range (exit_addr - (long )(ctx->idx *4 ))) {PPC_JMP (exit_addr); - }else if (ctx->alt_exit_addr) { -if (WARN_ON (!is_offset_in_branch_range ((long )ctx->alt_exit_addr - (ctx->idx *4 )))) -return -1 ; + }else if (ctx->alt_exit_addr &&is_offset_in_branch_range ( + (long )(ctx->alt_exit_addr) - (long )(ctx->idx *4 ))) {PPC_JMP (ctx->alt_exit_addr); }else { ctx->alt_exit_addr = ctx->idx *4 ;
@@ -151,6 +150,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)*/ if (cgctx.seen &SEEN_TAILCALL || !is_offset_in_branch_range ((long )cgctx.idx *4 )) { cgctx.idx =0 ; + cgctx.alt_exit_addr =0 ;if (bpf_jit_build_body (fp,NULL ,NULL , &cgctx, addrs,0 , false)) { fp = org_fp; goto out_addrs;
@@ -187,10 +187,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) code_base = (u32 *)(image +FUNCTION_DESCR_SIZE ); fcode_base = (u32 *)(fimage +FUNCTION_DESCR_SIZE ); -/* Code generation passes 1-2 */ -for (pass =1 ; pass <3 ; pass++) { +/* Code generation passes 1-2+, loop until program size converges. */ +for (pass =1 ; pass <=CODEGEN_MAX_PASSES ; pass++) { +u32 prev_proglen = proglen; +/* Now build the prologue, body code & epilogue for real. */ cgctx.idx =0 ; + cgctx.exentry_idx =0 ; cgctx.alt_exit_addr =0 ;bpf_jit_build_prologue (code_base, &cgctx); if (bpf_jit_build_body(fp, code_base, fcode_base, &cgctx, addrs, pass,
@@ -200,11 +203,27 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) fp = org_fp; goto out_addrs; } + addrs[fp->len] = cgctx.idx *4 ;bpf_jit_build_epilogue (code_base, &cgctx); + proglen = cgctx.idx *4 ; +if (bpf_jit_enable >1 )pr_info ("Pass %d: shrink = %d, seen = 0x%x\n" , pass, - proglen - (cgctx.idx *4 ), cgctx.seen); + prev_proglen - proglen, cgctx.seen); + +/* Check if program size has converged, but ensure minimum passes */ +if (pass >=CODEGEN_MIN_PASSES && proglen == prev_proglen) +break ; + +if (pass ==CODEGEN_MAX_PASSES && proglen != prev_proglen) { +pr_err ("BPF JIT: Program did not converge after %d passes\n" , +CODEGEN_MAX_PASSES ); +bpf_arch_text_copy (&fhdr->size, &hdr->size,sizeof (hdr->size)); +bpf_jit_binary_pack_free (fhdr, hdr); + fp = org_fp; + goto out_addrs; + } }if (bpf_jit_enable >1 )
@@ -264,7 +283,7 @@ int bpf_add_extable_entry(struct bpf_prog *fp, u32 *image, u32 *fimage, int passu32 *fixup;/* Populate extable entries only in the last pass */ -if (pass !=2 ) +if (pass <CODEGEN_MIN_PASSES )return 0 ; if (!fp->aux->extable ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/670 batman-adv: Limit number of aggregated packets directly
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 434becf57bdc89f939db635ed3337b9d1da5967e upstream.
The currently selected size in BATADV_MAX_AGGREGATION_BYTES (512) is chosen such that the number of possible aggregated packets is lower than 32. This number must be limited so that the type of batadv_forw_packet->direct_link_flags has enough bits to represent each packet (with the size of at least 24 bytes).
This requirement is better implemented in code instead of having it inside a comment.
--- net/batman-adv/bat_iv_ogm.c | 4 ++++ net/batman-adv/main.h | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)
net/batman-adv/bat_iv_ogm.c +4 -0
@@ -449,6 +449,7 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,struct batadv_ogm_packet *batadv_ogm_packet;int aggregated_bytes = forw_packet->packet_len + packet_len;struct batadv_hard_iface *primary_if =NULL ; +u8 packet_num = forw_packet->num_packets +1 ;bool res = false;unsigned long aggregation_end_time;
@@ -474,6 +475,9 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,if (aggregated_bytes >BATADV_MAX_AGGREGATION_BYTES )return false; +if (packet_num >=BITS_PER_TYPE (forw_packet->direct_link_flags)) +return false; +/* packet is not leaving on the same interface. */ if (forw_packet->if_outgoing != if_outgoing)return false;
net/batman-adv/main.h +0 -3
@@ -102,9 +102,6 @@*/ #define BATADV_TQ_SIMILARITY_THRESHOLD 50 -/* should not be bigger than 512 bytes or change the size of -* forw_packet->direct_link_flags -*/ #define BATADV_MAX_AGGREGATION_BYTES 512#define BATADV_MAX_AGGREGATION_MS 100
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/670 batman-adv: Close OGM aggregation before transmission
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit f91f64a91682c07e6c5f059804e709656364e8a6 upstream.
The OGM send worker leaves its forwarding packet on forw_bat_list until after batadv_iv_ogm_emit() returns. Aggregation holds forw_bat_list_lock, but emission reads and clones the packet without that lock.
CPU 0 can therefore start emitting a queued packet while CPU 1 takes the list lock, finds the same packet and appends another OGM. The sender can observe the new packet length before the corresponding direct-link flag is set, or clone the skb while its length and payload are being updated. This can transmit an OGM with incorrect flags or inconsistent data.
KCSAN reported:
BUG: KCSAN: data-race in batadv_iv_ogm_queue_add / batadv_iv_send_outstanding_bat_ogm_packet write to 0xffff888100fedcf8 of 2 bytes by interrupt on cpu 1: read to 0xffff888100fedcf8 of 2 bytes by task 70 on cpu 2: value changed: 0x00c0 -> 0x00d8
Mark the aggregate as full under forw_bat_list_lock before emission. This waits for any ongoing append and prevents further aggregation. Emission uses packet_len to walk the OGMs, so all queued packets are still sent. Keep the packet on the list so interface purging can find the worker, wait for it to finish and free the packet.
--- net/batman-adv/bat_iv_ogm.c | 5 +++++ net/batman-adv/types.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +5 -0
@@ -1793,6 +1793,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } +/* Mark aggregate as full before forcing emit. */ +spin_lock_bh (&bat_priv->forw_bat_list_lock); + forw_packet->num_packets =BITS_PER_TYPE (forw_packet->direct_link_flags); +spin_unlock_bh (&bat_priv->forw_bat_list_lock); +batadv_iv_ogm_emit (forw_packet);/* we have to have at least one packet in the queue to determine the
net/batman-adv/types.h +7 -1
@@ -2208,7 +2208,13 @@ struct batadv_forw_packet {/** @direct_link_flags: direct link flags for aggregated OGM packets */ u32 direct_link_flags; -/** @num_packets: counter for aggregated OGMv1 packets */ +/** +* @num_packets: counter for aggregated OGMv1 packets. Set to +* BITS_PER_TYPE(forw_packet->direct_link_flags) (independent of the +* real number of aggregated packets) by the send worker to prevent +* further aggregation while the packet is emitted. It must therefore +* not be used to iterate over the aggregated packets +*/ u8 num_packets;/** @delayed_work: work queue callback item for packet sending */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/670 batman-adv: tpmeter: fix u32 truncation of reported bytes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 1025b76d13288a311e8259a0eefde0854fa63c41 upstream.
When more than 4 GB are transferred by the throughput meter, batadv_tp_batctl_notify() will cut of the upper 32 bit of the u64 counter and thus under-report the actual transferred bytes.
The data type of the temporary storage variable must therefore still continue to use u64.
--- net/batman-adv/tp_meter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/tp_meter.c +1 -1
@@ -226,9 +226,9 @@ static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason, unsigned long start_time, u64 total_sent, u32 cookie) { + u64 total_bytes;u32 test_time;u8 result; -u32 total_bytes;if (!batadv_tp_is_error (reason)) { result =BATADV_TP_REASON_COMPLETE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/670 batman-adv: tt: only transmit local ROAM flag together with DEL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 10f24f058417024a2c19cb8d88a6a0678a58a21b upstream.
BATADV_TT_CLIENT_ROAM is part of BATADV_TT_REMOTE_MASK but on the wire it only has a defined meaning together with BATADV_TT_CLIENT_DEL: the originator no longer serves the client because it roamed to another node. Such a DEL is only relevant for events (non-full table requests).
An ADD carrying ROAM is processed (by accident) by the receiver like aROAMING_ADV: a newly created global entry is marked as roaming and is excluded from the global CRC. But the sender includes it in its local CRC.
But such a behavior doesn't make sense for non-ROAM_ADV because a new TTVN is meant as announced commit of the local TT table of a node and should therefore not be used to create a temporary (roam) global entry in a node.
At the moment, such an ADD with the BATADV_TT_CLIENT_ROAM flag set can happen due to two mechanisms:
batadv_tt_local_valid() copies all flags of the local entry into a full table response. It is not synchronized with batadv_tt_local_mark_removed(). An entry which was marked as ROAM|PENDING by a ROAMING_ADV is still part of the current TTVN and is sent with the ROAM flag set. The receivers then create a roaming global entry for it and detect a CRC mismatch, which causes them to request the full table again.
The same can happen for an ADD change which is queued for an entry which (still) has the ROAM flag set. For example when only the dynamic WIFI or ISOLA flags were updated.
It is not triggered by batadv_send_other_tt_response() because batadv_tt_global_valid() is already taking care of filtering out BATADV_TT_CLIENT_ROAM entries.
For the two problematic announcement mechanism, only send the ROAM flag of local entries together with a DEL.
This only fixes the ROAM marking of the global entry and the resulting CRC mismatch. When the requester of the full table is the node which sent the ROAMING_ADV, the still announced entry will (independent of the ROAM flag) cause batadv_tt_global_purge_local() to remove the requester's own (new) local entry for the client. This is not addressed here.
--- net/batman-adv/translation-table.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/batman-adv/translation-table.c +14 -2
@@ -470,7 +470,6 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,if (!tt_change_node)return ; - tt_change_node->change.flags = flags;memset (tt_change_node->change.reserved,0 ,sizeof (tt_change_node->change.reserved));ether_addr_copy (tt_change_node->change.addr, common->addr);
@@ -478,6 +477,15 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, del_op_requested = flags &BATADV_TT_CLIENT_DEL ; +/* the ROAM flag is only meaningful for the receiver in combination +* with a DEL. An ADD with ROAM would be interpreted as a roaming +* advertisement +*/ +if (!del_op_requested) + flags &= ~BATADV_TT_CLIENT_ROAM ; + + tt_change_node->change.flags = flags; +/* check for ADD+DEL or DEL+ADD events */ spin_lock_bh (&bat_priv->tt.changes_list_lock); list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
@@ -2757,8 +2765,12 @@ static bool batadv_tt_local_valid(const void *entry_ptr,if (tt_common_entry->flags &BATADV_TT_CLIENT_NEW )return false; +/* the entry is (still) announced. A ROAM flag of an entry which is +* pending to be removed must not be transmitted. Otherwise, the +* receiver would handle it like a roaming advertisement +*/ if (flags) - *flags = tt_common_entry->flags; + *flags = tt_common_entry->flags & ~BATADV_TT_CLIENT_ROAM ;return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/670 batman-adv: tt: clear ROAM flag when re-adding a pending local client
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit cc2186d7854785b30d423f5d43757b086b300e55 upstream.
When a ROAMING_ADV is received for an announced local client, batadv_tt_local_mark_removed() sets BATADV_TT_CLIENT_ROAM, queues a DEL|ROAM change and marks the entry as BATADV_TT_CLIENT_PENDING. If the client sends a frame again before the next TTVN commit, batadv_tt_local_add_existing() only clears the PENDING flag and returns early. The ADD cancels the queued DEL, but the entry keeps the ROAM flag:
* batadv_is_my_client() reports the client as not served by this node
* batadv_tt_local_client_is_roaming() reroutes unicast frames for it to the node which sent the ROAMING_ADV
The ROAM flag is only removed with the next frame of the client.
Since BATADV_TT_CLIENT_ROAM is set together with BATADV_TT_CLIENT_PENDING, it has to be cleared also at the same time with BATADV_TT_CLIENT_PENDING when the client roamed back.
--- net/batman-adv/translation-table.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +6 -3
@@ -658,6 +658,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,int hash_added, table_size, packet_size_max;bool ret = false;bool roamed_back = false; +bool added = false;u8 remote_flags;u32 match_mark;
@@ -684,7 +685,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,* flag can be reset like it was never enqueued */ tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING ; - goto add_event; + added = true; }if (tt_local->common.flags &BATADV_TT_CLIENT_ROAM ) {
@@ -765,10 +766,12 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr, goto out; } -add_event: -batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); + added = true; check_roaming: +if (added) +batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); +/* Check whether it is a roaming, but don't do anything if the roaming * process has already been handled */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/670 batman-adv: tt: send ROAM_ADV on each roamed back client
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit aff4d5d10f2dcb4a9b604e27414dafa1d51b6406 upstream.
When a ROAMING_ADV is received for an announced local client, batadv_roam_tvlv_unicast_handler_v1() creates a global entry with the BATADV_TT_CLIENT_ROAM flag set.
If the client sends a frame again before the next TTVN commit, batadv_tt_local_add_roam() is expected to announce this return via a ROAM_ADV frame. But this doesn't happen because the global entry (created by the first ROAMING_ADV) carries BATADV_TT_CLIENT_ROAM until the new originator announces the client.
Let batadv_tt_local_add_roam() always handle a roamed back client - independent of the ROAM flag of the global entry:
* trigger sending of the ROAM_ADV frame(s)
* remove the (with the roaming) associated global entry
--- net/batman-adv/translation-table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/translation-table.c +2 -1
@@ -775,7 +775,8 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,/* Check whether it is a roaming, but don't do anything if the roaming * process has already been handled */ -if (tt_global && !(tt_global->common.flags &BATADV_TT_CLIENT_ROAM )) { +if (tt_global && + (roamed_back || !(tt_global->common.flags &BATADV_TT_CLIENT_ROAM ))) {/* These node are probably going to update their tt table */ head = &tt_global->orig_list;rcu_read_lock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/670 batman-adv: tt: ignore ROAM flag of received ADD changes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit c5d68abe6e7f1dbd132a602cb696fe1fff0389eb upstream.
A received TT change (OGM diff or full table response) with the ROAM flag but without DEL is handled by batadv_tt_global_add() like a ROAMING_ADV:
* a newly created global entry gets BATADV_TT_CLIENT_ROAM and is therefore excluded from the global CRC. The sender has it in its local CRC and the receiver has to request the full table again
* batadv_tt_global_purge_local() removes the local entry of the receiver. The receiver's own client is considered as roamed to the sender and frames for it are rerouted
The ROAM flag only has a meaning together with DEL. Drop it on reception to keep it from populating the global table with a temporary ROAMING entry which is not part of the CRC - and therefore causing a CRC mismatch.
--- net/batman-adv/translation-table.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +12 -3
@@ -3339,20 +3339,29 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv, {int i;int roams; +u8 flags;for (i =0 ; i < tt_num_changes; i++) { -if ((tt_change + i)->flags &BATADV_TT_CLIENT_DEL ) { - roams = (tt_change + i)->flags &BATADV_TT_CLIENT_ROAM ; + flags = (tt_change + i)->flags; + +if (flags &BATADV_TT_CLIENT_DEL ) { + roams = flags &BATADV_TT_CLIENT_ROAM ;batadv_tt_global_del (bat_priv, orig_node, (tt_change + i)->addr,ntohs ((tt_change + i)->vid),"tt removed by changes" , roams); }else { +/* an announced client cannot have roamed away from +* orig_node. Only a ROAMING_ADV is allowed to add a +* global entry with the ROAM flag +*/ + flags &= ~BATADV_TT_CLIENT_ROAM ; +if (!batadv_tt_global_add (bat_priv, orig_node, (tt_change + i)->addr,ntohs ((tt_change + i)->vid), - (tt_change + i)->flags, ttvn)) + flags, ttvn))/* In case of problem while storing a * global_entry, we stop the updating * procedure without committing the
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/670 batman-adv: tt: only update flags for TT events
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit ad1fd828aa3944efc393b84b0d7c02483f1b5638 upstream.
In the first implementation of the translation table events, it was only possible to announce:
* ADD: new locally detected client
* DEL: disappeared local client
If an ADD event was queued and then a DEL event was queued in the same timeslot, it is valid to destroy both events because nothing actually changed for remode nodes
But with commit 3c4f7ab60cc2 ("batman-adv: improve the TT component to support runtime flag changes") and subsequent changes, it could also happen that there are extra ADD events:
* ADD: _NEW_ locally detected client
* ADD: already existing client with new flags
* DEL: disappeared local client
The first and the last type of event could in theory still be removed together from the (to be announced) events queue. But if the "update flags" ADD is dropped together with the DEL, it would still leave global translation table of a remote node in the incorrect state - believing that the client didn't disappear.
If a detected client was previously announced, a DEL event must only overwrite the "update flags" ADD but the DEL itself must still continue to exist in the (to be anounced) events queue. For now, adjustment of the announced flags is used for everything instead of dropping already queued up events completely.
Similarly, a DEL followed by an ADD caused both entries to be deleted. But the new ADD could announce flags changes which were not yet present for the client before it was marked for DELetion. The new ADD must therefore only overwrite the DEL - but still be kept.
--- net/batman-adv/translation-table.c | 41 ++++++++---------------------- 1 file changed, 11 insertions(+), 30 deletions(-)
net/batman-adv/translation-table.c +11 -30
@@ -455,6 +455,9 @@ batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry)* @bat_priv: the bat priv with all the soft interface information * @tt_local_entry: the TT entry involved in the event * @event_flags: flags to store in the event structure +* +* Only a single change per client is queued. It describes the latest state of +* the client and a new event therefore replaces an already queued one. */ static void batadv_tt_local_event(struct batadv_priv *bat_priv, struct batadv_tt_local_entry *tt_local_entry,
@@ -463,8 +466,7 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,struct batadv_tt_change_node *tt_change_node, *entry, *safe;struct batadv_tt_common_entry *common = &tt_local_entry->common;u8 flags = common->flags | event_flags; -bool event_removed = false; -bool del_op_requested, del_op_entry; +bool del_op_requested; tt_change_node =kmem_cache_alloc (batadv_tt_change_cache,GFP_ATOMIC );if (!tt_change_node)
@@ -496,44 +498,23 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,if (entry->change.vid != tt_change_node->change.vid)continue ; -/* DEL+ADD in the same orig interval have no effect and can be -* removed to avoid silly behaviour on the receiver side. The -* other way around (ADD+DEL) can happen in case of roaming of -* a client still in the NEW state. Roaming of NEW clients is -* now possible due to automatically recognition of "temporary" -* clients -*/ - del_op_entry = entry->change.flags &BATADV_TT_CLIENT_DEL ; -if (!del_op_requested && del_op_entry) - goto del; -if (del_op_requested && !del_op_entry) - goto del; - -/* this is a second add in the same originator interval. It -* means that flags have been changed: update them! +/* the other nodes may know the client with different +* flags. A DEL+ADD must therefore still announce the +* current flags and an ADD+DEL must still remove the +* client. ADD+ADD and DEL+DEL only update the flags */ -if (!del_op_requested && !del_op_entry) - entry->change.flags = flags; - -continue ; -del: -list_del (&entry->list); -kmem_cache_free (batadv_tt_change_cache, entry); + entry->change.flags = flags;kmem_cache_free (batadv_tt_change_cache, tt_change_node); - event_removed = true; + goto unlock; }/* track the change in the OGMinterval list */ list_add_tail (&tt_change_node->list, &bat_priv->tt.changes_list); +atomic_inc (&bat_priv->tt.local_changes); unlock:spin_unlock_bh (&bat_priv->tt.changes_list_lock); - -if (event_removed) -atomic_dec (&bat_priv->tt.local_changes); -else -atomic_inc (&bat_priv->tt.local_changes); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/670 batman-adv: tt: dont drop local events queued during TVLV update
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit ed7a0dfdd370acb48be7a281df732c1bebcc7f1d upstream.
batadv_tt_tvlv_container_update() read the number of local changes without holding changes_list_lock. batadv_tt_local_event() is not serialized by the commit_lock and can queue new events before the changes_list is flushed:
CPU0 CPU1
batadv_tt_tvlv_container_update()
num = ...local_changes;
batadv_tt_local_event()
list_add_tail(...);
...local_changes++;
spin_lock_bh(&...changes_list_lock);
/* only num events copied but all freed */The additional events were freed without ever being sent. Other nodes will only notice this via a CRC mismatch and must request the full table.
The number of changes and the changes_list must therefore be taken atomically. Events queued afterwards then stay in the tt.changes_list for the next TT round.
The changes can no longer be kept for the next round when the TVLV buffer allocation fails. But they would be sent with a skipped TTVN anyway, so the other nodes have to request the full table in this case either way. The last changeset is only dropped in this case when the TTVN was incremented. Without new changes, it still describes the current TTVN.
Previously, the unconsumed changes caused a retry of the TVLV container update in the next commit round. Since the changes are now consumed, the next round would only take the path without changes and wait for BATADV_TT_OGM_APPEND_MAX rounds before updating the container again. Until then, the outdated container with the previous TTVN would still be announced. The ogm_append_cnt is therefore reset on failure to retry the update in the next OGM interval.
This doesn't make the CRC consistent with the announced changeset. The local table modifications are still not serialized with the commit and batadv_tt_local_transition_new() can still make a client part of the CRC for which the event is only part of the next TT round. Such an inconsistency is detected by the CRC check of the other nodes and solved via a full table request.
[ Context, switch to old "mesh_iface" name "soft_iface", access
local_changes with atomic_t helpers ]
--- net/batman-adv/translation-table.c | 61 +++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 13 deletions(-)
net/batman-adv/translation-table.c +48 -13
@@ -1019,20 +1019,22 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,* batadv_tt_tvlv_container_update() - update the translation table tvlv * container after local tt changes have been committed * @bat_priv: the bat priv with all the soft interface information +* @changes_list: list of committed changes which will be consumed +* @tt_diff_entries_num: number of entries in @changes_list */ -static void batadv_tt_tvlv_container_update (struct batadv_priv *bat_priv) +static void batadv_tt_tvlv_container_update (struct batadv_priv *bat_priv, +struct list_head *changes_list, +int tt_diff_entries_num) {struct batadv_tt_change_node *entry, *safe;struct batadv_tvlv_tt_data *tt_data;struct batadv_tvlv_tt_change *tt_change;int tt_diff_len, tt_change_len =0 ; -int tt_diff_entries_num =0 ;int tt_diff_entries_count =0 ;bool drop_changes = false;size_t tt_extra_len =0 ;u16 tvlv_len; - tt_diff_entries_num =atomic_read (&bat_priv->tt.local_changes); tt_diff_len =batadv_tt_len (tt_diff_entries_num);/* if we have too many changes for one packet don't send any
@@ -1050,19 +1052,39 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tvlv_len =batadv_tt_prepare_tvlv_local_data (bat_priv, &tt_data, &tt_change, &tt_diff_len); -if (!tvlv_len) +if (!tvlv_len) { +/* the changes are lost and the other nodes have to request the +* full table. Don't answer TT requests for the new TTVN with +* the stale changeset of the previous TTVN. Without changes, the +* TTVN was not incremented and the last changeset is still valid +*/ +if (drop_changes || tt_diff_entries_num >0 ) { +list_for_each_entry_safe (entry, safe, changes_list, + list) { +list_del (&entry->list); +kmem_cache_free (batadv_tt_change_cache, entry); + } + +spin_lock_bh (&bat_priv->tt.last_changeset_lock); +kfree (bat_priv->tt.last_changeset); + bat_priv->tt.last_changeset =NULL ; + bat_priv->tt.last_changeset_len =0 ; +spin_unlock_bh (&bat_priv->tt.last_changeset_lock); + } + +/* announce the already committed TTVN in the next OGM interval +* instead of waiting for BATADV_TT_OGM_APPEND_MAX idle rounds +*/ +atomic_set (&bat_priv->tt.ogm_append_cnt,0 );return ; + } tt_data->flags =BATADV_TT_OGM_DIFF ;if (!drop_changes && tt_diff_len ==0 ) goto container_register; -spin_lock_bh (&bat_priv->tt.changes_list_lock); -atomic_set (&bat_priv->tt.local_changes,0 ); - -list_for_each_entry_safe (entry, safe, &bat_priv->tt.changes_list, - list) { +list_for_each_entry_safe (entry, safe, changes_list, list) {if (tt_diff_entries_count < tt_diff_entries_num) { memcpy(tt_change + tt_diff_entries_count, &entry->change,
@@ -1072,7 +1094,6 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)list_del (&entry->list);kmem_cache_free (batadv_tt_change_cache, entry); } -spin_unlock_bh (&bat_priv->tt.changes_list_lock); tt_extra_len =batadv_tt_len (tt_diff_entries_num - tt_diff_entries_count);
@@ -3761,11 +3782,25 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)*/ static void batadv_tt_local_commit_changes_nolock (struct batadv_priv *bat_priv) { +LIST_HEAD (changes_list); +int changes_num; +lockdep_assert_held (&bat_priv->tt.commit_lock); -if (atomic_read (&bat_priv->tt.local_changes) <1 ) { +/* atomically get the list of changes. The TTVN decision and the +* announced changeset must cover the same events. Events queued +* afterwards stay in the tt.changes_list for the next TT round +*/ +spin_lock_bh (&bat_priv->tt.changes_list_lock); +list_splice_init (&bat_priv->tt.changes_list, &changes_list); + changes_num =atomic_read (&bat_priv->tt.local_changes); +atomic_set (&bat_priv->tt.local_changes,0 ); +spin_unlock_bh (&bat_priv->tt.changes_list_lock); + +if (changes_num ==0 ) {if (!batadv_atomic_dec_not_zero (&bat_priv->tt.ogm_append_cnt)) -batadv_tt_tvlv_container_update (bat_priv); +batadv_tt_tvlv_container_update (bat_priv, &changes_list, + changes_num);return ; }
@@ -3782,7 +3817,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)/* reset the sending counter */ atomic_set (&bat_priv->tt.ogm_append_cnt,BATADV_TT_OGM_APPEND_MAX ); -batadv_tt_tvlv_container_update (bat_priv); +batadv_tt_tvlv_container_update (bat_priv, &changes_list, changes_num); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/670 lib/crypto: mips: Disable Octeon SHA code on little-endian kernels
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit dd2a4edb26e1c78823c50ba10c42f2d3de2e5ec4 upstream.
Kernels built for the MIPS64-based Cavium Octeon SoCs are normally big-endian, but little-endian builds are also supported. Currently, the SHA-1, SHA-256, and SHA-512 code using the Octeon crypto co-processor is enabled in both builds.
This code is untestable without the hardware. However, based on the code itself, it is implausible that it computes hash values correctly in little-endian builds. Such builds write many incorrect values to COP2:
- SHA-1 and SHA-256: The 64-bit integer that contains the last two 32-bit message words of each block is written to COP2 entirely byte-reflected, due to missing endianness conversion in octeon_sha1_start() and octeon_sha256_start() to compensate for using native 64-bit loads from the message bytes. This differs from all the earlier message words which are written correctly.
Furthermore, the state is written to COP2 with each 32-bit word byte-reflected within each 64-bit integer, due to incorrect use of 64-bit endianness conversion in write_octeon_64bit_hash_dword() when the state is kept in memory in native-endian 32-bit words.
- SHA-512: All the 64-bit message words are written to COP2 byte-reflected, due to missing endianness conversion in write_octeon_64bit_block_sha512() and octeon_sha512_start(). The SHA-512 state words seem to be written correctly.
Big-endian kernels aren't affected by these bugs. These bugs also aren't new; this code has been broken on little-endian ever since it and Octeon little-endian support were first added in v4.1.
Commit d2a948d2db68 ("MIPS: Octeon: Make octeon-md5 driver endian-agnostic") made the MD5 code work on little-endian kernels by adding 64-bit endianness conversions to the COP2 macros used by MD5 (some of which are shared by SHA-1 and SHA-256, despite those algorithms keeping the state words in native-endian instead of MD5's little-endian, causing some of the strange behavior described above). However, SHA-1, SHA-256, and SHA-512 were never fixed to work on little-endian kernels.
Therefore, disable the Octeon SHA-1, SHA-256, and SHA-512 code in little-endian kernels. This causes the generic code that actually computes hash values correctly to be used instead.
--- arch/mips/crypto/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/mips/crypto/Kconfig +3 -3
@@ -34,7 +34,7 @@ config CRYPTO_MD5_OCTEON config CRYPTO_SHA1_OCTEON tristate "Hash functions: SHA-1 (OCTEON)" - depends on CPU_CAVIUM_OCTEON + depends on CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN select CRYPTO_SHA1 select CRYPTO_HASH help
@@ -44,7 +44,7 @@ config CRYPTO_SHA1_OCTEON config CRYPTO_SHA256_OCTEON tristate "Hash functions: SHA-224 and SHA-256 (OCTEON)" - depends on CPU_CAVIUM_OCTEON + depends on CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN select CRYPTO_SHA256 select CRYPTO_HASH help
@@ -54,7 +54,7 @@ config CRYPTO_SHA256_OCTEON config CRYPTO_SHA512_OCTEON tristate "Hash functions: SHA-384 and SHA-512 (OCTEON)" - depends on CPU_CAVIUM_OCTEON + depends on CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN select CRYPTO_SHA512 select CRYPTO_HASH help
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/670 mm: replace free hugepage folios after migration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: yangge <[email protected]>
[ Upstream commit 04f13d241b8b146b23038bffd907cb8278391d07 ]
My machine has 4 NUMA nodes, each equipped with 32GB of memory. I have configured each NUMA node with 16GB of CMA and 16GB of in-use hugetlb pages. The allocation of contiguous memory via cma_alloc() can fail probabilistically.
When there are free hugetlb folios in the hugetlb pool, during the migration of in-use hugetlb folios, new folios are allocated from the free hugetlb pool. After the migration is completed, the old folios are released back to the free hugetlb pool instead of being returned to the buddy system. This can cause test_pages_isolated() check to fail, ultimately leading to the failure of cma_alloc().
Call trace:
cma_alloc()
__alloc_contig_migrate_range() // migrate in-use hugepage test_pages_isolated()
__test_page_isolated_in_pageblock()
PageBuddy(page) // check if the page is in buddy
To address this issue, we introduce a function named replace_free_hugepage_folios(). This function will replace the hugepage in the free hugepage pool with a new one and release the old one to the buddy system. After the migration of in-use hugetlb pages is completed, we will invoke replace_free_hugepage_folios() to ensure that these hugepages are properly released to the buddy system. Following this step, when test_pages_isolated() is executed for inspection, it will successfully pass.
Additionally, when alloc_contig_range() is used to migrate multiple in-use hugetlb pages, it can result in some in-use hugetlb pages being released back to the free hugetlb pool and subsequently being reallocated and used again. For example:
[huge 0] [huge 1]
To migrate huge 0, we obtain huge x from the pool. After the migration is completed, we return the now-freed huge 0 back to the pool. When it's time to migrate huge 1, we can simply reuse the now-freed huge 0 from the pool. As a result, when replace_free_hugepage_folios() is executed, it cannot release huge 0 back to the buddy system. To address this issue, we should prevent the reuse of isolated free hugepages during the migration process.
--- include/linux/hugetlb.h | 7 +++++++ mm/hugetlb.c | 42 +++++++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 12 +++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-)
include/linux/hugetlb.h +7 -0
@@ -687,6 +687,7 @@ struct huge_bootmem_page {int isolate_or_dissolve_huge_page (struct page *page,struct list_head *list);void wait_for_freed_hugetlb_folios (void ); +int replace_free_hugepage_folios (unsigned long start_pfn,unsigned long end_pfn);struct folio *alloc_hugetlb_folio (struct vm_area_struct *vma,unsigned long addr,bool cow_from_owner); struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid,
@@ -1078,6 +1079,12 @@ static inline void wait_for_freed_hugetlb_folios(void) { } +static inline int replace_free_hugepage_folios (unsigned long start_pfn, +unsigned long end_pfn) +{ +return 0 ; +} +static inline struct folio *alloc_hugetlb_folio (struct vm_area_struct *vma,unsigned long addr,bool cow_from_owner)
mm/hugetlb.c +42 -0
60 lines not on this page · raw message
mm/page_alloc.c +11 -1
@@ -6743,7 +6743,17 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end, ret =__alloc_contig_migrate_range (&cc, start, end, migratetype);if (ret && ret != -EBUSY ) goto done; - ret =0 ; + +/* +* When in-use hugetlb pages are migrated, they may simply be released +* back into the free hugepage pool instead of being returned to the +* buddy system. After the migration of in-use huge pages is completed, +* we will invoke replace_free_hugepage_folios() to ensure that these +* hugepages are properly released to the buddy system. +*/ + ret =replace_free_hugepage_folios (start, end); +if (ret) + goto done;/* * Pages from [start, end) are within a pageblock_nr_pages
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/670 mm/hugetlb: fix kernel NULL pointer dereference when replacing free hugetlb folios
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ge Yang <[email protected]>
[ Upstream commit 113ed54ad276c352ee5ce109bdcf0df118a43bda ]
A kernel crash was observed when replacing free hugetlb folios:
BUG: kernel NULL pointer dereference, address: 0000000000000028 PGD 0 P4D 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 28 UID: 0 PID: 29639 Comm: test_cma.sh Tainted 6.15.0-rc6-zp #41 PREEMPT(voluntary) RIP: 0010:alloc_and_dissolve_hugetlb_folio+0x1d/0x1f0 RSP: 0018:ffffc9000b30fa90 EFLAGS: 00010286 RAX: 0000000000000000 RBX: 0000000000342cca RCX: ffffea0043000000 RDX: ffffc9000b30fb08 RSI: ffffea0043000000 RDI: 0000000000000000 RBP: ffffc9000b30fb20 R08: 0000000000001000 R09: 0000000000000000 R10: ffff88886f92eb00 R11: 0000000000000000 R12: ffffea0043000000 R13: 0000000000000000 R14: 00000000010c0200 R15: 0000000000000004 FS: 00007fcda5f14740(0000) GS:ffff8888ec1d8000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000028 CR3: 0000000391402000 CR4: 0000000000350ef0 Call Trace: <TASK> replace_free_hugepage_folios+0xb6/0x100 alloc_contig_range_noprof+0x18a/0x590 ? srso_return_thunk+0x5/0x5f ? down_read+0x12/0xa0 ? srso_return_thunk+0x5/0x5f cma_range_alloc.constprop.0+0x131/0x290 __cma_alloc+0xcf/0x2c0 cma_alloc_write+0x43/0xb0 simple_attr_write_xsigned.constprop.0.isra.0+0xb2/0x110 debugfs_attr_write+0x46/0x70 full_proxy_write+0x62/0xa0 vfs_write+0xf8/0x420 ? srso_return_thunk+0x5/0x5f ? filp_flush+0x86/0xa0 ? srso_return_thunk+0x5/0x5f ? filp_close+0x1f/0x30 ? srso_return_thunk+0x5/0x5f ? do_dup2+0xaf/0x160 ? srso_return_thunk+0x5/0x5f ksys_write+0x65/0xe0 do_syscall_64+0x64/0x170 entry_SYSCALL_64_after_hwframe+0x76/0x7e
There is a potential race between __update_and_free_hugetlb_folio() and replace_free_hugepage_folios():
CPU1 CPU2__update_and_free_hugetlb_folio replace_free_hugepage_folios
folio_test_hugetlb(folio) -- It's still hugetlb folio.
__folio_clear_hugetlb(folio) hugetlb_free_folio(folio)
h = folio_hstate(folio) -- Here, h is NULL pointer
When the above race condition occurs, folio_hstate(folio) returns NULL, and subsequent access to this NULL pointer will cause the system to crash. To resolve this issue, execute folio_hstate(folio) under the protection of the hugetlb_lock lock, ensuring that folio_hstate(folio) does not return NULL.
--- mm/hugetlb.c | 8 ++++++++ 1 file changed, 8 insertions(+)
mm/hugetlb.c +8 -0
@@ -3012,12 +3012,20 @@ int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn)while (start_pfn < end_pfn) { folio =pfn_folio (start_pfn); + +/* +* The folio might have been dissolved from under our feet, so make sure +* to carefully check the state under the lock. +*/ +spin_lock_irq (&hugetlb_lock);if (folio_test_hugetlb (folio)) { h =folio_hstate (folio); }else { +spin_unlock_irq (&hugetlb_lock); start_pfn++;continue ; } +spin_unlock_irq (&hugetlb_lock);if (!folio_ref_count (folio)) { ret = alloc_and_dissolve_hugetlb_folio(h, folio,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/670 blk-mq: end the request if getting a keyslot fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit e67cb6ed40e7f45912b63d7d575f18dfd2ebc98a upstream.
When blk_crypto_rq_get_keyslot() fails, blk_mq_submit_bio() ends the bio by hand and frees the request. By then blk_mq_bio_to_request() has done the IO accounting, which blk_mq_free_request() doesn't undo, so the in_flight counter never drops and iostat shows a device that is 100% busy. If the bio went through zone write plugging the zone stays plugged as well, and every later write to it waits forever.
Use blk_mq_end_request() like the dispatch path does for a request the driver rejected, after marking it for zone write plugging.
Move the call to blk_zone_write_plug_init_request() before blk_crypto_rq_get_keyslot() so that it doesn't need to be duplicated. It doesn't depend on the keyslot.
--- block/blk-mq.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
block/blk-mq.c +4 -6
@@ -3122,17 +3122,15 @@ void blk_mq_submit_bio(struct bio *bio)blk_mq_bio_to_request (rq, bio, nr_segs); +if (bio_zone_write_plugging (bio)) +blk_zone_write_plug_init_request (rq); + ret =blk_crypto_rq_get_keyslot (rq);if (ret !=BLK_STS_OK ) { - bio->bi_status = ret; -bio_endio (bio); -blk_mq_free_request (rq); +blk_mq_end_request (rq, ret);return ; } -if (bio_zone_write_plugging (bio)) -blk_zone_write_plug_init_request (rq); -if (op_is_flush (bio->bi_opf) &&blk_insert_flush (rq))return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/670 Bluetooth: hci_sync: pause advertising for the scan address update
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valentin Kindschi <[email protected]>
[ Upstream commit 56ed6b127a27c418dc2daa3fd076539d8fe69c4c ]
hci_active_scan_sync() programs a non-resolvable private address with LE Set Random Address on every active scan start.
BLUETOOTH CORE SPECIFICATION Vol 4, Part E, 7.8.4 says the controller shall return Command Disallowed (0x0C) for that command while legacy advertising or scanning is enabled. hci_pause_addr_resolution(), called just above, only stops advertising when LL privacy is in use, so on a controller without it the command is issued while advertising is still on:
Bluetooth: hci0: Opcode 0x2005 failed: -16
It does not converge either. hdev->random_addr is only set on a successful command complete, so it stays BDADDR_ANY, and the deferral added by commit c2994b008492 ("Bluetooth: hci_sync: Fix not setting Random Address when required") requires it to be set. Unlike the resolvable address a few lines above, which is reused while rpa_valid(), the non-resolvable one is regenerated and rewritten on every call, so a controller that refuses the write is asked again at the scan restart period of about 10 s, for as long as discovery keeps restarting. Observed on a BCM43455, which has no LL privacy and no extended advertising, 190 rejections in one capture, every one retrying the same address:
< LE Set Random Address Address: 02:16:91:90:F1:D4 (Non-Resolvable) > Command Complete LE Set Random Address, Command Disallowed < LE Set Random Address Address: 26:90:57:96:9A:3E (Non-Resolvable) > Command Complete LE Set Random Address, Command Disallowed
Pause advertising for the address update, and resume it once the update is done and before the scan is started. The pause does not outlive the
function: it is taken only when nothing else holds it, and every exit resumes advertising, which also releases the pause taken by hci_pause_addr_resolution(). A failed pause returns before marking anything paused, so the error path is a no-op.
The resume in the error path is no longer guarded by ll_privacy_capable(). That guard matched a pause taken only under LL privacy; the pause added here is unconditional, and hci_resume_advertising_sync() returns early when nothing was paused.
One caveat this widens, raised on the previous posting. When HCI_ADVERTISING is set, hci_pause_advertising_sync() also clears HCI_DISCOVERABLE and HCI_LIMITED_DISCOVERABLE and zeroes discov_timeout, and hci_resume_advertising_sync() restores only HCI_ADVERTISING, so the discoverable state is lost. It reproduces today on an LL privacy controller through hci_pause_addr_resolution(); the unconditional pause makes it reachable without LL privacy as well. hci_suspend_sync() also pauses unconditionally, so a device that suspends loses the same state on any controller today. That asymmetry is pre-existing and is left alone here rather than folded into a scan path fix.
Legacy controllers have one random address register, shared by the scanner and the advertiser. Restoring the advertiser here can reprogram it when the advertiser is non-connectable, so the scan then uses that address rather than the one generated for it. Both are non-resolvable and neither is linkable to the identity address. With privacy enabled both roles already share one resolvable address the same way.
With the patch, on the same hardware:
< LE Set Advertising Enable Enable: 0x00 Success < LE Set Random Address Success < LE Set Advertising Parameters Success < LE Set Advertising Enable Enable: 0x01 Success < LE Set Scan Parameters Success < LE Set Scan Enable Enable: 0x01 Success
The address write is accepted, and advertising is restored before the scan is started.
Over 119369 btmon records and about 12 minutes of the normal workload of that device, alternating active and passive scanning with ten outgoing connection attempts, every LE Set Random Address succeeded and there were no Command Disallowed responses of any opcode, against one per scan restart before.
Patch 1 is required: without it the resume added here returns -EPERM on the controllers this fixes and leaves advertising disabled.
[ Valentin: Adjusted for 6.12.y: the privacy guard removed in the failed: label
reads use_ll_privacy(hdev) in this tree, and the context uses test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) instead of hci_test_quirk(). The added lines are unchanged. Requires commit 737139f4157d ("Bluetooth: hci_sync: re-enable legacy advertising on resume"). ]
--- net/bluetooth/hci_sync.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
net/bluetooth/hci_sync.c +12 -3
@@ -6154,6 +6154,7 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)u8 filter_policy =0x00 ;/* Default is to enable duplicates filter */ u8 filter_dup =LE_SCAN_FILTER_DUP_ENABLE ; +bool paused;int err;bt_dev_dbg (hdev,"" );
@@ -6177,6 +6178,12 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)if (err) goto failed; +/* LE Set Random Address is disallowed while advertising is enabled. */ + paused = !hdev->advertising_paused; + err =hci_pause_advertising_sync (hdev); +if (err) + goto failed; +/* All active scans will be done with either a resolvable private * address (when privacy feature has been enabled) or non-resolvable * private address.
@@ -6186,6 +6193,9 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)if (err <0 ) own_addr_type =ADDR_LE_DEV_PUBLIC ; +if (paused) +hci_resume_advertising_sync (hdev); +if (hci_is_adv_monitoring (hdev) || (test_bit (HCI_QUIRK_STRICT_DUPLICATE_FILTER , &hdev->quirks) && hdev->discovery.result_filtering)) {
@@ -6209,9 +6219,8 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)return err; failed: -/* Resume advertising if it was paused */ -if (use_ll_privacy (hdev)) -hci_resume_advertising_sync (hdev); +/* No-op when advertising was not paused. */ +hci_resume_advertising_sync (hdev);/* Resume passive scanning */ hci_update_passive_scan_sync (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/670 iio: adc: ti-ads1100: Fix incorrect reading when datarate changed in single mode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Szczudlo <[email protected]>
[ Upstream commit 38dbf24dfbd0a73b89fa2871a7148429aef05531 ]
When device is suspended and it is in single mode then changing datarate doesn't make it actually wait for new measurement, so to be sure that read after change is correct, functions that changes datarate and gain will wait for a new data.
--- drivers/iio/adc/ti-ads1100.c | 121 +++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 6 deletions(-)
drivers/iio/adc/ti-ads1100.c +115 -6
@@ -14,10 +14,12 @@#include <linux/module.h> #include <linux/init.h> #include <linux/i2c.h> +#include <linux/iopoll.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <linux/time.h> #include <linux/units.h> #include <linux/iio/iio.h>
@@ -42,6 +44,9 @@static const int ads1100_data_rate[] = {128 ,32 ,16 ,8 };static const int ads1100_data_rate_bits[] = {12 ,14 ,15 ,16 }; +/* Timeout based on the minimum sample rate of 8 SPS (7500ms) */ +#define ADS1100_MAX_DRDY_TIMEOUT_US (7500 * USEC_PER_MSEC) +struct ads1100_data {struct i2c_client *client;struct regulator *reg_vdd;
@@ -123,10 +128,86 @@ static int ads1100_get_adc_result(struct ads1100_data *data, int chan, int *val)return 0 ; } +static int ads1100_conversion_busy (struct ads1100_data *data) +{ +u8 buffer[3 ]; +int ret; + + ret =i2c_master_recv (data->client, (char *)&buffer,sizeof (buffer)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C read fail: %d\n" , ret); +return ret; + } + +return FIELD_GET (ADS1100_CFG_ST_BSY , buffer[2 ]); +} + +static int ads1100_wait_single_conversion (struct ads1100_data *data) +{ +int data_rate_index =FIELD_GET (ADS1100_DR_MASK , data->config); +int data_rate_Hz = ads1100_data_rate[data_rate_index]; +unsigned long poll_us =DIV_ROUND_CLOSEST (USEC_PER_SEC , data_rate_Hz) /4 ; +int busy; +int ret; + + ret =readx_poll_timeout (ads1100_conversion_busy, data, + busy, busy <=0 , + poll_us,ADS1100_MAX_DRDY_TIMEOUT_US ); +if (busy <0 ) +return busy; + +return ret; +} + +static int ads1100_start_single_conversion (struct ads1100_data *data) +{ +u8 config = data->config |ADS1100_CFG_SC ; +int ret; + + ret =i2c_master_send (data->client, &config,sizeof (config)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C write fail: %d\n" , ret); +return ret; + } +/* Need to wait because of change from continuous to single mode */ + ret =ads1100_wait_single_conversion (data); +if (ret) +return ret; + + config |=ADS1100_CFG_ST_BSY ; + + ret =i2c_master_send (data->client, &config,sizeof (config)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C write fail: %d\n" , ret); +return ret; + } + +/* No need to cache it, it's status bit */ + data->config = config & ~ADS1100_CFG_ST_BSY ; + +return 0 ; +} + +static int ads1100_poll_data_ready (struct ads1100_data *data) +{ +int ret; + + ret =ads1100_start_single_conversion (data); +if (ret) +return ret; + + ret =ads1100_wait_single_conversion (data); +if (ret) +return ret; + +return ads1100_set_config_bits (data,ADS1100_CFG_SC ,ADS1100_CONTINUOUS ); +} +static int ads1100_set_scale (struct ads1100_data *data,int val,int val2) {int microvolts;int gain; +int ret;/* With Vdd between 2.7 and 5V, the scale is always below 1 */ if (val)
@@ -135,6 +216,10 @@ static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)if (!val2)return -EINVAL ; + ret =pm_runtime_resume_and_get (&data->client->dev); +if (ret) +return ret; + microvolts =regulator_get_voltage (data->reg_vdd);/* * val2 is in 'micro' units, n = val2 / 1000000
@@ -144,27 +229,51 @@ static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)* bitshift so everything fits in 32-bits yields this formula. */ gain =DIV_ROUND_CLOSEST (microvolts,BIT (15 )) *MILLI / val2; -if (gain <BIT (0 ) || gain >BIT (3 )) -return -EINVAL ; +if (gain <BIT (0 ) || gain >BIT (3 )) { + ret = -EINVAL ; + goto out; + }ads1100_set_config_bits (data,ADS1100_PGA_MASK ,ffs (gain) -1 ); -return 0 ; + ret =ads1100_poll_data_ready (data); +out: +pm_runtime_mark_last_busy (&data->client->dev); +pm_runtime_put_autosuspend (&data->client->dev); + +return ret; }static int ads1100_set_data_rate (struct ads1100_data *data,int chan,int rate) {unsigned int i;unsigned int size; +int ret; size = data->supports_data_rate ?ARRAY_SIZE (ads1100_data_rate) :1 ;for (i =0 ; i < size; i++) {if (ads1100_data_rate[i] == rate) -return ads1100_set_config_bits (data,ADS1100_DR_MASK , -FIELD_PREP (ADS1100_DR_MASK , i)); +break ; } -return -EINVAL ; +if (i == size) +return -EINVAL ; + + ret =pm_runtime_resume_and_get (&data->client->dev); +if (ret) +return ret; + + ret =ads1100_set_config_bits (data,ADS1100_DR_MASK , +FIELD_PREP (ADS1100_DR_MASK , i)); +if (ret) + goto out; + + ret =ads1100_poll_data_ready (data); +out: +pm_runtime_mark_last_busy (&data->client->dev); +pm_runtime_put_autosuspend (&data->client->dev); + +return ret; }static int ads1100_get_vdd_millivolts (struct ads1100_data *data)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/670 soc: qcom: pmic_glink: Fix device access from worker during suspend
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 7d0767c5cd878707fd6711023731549c83563840 ]
For historical reasons, the GLINK smem interrupt is registered with IRRQF_NO_SUSPEND flag set, which is the underlying problem here, since the incoming messages can be delivered during late suspend and early resume.
In this specific case, the pmic_glink_altmode_worker() currently gets scheduled on the system_wq which can be scheduled to run while devices are still suspended. This proves to be a problem when a Type-C retimer, switch or mux that is controlled over a bus like I2C, because the I2C controller is suspended.
This has been proven to be the case on the X Elite boards where such retimers (ParadeTech PS8830) are used in order to handle Type-C orientation and altmode configuration. The following warning is thrown:
[ 35.134876] i2c i2c-4: Transfer while suspended [ 35.143865] WARNING: CPU: 0 PID: 99 at drivers/i2c/i2c-core.h:56 __i2c_transfer+0xb4/0x57c [i2c_core] [ 35.352879] Workqueue: events pmic_glink_altmode_worker [pmic_glink_altmode] [ 35.360179] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 35.455242] Call trace: [ 35.457826] __i2c_transfer+0xb4/0x57c [i2c_core] (P) [ 35.463086] i2c_transfer+0x98/0xf0 [i2c_core] [ 35.467713] i2c_transfer_buffer_flags+0x54/0x88 [i2c_core] [ 35.473502] regmap_i2c_write+0x20/0x48 [regmap_i2c] [ 35.478659] _regmap_raw_write_impl+0x780/0x944 [ 35.483401] _regmap_bus_raw_write+0x60/0x7c [ 35.487848] _regmap_write+0x134/0x184 [ 35.491773] regmap_write+0x54/0x78 [ 35.495418] ps883x_set+0x58/0xec [ps883x] [ 35.499688] ps883x_sw_set+0x60/0x84 [ps883x] [ 35.504223] typec_switch_set+0x48/0x74 [typec] [ 35.508952] pmic_glink_altmode_worker+0x44/0x1fc [pmic_glink_altmode] [ 35.515712] process_scheduled_works+0x1a0/0x2d0 [ 35.520525] worker_thread+0x2a8/0x3c8 [ 35.524449] kthread+0xfc/0x184 [ 35.527749] ret_from_fork+0x10/0x20
The proper solution here should be to not deliver these kind of messages during system suspend at all, or at least make it configurable per glink client. But simply dropping the IRQF_NO_SUSPEND flag entirely will break other clients. The final shape of the rework of the pmic glink driver in order to fulfill both the filtering of the messages that need to be able to wake-up the system and the queueing of these messages until the system has properly resumed is still being discussed and it is planned as a future effort.
Meanwhile, the stop-gap fix here is to schedule the pmic glink altmode worker on the system_freezable_wq instead of the system_wq. This will result in the altmode worker not being scheduled to run until the devices are resumed first, which will give the controllers like I2C a chance to resume before the transfer is requested.
--- drivers/soc/qcom/pmic_glink_altmode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/pmic_glink_altmode.c +2 -2
@@ -304,7 +304,7 @@ static void pmic_glink_altmode_sc8180xp_notify(struct pmic_glink_altmode *altmod alt_port->mode = mode; alt_port->hpd_state = hpd_state; alt_port->hpd_irq = hpd_irq; -schedule_work (&alt_port->work); +queue_work (system_freezable_wq, &alt_port->work); }#define SC8280XP_DPAM_MASK 0x3f
@@ -347,7 +347,7 @@ static void pmic_glink_altmode_sc8280xp_notify(struct pmic_glink_altmode *altmod alt_port->mode = mode; alt_port->hpd_state = hpd_state; alt_port->hpd_irq = hpd_irq; -schedule_work (&alt_port->work); +queue_work (system_freezable_wq, &alt_port->work); }static void pmic_glink_altmode_callback (const void *data,size_t len,void *priv)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/670 PCI: endpoint: pci-epf-vntb: Manage virtual NTB and PCI bus lifetime
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 5cdbd6d3a3a147fa9975e35f2602cbec9a72a932 ]
The virtual PCI driver registers an ntb_dev but has no remove callback. Unbinding the endpoint function can therefore free BARs while the NTB device and its client still use them. It also leaves the virtual PCI devices and root bus allocated.
Allocate an ntb_dev for each virtual PCI probe and unregister it from the matching remove callback. Start command processing only after registration. Publish the device for doorbell IRQs at the same point. During remove, stop the command work and drain IRQ handlers before unregistering the device.
Retain the root bus returned by pci_scan_bus() so it can be removed on unbind. Unregister the virtual PCI driver before releasing endpoint resources. Stop and remove the root bus under the PCI rescan/remove lock, then release its host bridge.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +55 -14
@@ -116,7 +116,7 @@ struct epf_ntb_ctrl { } __packed;struct epf_ntb { -struct ntb_dev ntb; +struct ntb_dev *ntb;struct pci_epf *epf;struct config_group group;
@@ -142,10 +142,15 @@ struct epf_ntb {void __iomem *vpci_mw_addr[MAX_MW ];struct delayed_work cmd_handler; +struct pci_bus *vpci_bus; };#define to_epf_ntb (epf_group) container_of((epf_group), struct epf_ntb, group) -#define ntb_ndev (__ntb) container_of(__ntb, struct epf_ntb, ntb) + +static struct epf_ntb *ntb_ndev (struct ntb_dev *ntb) +{ +return ntb->pdev->sysdata; +}static struct pci_epf_header epf_ntb_header = { .vendorid =PCI_ANY_ID ,
@@ -171,7 +176,7 @@ static int epf_ntb_link_up(struct epf_ntb *ntb, bool link_up)else ntb->reg->link_status &= ~LINK_STATUS_UP ; -ntb_link_event (&ntb->ntb); +ntb_link_event (ntb->ntb);return 0 ; }
@@ -259,7 +264,7 @@ static void epf_ntb_cmd_handler(struct work_struct *work)for (i =1 ; i < ntb->db_count; i++) {if (ntb->epf_db[i]) { ntb->db |=1 << (i -1 ); -ntb_db_event (&ntb->ntb, i); +ntb_db_event (ntb->ntb, i); ntb->epf_db[i] =0 ; } }
@@ -760,7 +765,6 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb) }INIT_DELAYED_WORK (&ntb->cmd_handler, epf_ntb_cmd_handler); -queue_work (kpcintb_workqueue, &ntb->cmd_handler.work);return 0 ;
@@ -1009,6 +1013,7 @@ static int vpci_scan_bus(void *sysdata)pr_err ("create pci bus failed\n" );return -EINVAL ; } + ndev->vpci_bus = vpci_bus;pci_bus_add_devices (vpci_bus);
@@ -1053,7 +1058,7 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx,int ret;struct device *dev; - dev = &ntb->ntb.dev; + dev = &ndev->dev; barno = ntb->epf_ntb_bar[BAR_MW0 + idx]; epf_bar = &ntb->epf->bar[barno]; epf_bar->phys_addr = addr;
@@ -1153,7 +1158,7 @@ static int vntb_epf_peer_db_set(struct ntb_dev *ndev, u64 db_bits) ret =pci_epc_raise_irq (ntb->epf->epc, func_no, vfunc_no,PCI_IRQ_MSI , interrupt_num +1 );if (ret) -dev_err (&ntb->ntb.dev,"Failed to raise IRQ\n" ); +dev_err (&ntb->epf->dev,"Failed to raise IRQ\n" );return ret; }
@@ -1236,13 +1241,18 @@ static const struct ntb_dev_ops vntb_epf_ops = {static int pci_vntb_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -int ret;struct epf_ntb *ndev = (struct epf_ntb *)pdev->sysdata;struct device *dev = &pdev->dev; +struct ntb_dev *ntb; +int ret; - ndev->ntb.pdev = pdev; - ndev->ntb.topo =NTB_TOPO_NONE ; - ndev->ntb.ops = &vntb_epf_ops; + ntb =devm_kzalloc (dev,sizeof (*ntb),GFP_KERNEL ); +if (!ntb) +return -ENOMEM ; + + ntb->pdev = pdev; + ntb->topo =NTB_TOPO_NONE ; + ntb->ops = &vntb_epf_ops; ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 ));if (ret) {
@@ -1250,16 +1260,33 @@ static int pci_vntb_probe(struct pci_dev *pdev, const struct pci_device_id *id)return ret; } - ret =ntb_register_device (&ndev->ntb); + ret =ntb_register_device (ntb);if (ret) {dev_err (dev,"Failed to register NTB device\n" );return ret; } +/* Publish after ntb_register_device() succeeds */ +smp_store_release (&ndev->ntb, ntb); +queue_delayed_work (kpcintb_workqueue, &ndev->cmd_handler,0 ); +dev_dbg (dev,"PCI Virtual NTB driver loaded\n" );return 0 ; } +static void pci_vntb_remove (struct pci_dev *pdev) +{ +struct epf_ntb *ndev = pdev->sysdata; +struct ntb_dev *ntb; + +/* Stop the work reader */ +cancel_delayed_work_sync (&ndev->cmd_handler); + + ntb =xchg (&ndev->ntb,NULL ); + +ntb_unregister_device (ntb); +} +static struct pci_device_id pci_vntb_table[] = { {PCI_DEVICE (0xffff ,0xffff ),
@@ -1271,6 +1298,7 @@ static struct pci_driver vntb_pci_driver = { .name = "pci-vntb", .id_table = pci_vntb_table, .probe = pci_vntb_probe, + .remove = pci_vntb_remove, };/* ============ PCIe EPF Driver Bind ====================*/
@@ -1351,12 +1379,25 @@ static int epf_ntb_bind(struct pci_epf *epf)*/ static void epf_ntb_unbind (struct pci_epf *epf) { +struct pci_host_bridge *bridge;struct epf_ntb *ntb =epf_get_drvdata (epf); +pci_unregister_driver (&vntb_pci_driver); + +if (ntb->vpci_bus) { + bridge =to_pci_host_bridge (ntb->vpci_bus->bridge); + +pci_lock_rescan_remove (); +pci_stop_root_bus (ntb->vpci_bus); +pci_remove_root_bus (ntb->vpci_bus); + ntb->vpci_bus =NULL ; +pci_unlock_rescan_remove (); + +pci_free_host_bridge (bridge); + } +epf_ntb_epc_cleanup (ntb);epf_ntb_config_spad_bar_free (ntb); - -pci_unregister_driver (&vntb_pci_driver); }// EPF driver probe
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/670 arm64: dts: ti: k3-am625-sk: Remove M4 mailbox node redefinition
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Davis <[email protected]>
[ Upstream commit 17d0723c6cf841ebaf510eaf9bb1ebf4991d6e9d ]
This node is already defined in the included k3-am62x-sk-common.dtsi. Remove this redefinition.
Stable-dep-of: 8ef8a0e38d13 ("arm64: dts: ti: k3-am625-sk-common: Set eMMC clock pin as OUTPUT")
--- arch/arm64/boot/dts/ti/k3-am625-sk.dts | 7 ------- 1 file changed, 7 deletions(-)
arch/arm64/boot/dts/ti/k3-am625-sk.dts +0 -7
@@ -243,13 +243,6 @@ cpsw3g_phy1: ethernet-phy@1 { }; }; -&mailbox0_cluster0 { - mbox_m4_0: mbox-m4-0 { - ti,mbox-rx = <0 0 0>; - ti,mbox-tx = <1 0 0>; - }; -}; - &fss { bootph-all; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/670 arm64: dts: ti: k3-am62*: remove SoC dtsi from common dtsi
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anshul Dalal <[email protected]>
[ Upstream commit e0b9feca7329c495a76891d7766a781dea73787d ]
The k3-am62x-sk-common dtsi represents the common hardware used across am62x EVMs which can be configured with various DDR sizes or none (with DDR integrated in the package) based on the specific am62x SoC used.
Therefore this patch moves the memory node and the SoC specific k3-am625 dtsi out of sk-common and into the board dts files. No functional change is intended from this patch. The device-tree inheritance is changed as follows:
Before:
k3-am62
^
k3-am625
^
k3-am62x-sk-common
^am62x EVMs (k3-am625-sk, k3-am62-lp-sk)
After:
k3-am62
^
k3-am625 k3-am62x-sk-common
^ ^am62x EVMs (k3-am625-sk, k3-am62-lp-sk)
Move the SoC include and RAM description out of the shared evaluation board description and into the individual board descriptions. Preserve the existing unlabeled reserved-memory node.
Also extract the existing AM625 SK hardware description into a common include, keeping the SoC selection, board identity and RAM in the board description. This supplies the location needed by the subsequent eMMC clock pin correction without adding support for another board.
Keep all existing hardware properties, including boot phase annotations, the eMMC non-removable flag and the audio codec supply. No functional change is intended.
Stable-dep-of: 8ef8a0e38d13 ("arm64: dts: ti: k3-am625-sk-common: Set eMMC clock pin as OUTPUT")
--- arch/arm64/boot/dts/ti/k3-am62-lp-sk.dts | 8 + .../arm64/boot/dts/ti/k3-am625-sk-common.dtsi | 304 ++++++++++++++++++ arch/arm64/boot/dts/ti/k3-am625-sk.dts | 301 +---------------- .../arm64/boot/dts/ti/k3-am62x-sk-common.dtsi | 8 - 4 files changed, 316 insertions(+), 305 deletions(-) create mode 100644 arch/arm64/boot/dts/ti/k3-am625-sk-common.dtsi
arch/arm64/boot/dts/ti/k3-am62-lp-sk.dts +8 -0
@@ -7,12 +7,20 @@ /dts-v1/; +#include "k3-am625.dtsi" #include "k3-am62x-sk-common.dtsi" / { compatible = "ti,am62-lp-sk", "ti,am625"; model = "Texas Instruments AM62x LP SK"; + memory@80000000 { + /* 2G RAM */ + reg = <0x00000000 0x80000000 0x00000000 0x80000000>; + device_type = "memory"; + bootph-pre-ram; + }; + vmain_pd: regulator-0 { /* TPS65988 PD CONTROLLER OUTPUT */ compatible = "regulator-fixed";
arch/arm64/boot/dts/ti/k3-am625-sk-common.dtsi new file +304 -0
304 lines not on this page · raw message
arch/arm64/boot/dts/ti/k3-am625-sk.dts +4 -297
314 lines not on this page · raw message
arch/arm64/boot/dts/ti/k3-am62x-sk-common.dtsi +0 -8
@@ -8,7 +8,6 @@ #include <dt-bindings/leds/common.h> #include <dt-bindings/gpio/gpio.h> #include <dt-bindings/net/ti-dp83867.h> -#include "k3-am625.dtsi" / { aliases {
@@ -27,13 +26,6 @@ chosen { stdout-path = "serial2:115200n8"; }; - memory@80000000 { - bootph-pre-ram; - device_type = "memory"; - /* 2G RAM */ - reg = <0x00000000 0x80000000 0x00000000 0x80000000>; - }; - reserved-memory { #address-cells = <2>; #size-cells = <2>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/670 arm64: dts: ti: k3-am625-sk-common: Set eMMC clock pin as OUTPUT
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Judith Mendez <[email protected]>
[ Upstream commit 8ef8a0e38d1377c6d51c06f95c64d87641b2c717 ]
MMC clock pins must be configured as OUTPUT-only per TRM [0] with receiver disabled (RXACTIVE bit = 0). Change MMC CLK pins from PIN_INPUT to PIN_OUTPUT to match documentation.
[0] https://www.ti.com/lit/pdf/spruiv7 Rev. C: Table 12-246. MMCSDi I/O Signals
--- arch/arm64/boot/dts/ti/k3-am625-sk-common.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am625-sk-common.dtsi +1 -1
@@ -98,7 +98,7 @@ main_mmc0_pins_default: main-mmc0-default-pins { bootph-all; pinctrl-single,pins = < AM62X_IOPAD(0x220, PIN_INPUT, 0) /* (Y3) MMC0_CMD */ - AM62X_IOPAD(0x218, PIN_INPUT, 0) /* (AB1) MMC0_CLK */ + AM62X_IOPAD(0x218, PIN_OUTPUT, 0) /* (AB1) MMC0_CLK */ AM62X_IOPAD(0x214, PIN_INPUT, 0) /* (AA2) MMC0_DAT0 */ AM62X_IOPAD(0x210, PIN_INPUT_PULLUP, 0) /* (AA1) MMC0_DAT1 */ AM62X_IOPAD(0x20c, PIN_INPUT_PULLUP, 0) /* (AA3) MMC0_DAT2 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/670 KVM: guest_memfd: Split bind() into prepare()+commit() phases
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 83411f32b8ad96c6b05b1511d1a588daab44bd25 ]
Split binding a memslot to a guest_memfd instance into prepare() and commit() phases so that KVM can separate preparing the memslot from binding the memslot to the gmem instance, i.e. from committing the memslot. This will allow waiting to commit the memslot+gmem binding until the memslot is fully prepared, which is necessary as the memslot becomes reachable when the binding is created.
As a bonus, drop the unwind-on-failure from the commit phase (other than nullifying the bindings), as the only reason bind() did the full unwind is because it technically didn't own the memslot, i.e. "needed" to leave memslot in the same state it started in.
No functional change intended (the unwinding down on bind() failure was effectively dead code since KVM simply deletes the memslot on failure, i.e. there was nothing that could actually observe the unwind).
--- virt/kvm/guest_memfd.c | 61 +++++++++++++++++++++++++----------------- virt/kvm/kvm_main.c | 18 ++++++++++++- virt/kvm/kvm_mm.h | 18 +++++++++---- 3 files changed, 66 insertions(+), 31 deletions(-)
virt/kvm/guest_memfd.c +36 -25
@@ -472,15 +472,13 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args)return __kvm_gmem_create (kvm, size, flags); } -int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,u64 offset) +int kvm_gmem_prepare_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned int fd,u64 offset) {u64 size = slot->npages <<PAGE_SHIFT ; -unsigned long start, end;struct kvm_gmem *gmem;struct inode *inode;struct file *file; -int r = -EINVAL ;BUILD_BUG_ON (sizeof (gpa_t) !=sizeof (offset));BUILD_BUG_ON (sizeof (gfn_t) !=sizeof (slot->gmem.pgoff));
@@ -501,40 +499,53 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,if (!PAGE_ALIGNED (offset) || offset + size >i_size_read (inode)) goto err; +/* +* memslots of flag KVM_MEM_GUEST_MEMFD are immutable to change, so +* kvm_gmem_bind() must occur on a new memslot. Because the memslot +* is not visible yet, kvm_gmem_get_pfn() is guaranteed to see the file. +*/ +WRITE_ONCE (slot->gmem.file, file); + slot->gmem.pgoff = offset >>PAGE_SHIFT ; + +/* +* Gift the caller a reference to the file. The reference will be +* dropped after bindings are established, or if installing the new +* memslot ultimately fails. +*/ +return 0 ; + +err: +fput (file); +return -EINVAL ; +} + +int kvm_gmem_commit_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot) +{ +struct kvm_gmem *gmem = slot->gmem.file->private_data; +struct inode *inode =file_inode (slot->gmem.file); +unsigned long start, end; +int r; + +if (WARN_ON_ONCE (slot->gmem.file->f_op != &kvm_gmem_fops)) +return -EIO ; +filemap_invalidate_lock (inode->i_mapping); - start = offset >>PAGE_SHIFT ; + start = slot->gmem.pgoff; end = start + slot->npages;if (!xa_empty (&gmem->bindings) &&xa_find (&gmem->bindings, &start, end -1 ,XA_PRESENT )) {filemap_invalidate_unlock (inode->i_mapping); - goto err; +return -EEXIST ; } -/* -* memslots of flag KVM_MEM_GUEST_MEMFD are immutable to change, so -* kvm_gmem_bind() must occur on a new memslot. Because the memslot -* is not visible yet, kvm_gmem_get_pfn() is guaranteed to see the file. -*/ -WRITE_ONCE (slot->gmem.file, file); - slot->gmem.pgoff = start; - r =xa_err (xa_store_range (&gmem->bindings, start, end -1 , slot,GFP_KERNEL )); -if (r) { +if (r)xa_store_range (&gmem->bindings, start, end -1 ,NULL ,GFP_KERNEL ); - slot->gmem.file =NULL ; - slot->gmem.pgoff =0 ; - } +filemap_invalidate_unlock (inode->i_mapping); -/* -* Drop the reference to the file, even on success. The file pins KVM, -* not the other way 'round. Active bindings are invalidated if the -* file is closed before memslots are destroyed. -*/ -err: -fput (file);return r; }
virt/kvm/kvm_main.c +17 -1
@@ -2103,7 +2103,23 @@ int __kvm_set_memory_region(struct kvm *kvm, new->flags = mem->flags; new->userspace_addr = mem->userspace_addr;if (change ==KVM_MR_CREATE && (mem->flags &KVM_MEM_GUEST_MEMFD )) { - r =kvm_gmem_bind (kvm, new, mem->guest_memfd, mem->guest_memfd_offset); + r =kvm_gmem_prepare_memory_region (kvm, new, mem->guest_memfd, + mem->guest_memfd_offset); +if (r) + goto out; + + r =kvm_gmem_commit_memory_region (kvm, new); + +/* +* Drop the reference to the file, even on success. The file +* pins KVM, not the other way 'round. Active bindings are +* invalidated if the file is closed before memslots are +* destroyed. +*/ +#ifdef CONFIG_KVM_PRIVATE_MEM +fput (new->gmem.file); +#endif +if (r) goto out; }
virt/kvm/kvm_mm.h +13 -5
@@ -41,8 +41,9 @@ static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm,#ifdef CONFIG_KVM_PRIVATE_MEM void kvm_gmem_init (struct module *module);int kvm_gmem_create (struct kvm *kvm,struct kvm_create_guest_memfd *args); -int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,u64 offset); +int kvm_gmem_prepare_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned int fd,u64 offset); +int kvm_gmem_commit_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot);void kvm_gmem_unbind (struct kvm_memory_slot *slot);#else static inline void kvm_gmem_init (struct module *module)
@@ -50,9 +51,16 @@ static inline void kvm_gmem_init(struct module *module) } -static inline int kvm_gmem_bind (struct kvm *kvm, -struct kvm_memory_slot *slot, -unsigned int fd,u64 offset) +static inline int kvm_gmem_prepare_memory_region (struct kvm *kvm, +struct kvm_memory_slot *slot, +unsigned int fd,u64 offset) +{ +WARN_ON_ONCE (1 ); +return -EIO ; +} + +static inline int kvm_gmem_commit_memory_region (struct kvm *kvm, +struct kvm_memory_slot *slot) {WARN_ON_ONCE (1 );return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/670 iio: light: isl29028: fix runtime PM reference leak on error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabio Cesari <[email protected]>
[ Upstream commit 0e30d15b15647df786e60022650613e16dd70645 ]
isl29028_read_raw() and isl29028_write_raw() take a runtime PM reference with pm_runtime_resume_and_get() but return directly on their error paths without dropping it. The usage count never balances again and the device stops entering autosuspend for good. In isl29028_read_raw() this needs a regmap access to fail; in isl29028_write_raw() one rejected sysfs write is enough, for example
echo 200 > in_proximity_sampling_frequency
which is outside the [1:100] range and returns -EINVAL with the reference still held.
Take the reference with PM_RUNTIME_ACQUIRE_AUTOSUSPEND() instead, so it is released on every return path.
This also stops the return value of pm_runtime_put_autosuspend() from reaching userspace. That value only says whether the device could be suspended right away, so -EAGAIN or -EPERM turns a successful access into a failure, and with CONFIG_PM=n the stub returns -ENOSYS on every access.
--- drivers/iio/light/isl29028.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/iio/light/isl29028.c +4 -19
@@ -407,14 +407,9 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,mutex_unlock (&chip->lock); -if (ret <0 ) -return ret; +isl29028_set_pm_runtime_busy (chip, false); - ret =isl29028_set_pm_runtime_busy (chip, false); -if (ret <0 ) -return ret; - -return 0 ; +return ret; } static int isl29028_read_raw(struct iio_dev *indio_dev,
@@ -423,7 +418,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, {struct isl29028_chip *chip =iio_priv (indio_dev);struct device *dev =regmap_get_device (chip->regmap); -int ret, pm_ret; +int ret; ret =isl29028_set_pm_runtime_busy (chip, true);if (ret <0 )
@@ -476,17 +471,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,mutex_unlock (&chip->lock); -if (ret <0 ) -return ret; - -/** -* Preserve the ret variable if the call to -* isl29028_set_pm_runtime_busy() is successful so the reading -* (if applicable) is returned to user space. -*/ - pm_ret =isl29028_set_pm_runtime_busy (chip, false); -if (pm_ret <0 ) -return pm_ret; +isl29028_set_pm_runtime_busy (chip, false);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/670 KVM: arm64: ptdump: Check the page tables arent freed when accessing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei-Lin Chang <[email protected]>
[ Upstream commit 7d7199bdf77a3a6ed74d0037133f435a7febe97c ]
An open debugfs file keeps the KVM structure alive, but does not prevent mmu notifier release from freeing the stage-2 page tables when the VMM’s address space is torn down. Therefore page tables belonging to the mmus could have been freed when a thread opens or reads the ptdump files. Take the mmu_lock and check mmu->pgt is still alive before accessing the page tables.
Also for the ipa_range file and stage2_levels file, switch from keeping the pointer to the page tables to keeping the pointer to the mmu.
--- arch/arm64/kvm/ptdump.c | 50 +++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-)
arch/arm64/kvm/ptdump.c +36 -14
@@ -97,22 +97,35 @@ static struct kvm_ptdump_guest_state *kvm_ptdump_parser_create(struct kvm *kvm) {struct kvm_ptdump_guest_state *st;struct kvm_s2_mmu *mmu = &kvm->arch.mmu; -struct kvm_pgtable *pgtable = mmu->pgt; +s8 start_level; +u32 ia_bits;int ret; +/* +* We only need the pgt start level and IPA size to initialize the ptdump, +* get them while holding the mmu_lock. It's fine if the pgt gets freed +* afterwards, we'll check again when doing the actual dump. +*/ + scoped_guard(read_lock, &kvm->mmu_lock) { +if (!mmu->pgt) +return ERR_PTR (-ENOENT ); + start_level = mmu->pgt->start_level; + ia_bits = mmu->pgt->ia_bits; + } + st =kzalloc (sizeof (struct kvm_ptdump_guest_state ),GFP_KERNEL_ACCOUNT );if (!st)return ERR_PTR (-ENOMEM ); - ret =kvm_ptdump_build_levels (&st->level[0 ], pgtable->start_level); + ret =kvm_ptdump_build_levels (&st->level[0 ], start_level);if (ret) {kfree (st);return ERR_PTR (ret); } st->ipa_marker[0 ].name ="Guest IPA" ; - st->ipa_marker[1 ].start_address =BIT (pgtable->ia_bits); - st->range[0 ].end =BIT (pgtable->ia_bits); + st->ipa_marker[1 ].start_address =BIT (ia_bits); + st->range[0 ].end =BIT (ia_bits); st->kvm = kvm; st->parser_state = (struct ptdump_pg_state ) {
@@ -141,9 +154,11 @@ static int kvm_ptdump_guest_show(struct seq_file *m, void *unused) parser_state->seq = m; -write_lock (&kvm->mmu_lock); +guard (write_lock)(&kvm->mmu_lock); +if (!mmu->pgt) +return 0 ; + ret =kvm_pgtable_walk (mmu->pgt,0 ,BIT (mmu->pgt->ia_bits), &walker); -write_unlock (&kvm->mmu_lock);return ret; }
@@ -193,17 +208,27 @@ static const struct file_operations kvm_ptdump_guest_fops = {static int kvm_pgtable_range_show (struct seq_file *m,void *unused) { -struct kvm_pgtable *pgtable = m->private; +struct kvm_s2_mmu *mmu = m->private; +struct kvm *kvm =kvm_s2_mmu_to_kvm (mmu); + +guard (read_lock)(&kvm->mmu_lock); + +if (mmu->pgt) +seq_printf (m,"%2u\n" , mmu->pgt->ia_bits); -seq_printf (m,"%2u\n" , pgtable->ia_bits);return 0 ; }static int kvm_pgtable_levels_show (struct seq_file *m,void *unused) { -struct kvm_pgtable *pgtable = m->private; +struct kvm_s2_mmu *mmu = m->private; +struct kvm *kvm =kvm_s2_mmu_to_kvm (mmu); + +guard (read_lock)(&kvm->mmu_lock); + +if (mmu->pgt) +seq_printf (m,"%1d\n" ,KVM_PGTABLE_MAX_LEVELS - mmu->pgt->start_level); -seq_printf (m,"%1d\n" ,KVM_PGTABLE_MAX_LEVELS - pgtable->start_level);return 0 ; }
@@ -211,15 +236,12 @@ static int kvm_pgtable_debugfs_open(struct inode *m, struct file *file, int (*show)(struct seq_file *, void *)) {struct kvm *kvm = m->i_private; -struct kvm_pgtable *pgtable;int ret;if (!kvm_get_kvm_safe (kvm))return -ENOENT ; - pgtable = kvm->arch.mmu.pgt; - - ret =single_open (file, show, pgtable); + ret =single_open (file, show, &kvm->arch.mmu);if (ret <0 )kvm_put_kvm (kvm);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/670 media: microchip-isc: store the unshifted PFE_CFG0 BPS value
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 14cbe597504a04c5c49342d0566438e2b438a948 ]
pfe_cfg0_bps held a pre-shifted BPS value (ISC_PFE_CFG0_BPS_EIGHT was 0x4 << 28) ORed straight into the register. The other format selectors like cfa_baycfg store the bare field value and position it at the write, so this one was inconsistent.
Store the bare BPS value and apply it with FIELD_PREP() at the PFE_CFG0 write, and fix the pfe_cfg0_bps comment to match. No functional change.
Stable-dep-of: bb96c78c5f87 ("media: microchip-isc: fix SBGGR10 Bayer pattern")
--- drivers/media/platform/microchip/microchip-isc-base.c | 4 +++- drivers/media/platform/microchip/microchip-isc-regs.h | 10 +++++----- drivers/media/platform/microchip/microchip-isc.h | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/media/platform/microchip/microchip-isc-base.c +3 -1
@@ -8,6 +8,7 @@* Author: Eugen Hristev <[email protected]> * */ +#include <linux/bitfield.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/math64.h>
@@ -291,7 +292,8 @@ static int isc_configure(struct isc_device *isc)struct isc_subdev_entity *subdev = isc->current_subdev;int ret; - pfe_cfg0 = isc->config.sd_format->pfe_cfg0_bps; + pfe_cfg0 =FIELD_PREP (ISC_PFE_CFG0_BPS_MASK , + isc->config.sd_format->pfe_cfg0_bps); pipeline = isc->config.bits_pipeline; dcfg = isc->config.dcfg_imode | isc->dcfg;
drivers/media/platform/microchip/microchip-isc-regs.h +5 -5
@@ -31,11 +31,11 @@#define ISC_PFE_CFG0_MODE_PROGRESSIVE (0x0 << 4)#define ISC_PFE_CFG0_MODE_MASK GENMASK(6, 4) -#define ISC_PFE_CFG0_BPS_EIGHT (0x4 << 28) -#define ISC_PFG_CFG0_BPS_NINE (0x3 << 28) -#define ISC_PFG_CFG0_BPS_TEN (0x2 << 28) -#define ISC_PFG_CFG0_BPS_ELEVEN (0x1 << 28) -#define ISC_PFG_CFG0_BPS_TWELVE (0x0 << 28) +#define ISC_PFE_CFG0_BPS_EIGHT 0x4 +#define ISC_PFG_CFG0_BPS_NINE 0x3 +#define ISC_PFG_CFG0_BPS_TEN 0x2 +#define ISC_PFG_CFG0_BPS_ELEVEN 0x1 +#define ISC_PFG_CFG0_BPS_TWELVE 0x0#define ISC_PFE_CFG0_BPS_MASK GENMASK(30, 28)#define ISC_PFE_CFG0_COLEN BIT(12)
drivers/media/platform/microchip/microchip-isc.h +3 -1
@@ -62,7 +62,9 @@ struct isc_subdev_entity {* @mbus_code: V4L2 media bus format code. * @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. -* @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @pfe_cfg0_bps: ISC_PFE_CFG0 BPS field value (e.g. ISC_PFE_CFG0_BPS_EIGHT), +written into PFE_CFG0 with FIELD_PREP(ISC_PFE_CFG0_BPS_MASK) +at configure time. * @raw: If the format is raw bayer. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/670 media: microchip-isc: fix ISC_PFG_CFG0_BPS macro name typo
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 96defd0723fc893db6ccf5f4968323db4af0b0aa ]
The BPS field macros for ISC_PFE_CFG0 were spelled ISC_PFG_CFG0_BPS_* (NINE, TEN, ELEVEN, TWELVE). The register is PFE, not PFG. Rename them to ISC_PFE_CFG0_BPS_* to match the register and the EIGHT and MASK macros. No functional change.
Stable-dep-of: bb96c78c5f87 ("media: microchip-isc: fix SBGGR10 Bayer pattern")
--- .../platform/microchip/microchip-isc-regs.h | 8 ++++---- .../platform/microchip/microchip-sama5d2-isc.c | 18 +++++++++--------- .../platform/microchip/microchip-sama7g5-isc.c | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-)
drivers/media/platform/microchip/microchip-isc-regs.h +4 -4
@@ -32,10 +32,10 @@#define ISC_PFE_CFG0_MODE_MASK GENMASK(6, 4)#define ISC_PFE_CFG0_BPS_EIGHT 0x4 -#define ISC_PFG_CFG0_BPS_NINE 0x3 -#define ISC_PFG_CFG0_BPS_TEN 0x2 -#define ISC_PFG_CFG0_BPS_ELEVEN 0x1 -#define ISC_PFG_CFG0_BPS_TWELVE 0x0 +#define ISC_PFE_CFG0_BPS_NINE 0x3 +#define ISC_PFE_CFG0_BPS_TEN 0x2 +#define ISC_PFE_CFG0_BPS_ELEVEN 0x1 +#define ISC_PFE_CFG0_BPS_TWELVE 0x0#define ISC_PFE_CFG0_BPS_MASK GENMASK(30, 28)#define ISC_PFE_CFG0_COLEN BIT(12)
drivers/media/platform/microchip/microchip-sama5d2-isc.c +9 -9
@@ -147,49 +147,49 @@ static struct isc_format sama5d2_formats_list[] = { { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SBGGR12, .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG12, .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG12, .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB12, .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, {
@@ -210,7 +210,7 @@ static struct isc_format sama5d2_formats_list[] = { { .fourcc = V4L2_PIX_FMT_Y10, .mbus_code = MEDIA_BUS_FMT_Y10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, }, };
drivers/media/platform/microchip/microchip-sama7g5-isc.c +9 -9
@@ -156,49 +156,49 @@ static struct isc_format sama7g5_formats_list[] = { { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SBGGR12, .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG12, .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG12, .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB12, .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, {
@@ -224,7 +224,7 @@ static struct isc_format sama7g5_formats_list[] = { { .fourcc = V4L2_PIX_FMT_Y10, .mbus_code = MEDIA_BUS_FMT_Y10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, }, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/670 media: microchip-isc: fix SBGGR10 Bayer pattern
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit bb96c78c5f87072913f8825faebe64bf711a503c ]
SBGGR10 was mapped to ISC_BAY_CFG_RGRG instead of ISC_BAY_CFG_BGBG, causing red/blue channel swap.
--- drivers/media/platform/microchip/microchip-sama5d2-isc.c | 2 +- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/microchip/microchip-sama5d2-isc.c +1 -1
@@ -148,7 +148,7 @@ static struct isc_format sama5d2_formats_list[] = { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, - .cfa_baycfg = ISC_BAY_CFG_RGRG, + .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10,
drivers/media/platform/microchip/microchip-sama7g5-isc.c +1 -1
@@ -157,7 +157,7 @@ static struct isc_format sama7g5_formats_list[] = { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, - .cfa_baycfg = ISC_BAY_CFG_RGRG, + .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/670 mm/page_alloc: reject unreasonable folio/compound page sizes in alloc_contig_range_noprof()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand <[email protected]>
[ Upstream commit 0bf2edf041dcb0b304a8dbda8c699771d5a245d2 ]
Let's reject them early, which in turn makes folio_alloc_gigantic() reject them properly.
To avoid converting from order to nr_pages, let's just add MAX_FOLIO_ORDER and calculate MAX_FOLIO_NR_PAGES based on that.
While at it, let's just make the order a "const unsigned order".
Stable-dep-of: 4c767c5dd9bc ("mm/page_isolation: guard compound_order() against racing")
--- include/linux/mm.h | 6 ++++-- mm/page_alloc.c | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-)
include/linux/mm.h +4 -2
@@ -2058,11 +2058,13 @@ static inline long folio_nr_pages(const struct folio *folio)/* Only hugetlbfs can allocate folios larger than MAX_ORDER */ #ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE -#define MAX_FOLIO_NR_PAGES (1UL << PUD_ORDER) +#define MAX_FOLIO_ORDER PUD_ORDER#else -#define MAX_FOLIO_NR_PAGES MAX_ORDER_NR_PAGES +#define MAX_FOLIO_ORDER MAX_PAGE_ORDER#endif +#define MAX_FOLIO_NR_PAGES (1UL << MAX_FOLIO_ORDER) +/* * compound_nr() returns the number of pages in this potentially compound * page. compound_nr() can be called on a tail page, and is defined to
mm/page_alloc.c +9 -1
@@ -6685,6 +6685,7 @@ static int __alloc_contig_verify_gfp_mask(gfp_t gfp_mask, gfp_t *gfp_cc_mask)int alloc_contig_range_noprof (unsigned long start,unsigned long end,unsigned migratetype,gfp_t gfp_mask) { +const unsigned int order =ilog2 (end - start);unsigned long outer_start, outer_end;int ret =0 ;
@@ -6699,6 +6700,14 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end, };INIT_LIST_HEAD (&cc.migratepages); +/* +* In contrast to the buddy, we allow for orders here that exceed +* MAX_PAGE_ORDER, so we must manually make sure that we are not +* exceeding the maximum folio order. +*/ +if (WARN_ON_ONCE ((gfp_mask & __GFP_COMP) && order >MAX_FOLIO_ORDER )) +return -EINVAL ; + gfp_mask =current_gfp_context (gfp_mask);if (__alloc_contig_verify_gfp_mask (gfp_mask, (gfp_t *)&cc.gfp_mask))return -EINVAL ;
@@ -6796,7 +6805,6 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,free_contig_range (end, outer_end - end); }else if (start == outer_start && end == outer_end &&is_power_of_2 (end - start)) {struct page *head =pfn_to_page (start); -int order =ilog2 (end - start);check_new_pages (head, order);prep_new_page (head, order, gfp_mask,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/670 mm/page_isolation: guard compound_order() against racing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qi Xi <[email protected]>
[ Upstream commit 4c767c5dd9bc3521fed11e6fe1d52621fe5abf7b ]
The PageCompound branch reads compound_head() without holding a reference. A racing split or free can cause compound_head() to return a stale pointer, and compound_nr() reads the order from that stale head, leading to out-of-range shifts and making the skip distance meaningless.
Read the order explicitly with compound_order() and validate it is within MAX_FOLIO_ORDER before shifting. Also verify the derived head_pfn against the legitimate pfn: the head must not be past pfn, must be aligned to nr_pages, and pfn must fall within the compound page. Bail out with -EBUSY if any check fails.
--- mm/page_isolation.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
mm/page_isolation.c +20 -2
@@ -401,10 +401,28 @@ static int isolate_single_pageblock(unsigned long boundary_pfn, int flags,if (PageCompound (page)) {struct page *head =compound_head (page);unsigned long head_pfn =page_to_pfn (head); -unsigned long nr_pages =compound_nr (head); +unsigned int order =compound_order (head); +unsigned long nr_pages; + +/* compound_order() is racy. Cap it at MAX_FOLIO_ORDER. */ +if (order >MAX_FOLIO_ORDER ) + goto failed; + + nr_pages =1UL << order; + +/* +* compound_head() is also racy, so the derived head_pfn +* needs additional checks to make sure it is valid. +* Otherwise, just fail the check. pfn comes from +* __first_valid_page() as a legitimate PFN, so use it to +* check head_pfn. +*/ +if (head_pfn > pfn || !IS_ALIGNED (head_pfn, nr_pages) || + pfn - head_pfn >= nr_pages) + goto failed;if (head_pfn + nr_pages <= boundary_pfn || -PageHuge (page)) { +PageHuge (head)) { pfn = head_pfn + nr_pages;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/670 arm64: dts: qcom: ipq9574: Wire up USB3 PHY PIPE clock to GCC
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
[ Upstream commit 117d8d40be1ded4f35f3252efa83607a7134d5e0 ]
Connect the QMP PHY USB3 output to GCC so the USB3 PHY pipe clock can propagate to the USB controller.
--- arch/arm64/boot/dts/qcom/ipq9574.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/ipq9574.dtsi +1 -1
@@ -315,7 +315,7 @@ gcc: clock-controller@1800000 { <0>, <0>, <0>, - <0>; + <&usb_0_qmpphy>; #clock-cells = <1>; #reset-cells = <1>; #interconnect-cells = <1>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/670 crypto: omap - convert from tasklet to BH workqueue
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryo Takakura <[email protected]>
[ Upstream commit 381e8ee368234a51b3a4f231f6f24ff0b09d9f9e ]
tasklet has been marked deprecated and it's planned to be removed. Make omap crypto drivers to use BH workqueue which is the new interface for executing in BH context in place of tasklet.
Stable-dep-of: 5d69ed4cd4f9 ("crypto: omap-des - fix crypto engine cleanup")
--- drivers/crypto/omap-aes.c | 15 ++++++++------- drivers/crypto/omap-aes.h | 2 +- drivers/crypto/omap-des.c | 17 +++++++++-------- drivers/crypto/omap-sham.c | 15 ++++++++------- 4 files changed, 26 insertions(+), 23 deletions(-)
drivers/crypto/omap-aes.c +8 -7
@@ -33,6 +33,7 @@#include <linux/pm_runtime.h> #include <linux/scatterlist.h> #include <linux/string.h> +#include <linux/workqueue.h> #include "omap-crypto.h" #include "omap-aes.h"
@@ -222,7 +223,7 @@ static void omap_aes_dma_out_callback(void *data)struct omap_aes_dev *dd = data;/* dma_lch_out - completed */ -tasklet_schedule (&dd->done_task); +queue_work (system_bh_wq, &dd->done_task); }static int omap_aes_dma_init (struct omap_aes_dev *dd)
@@ -496,9 +497,9 @@ static void omap_aes_copy_ivout(struct omap_aes_dev *dd, u8 *ivbuf) ((u32 *)ivbuf)[i] =omap_aes_read (dd,AES_REG_IV (dd, i)); } -static void omap_aes_done_task (unsigned long data) +static void omap_aes_done_task (struct work_struct *t) { -struct omap_aes_dev *dd = (struct omap_aes_dev *)data; +struct omap_aes_dev *dd =from_work (dd, t, done_task);pr_debug ("enter done_task\n" );
@@ -932,7 +933,7 @@ static irqreturn_t omap_aes_irq(int irq, void *dev_id)if (!dd->total)/* All bytes read! */ -tasklet_schedule (&dd->done_task); +queue_work (system_bh_wq, &dd->done_task);else /* Enable DATA_IN interrupt for next block */ omap_aes_write (dd,AES_REG_IRQ_ENABLE (dd),0x2 );
@@ -1150,7 +1151,7 @@ static int omap_aes_probe(struct platform_device *pdev) (reg & dd->pdata->major_mask) >> dd->pdata->major_shift, (reg & dd->pdata->minor_mask) >> dd->pdata->minor_shift); -tasklet_init (&dd->done_task, omap_aes_done_task, (unsigned long )dd); +INIT_WORK (&dd->done_task, omap_aes_done_task); err =omap_aes_dma_init (dd);if (err == -EPROBE_DEFER ) {
@@ -1245,7 +1246,7 @@ static int omap_aes_probe(struct platform_device *pdev)omap_aes_dma_cleanup (dd); err_irq: -tasklet_kill (&dd->done_task); +cancel_work_sync (&dd->done_task); err_pm_disable:pm_runtime_disable (dev); err_res:
@@ -1280,7 +1281,7 @@ static void omap_aes_remove(struct platform_device *pdev)crypto_engine_exit (dd->engine); -tasklet_kill (&dd->done_task); +cancel_work_sync (&dd->done_task);omap_aes_dma_cleanup (dd);pm_runtime_disable (dd->dev);
drivers/crypto/omap-aes.h +1 -1
@@ -161,7 +161,7 @@ struct omap_aes_dev {unsigned long flags;int err; -struct tasklet_struct done_task; +struct work_struct done_task;struct aead_queue aead_queue;spinlock_t lock;
drivers/crypto/omap-des.c +9 -8
@@ -33,6 +33,7 @@#include <linux/pm_runtime.h> #include <linux/scatterlist.h> #include <linux/string.h> +#include <linux/workqueue.h> #include "omap-crypto.h"
@@ -133,7 +134,7 @@ struct omap_des_dev {unsigned long flags;int err; -struct tasklet_struct done_task; +struct work_struct done_task;struct skcipher_request *req;struct crypto_engine *engine;
@@ -328,7 +329,7 @@ static void omap_des_dma_out_callback(void *data)struct omap_des_dev *dd = data;/* dma_lch_out - completed */ -tasklet_schedule (&dd->done_task); +queue_work (system_bh_wq, &dd->done_task); }static int omap_des_dma_init (struct omap_des_dev *dd)
@@ -584,9 +585,9 @@ static int omap_des_crypt_req(struct crypto_engine *engine,omap_des_crypt_dma_start (dd); } -static void omap_des_done_task (unsigned long data) +static void omap_des_done_task (struct work_struct *t) { -struct omap_des_dev *dd = (struct omap_des_dev *)data; +struct omap_des_dev *dd =from_work (dd, t, done_task);int i;pr_debug ("enter done_task\n" );
@@ -899,7 +900,7 @@ static irqreturn_t omap_des_irq(int irq, void *dev_id)if (!dd->total)/* All bytes read! */ -tasklet_schedule (&dd->done_task); +queue_work (system_bh_wq, &dd->done_task);else /* Enable DATA_IN interrupt for next block */ omap_des_write (dd,DES_REG_IRQ_ENABLE (dd),0x2 );
@@ -1009,7 +1010,7 @@ static int omap_des_probe(struct platform_device *pdev) (reg & dd->pdata->major_mask) >> dd->pdata->major_shift, (reg & dd->pdata->minor_mask) >> dd->pdata->minor_shift); -tasklet_init (&dd->done_task, omap_des_done_task, (unsigned long )dd); +INIT_WORK (&dd->done_task, omap_des_done_task); err =omap_des_dma_init (dd);if (err == -EPROBE_DEFER ) {
@@ -1072,7 +1073,7 @@ static int omap_des_probe(struct platform_device *pdev)omap_des_dma_cleanup (dd); err_irq: -tasklet_kill (&dd->done_task); +cancel_work_sync (&dd->done_task); err_get:pm_runtime_disable (dev); err_res:
@@ -1092,7 +1093,7 @@ static void omap_des_remove(struct platform_device *pdev)omap_des_unregister_algs (dd->pdata); -tasklet_kill (&dd->done_task); +cancel_work_sync (&dd->done_task);omap_des_dma_cleanup (dd);pm_runtime_disable (dd->dev); }
drivers/crypto/omap-sham.c +8 -7
@@ -37,6 +37,7 @@#include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/string.h> +#include <linux/workqueue.h> #define MD5_DIGEST_SIZE 16
@@ -217,7 +218,7 @@ struct omap_sham_dev {int irq;int err;struct dma_chan *dma_lch; -struct tasklet_struct done_task; +struct work_struct done_task;u8 polling_mode; u8 xmit_buf[BUFLEN] OMAP_ALIGNED;
@@ -561,7 +562,7 @@ static void omap_sham_dma_callback(void *param)struct omap_sham_dev *dd = param;set_bit (FLAGS_DMA_READY , &dd->flags); -tasklet_schedule (&dd->done_task); +queue_work (system_bh_wq, &dd->done_task); } static int omap_sham_xmit_dma(struct omap_sham_dev *dd, size_t length,
@@ -1704,9 +1705,9 @@ static struct ahash_engine_alg algs_sha384_sha512[] = { }, }; -static void omap_sham_done_task (unsigned long data) +static void omap_sham_done_task (struct work_struct *t) { -struct omap_sham_dev *dd = (struct omap_sham_dev *)data; +struct omap_sham_dev *dd =from_work (dd, t, done_task);int err =0 ;dev_dbg (dd->dev,"%s: flags=%lx\n" , __func__, dd->flags);
@@ -1740,7 +1741,7 @@ static void omap_sham_done_task(unsigned long data)static irqreturn_t omap_sham_irq_common (struct omap_sham_dev *dd) {set_bit (FLAGS_OUTPUT_READY , &dd->flags); -tasklet_schedule (&dd->done_task); +queue_work (system_bh_wq, &dd->done_task);return IRQ_HANDLED ; }
@@ -2063,7 +2064,7 @@ static int omap_sham_probe(struct platform_device *pdev)platform_set_drvdata (pdev, dd);INIT_LIST_HEAD (&dd->list); -tasklet_init (&dd->done_task, omap_sham_done_task, (unsigned long )dd); +INIT_WORK (&dd->done_task, omap_sham_done_task);crypto_init_queue (&dd->queue,OMAP_SHAM_QUEUE_LENGTH ); err = (dev->of_node) ? omap_sham_get_res_of(dd, dev, &res) :
@@ -2204,7 +2205,7 @@ static void omap_sham_remove(struct platform_device *pdev) &dd->pdata->algs_info[i].algs_list[j]); dd->pdata->algs_info[i].registered--; } -tasklet_kill (&dd->done_task); +cancel_work_sync (&dd->done_task);pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_disable (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/670 crypto: omap-des - fix crypto engine cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 5d69ed4cd4f9c68ff9a6ebb2e8a1079223a4ec6e ]
omap_des_probe() allocates and starts a crypto engine, but the remove path does not call the matching crypto_engine_exit(). The probe failure path already performs this cleanup.
crypto_engine_alloc_init() creates a kthread worker for processing requests. Without crypto_engine_exit() during driver removal, the worker is left running after the device is removed.
Call crypto_engine_exit() after unregistering the algorithms and before tearing down the remaining request handling resources. This stops the engine and destroys its worker.
This issue was found by manual code inspection.
--- drivers/crypto/omap-des.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/crypto/omap-des.c +2 -0
@@ -1093,6 +1093,8 @@ static void omap_des_remove(struct platform_device *pdev)omap_des_unregister_algs (dd->pdata); +crypto_engine_exit (dd->engine); +cancel_work_sync (&dd->done_task);omap_des_dma_cleanup (dd);pm_runtime_disable (dd->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/670 iio: adc: ad7192: Revert "properly check spi_get_device_match_data()"
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 0309e66abea141f3ec339b064b8f8b8003d2a634 ]
This reverts commit b7f99fa1b64af2f696b13cec581cb4cd7d3982b8.
The added code is currently a dead code. Moreover, the driver is not designed to have any defaults effectively making driver data a mandatory information to work with. Taking all together, revert unneeded change.
Discussion at #1 concluded in agreeing a new policy on this for IIO.
Stable-dep-of: 7f7a119a370e ("iio: adc: ad7192: reject devices without match data")
--- drivers/iio/adc/ad7192.c | 3 --- 1 file changed, 3 deletions(-)
drivers/iio/adc/ad7192.c +0 -3
@@ -1394,9 +1394,6 @@ static int ad7192_probe(struct spi_device *spi) st->int_vref_mv = ret == -ENODEV ? avdd_mv : ret /MILLI ; st->chip_info =spi_get_device_match_data (spi); -if (!st->chip_info) -return -ENODEV ; - indio_dev->name = st->chip_info->name; indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->info = st->chip_info->info;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/670 iio: adc: ad7192: reject devices without match data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 7f7a119a370ecf6c8d4ab9e9ee0a8cdd77afedd3 ]
SPI driver_override allows a device to bind to this driver without matching either the OF or SPI device ID table. In that case, spi_get_device_match_data() returns NULL.
ad7192_probe() immediately dereferences the returned chip information to initialize the IIO device, causing a NULL pointer dereference.
Commit 572a00852635 ("iio: dac: ad5686: missing NULL check on match data") fixed the same driver_override issue in another SPI driver. Reject devices without match data before using the chip information.
--- drivers/iio/adc/ad7192.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/adc/ad7192.c +3 -0
@@ -1394,6 +1394,9 @@ static int ad7192_probe(struct spi_device *spi) st->int_vref_mv = ret == -ENODEV ? avdd_mv : ret /MILLI ; st->chip_info =spi_get_device_match_data (spi); +if (!st->chip_info) +return -ENODATA ; + indio_dev->name = st->chip_info->name; indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->info = st->chip_info->info;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/670 ALSA: core: Clean up file_operations definitions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 307835a6eb50e548e58ee604bf91909d4faa4203 ]
Align file_operations initializers with tabs to match the standard kernel coding style and improve readability.
Stable-dep-of: 1bbc033983b7 ("ALSA: timer: Handle userspace-driven timer ioctls from 32-bit tasks")
--- sound/core/compress_offload.c | 18 +++++++------- sound/core/control.c | 19 +++++++-------- sound/core/hwdep.c | 23 +++++++++--------- sound/core/init.c | 23 +++++++++--------- sound/core/jack.c | 38 ++++++++++++++--------------- sound/core/oss/mixer_oss.c | 13 +++++----- sound/core/oss/pcm_oss.c | 21 ++++++++-------- sound/core/pcm_native.c | 44 +++++++++++++++++----------------- sound/core/rawmidi.c | 16 ++++++------- sound/core/seq/oss/seq_oss.c | 21 ++++++++-------- sound/core/seq/seq_clientmgr.c | 19 +++++++-------- sound/core/sound.c | 9 ++++--- sound/core/timer.c | 25 ++++++++++--------- 13 files changed, 140 insertions(+), 149 deletions(-)
sound/core/compress_offload.c +9 -9
@@ -1014,17 +1014,17 @@ static long snd_compr_ioctl_compat(struct file *file, unsigned int cmd,#endif static const struct file_operations snd_compr_file_ops = { - .owner =THIS_MODULE , - .open = snd_compr_open, - .release = snd_compr_free, - .write = snd_compr_write, - .read = snd_compr_read, - .unlocked_ioctl = snd_compr_ioctl, + .owner =THIS_MODULE , + .open = snd_compr_open, + .release = snd_compr_free, + .write = snd_compr_write, + .read = snd_compr_read, + .unlocked_ioctl = snd_compr_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = snd_compr_ioctl_compat, + .compat_ioctl = snd_compr_ioctl_compat, #endif - .mmap = snd_compr_mmap, - .poll = snd_compr_poll, + .mmap = snd_compr_mmap, + .poll = snd_compr_poll, };static int snd_compress_dev_register (struct snd_device *device)
sound/core/control.c +9 -10
@@ -2269,16 +2269,15 @@ EXPORT_SYMBOL_GPL(snd_ctl_disconnect_layer);* INIT PART */ -static const struct file_operations snd_ctl_f_ops = -{ - .owner =THIS_MODULE , - .read = snd_ctl_read, - .open = snd_ctl_open, - .release = snd_ctl_release, - .poll = snd_ctl_poll, - .unlocked_ioctl = snd_ctl_ioctl, - .compat_ioctl = snd_ctl_ioctl_compat, - .fasync = snd_ctl_fasync, +static const struct file_operations snd_ctl_f_ops = { + .owner =THIS_MODULE , + .read = snd_ctl_read, + .open = snd_ctl_open, + .release = snd_ctl_release, + .poll = snd_ctl_poll, + .unlocked_ioctl = snd_ctl_ioctl, + .compat_ioctl = snd_ctl_ioctl_compat, + .fasync = snd_ctl_fasync, };/* call lops under rwsems; called from snd_ctl_dev_*() below() */
sound/core/hwdep.c +11 -12
@@ -324,18 +324,17 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,*/ -static const struct file_operations snd_hwdep_f_ops = -{ - .owner =THIS_MODULE , - .llseek = snd_hwdep_llseek, - .read = snd_hwdep_read, - .write = snd_hwdep_write, - .open = snd_hwdep_open, - .release = snd_hwdep_release, - .poll = snd_hwdep_poll, - .unlocked_ioctl = snd_hwdep_ioctl, - .compat_ioctl = snd_hwdep_ioctl_compat, - .mmap = snd_hwdep_mmap, +static const struct file_operations snd_hwdep_f_ops = { + .owner =THIS_MODULE , + .llseek = snd_hwdep_llseek, + .read = snd_hwdep_read, + .write = snd_hwdep_write, + .open = snd_hwdep_open, + .release = snd_hwdep_release, + .poll = snd_hwdep_poll, + .unlocked_ioctl = snd_hwdep_ioctl, + .compat_ioctl = snd_hwdep_ioctl_compat, + .mmap = snd_hwdep_mmap, };static void snd_hwdep_free (struct snd_hwdep *hwdep)
sound/core/init.c +11 -12
@@ -461,20 +461,19 @@ static int snd_disconnect_fasync(int fd, struct file *file, int on)return -ENODEV ; } -static const struct file_operations snd_shutdown_f_ops = -{ - .owner =THIS_MODULE , - .llseek = snd_disconnect_llseek, - .read = snd_disconnect_read, - .write = snd_disconnect_write, - .release = snd_disconnect_release, - .poll = snd_disconnect_poll, - .unlocked_ioctl = snd_disconnect_ioctl, +static const struct file_operations snd_shutdown_f_ops = { + .owner =THIS_MODULE , + .llseek = snd_disconnect_llseek, + .read = snd_disconnect_read, + .write = snd_disconnect_write, + .release = snd_disconnect_release, + .poll = snd_disconnect_poll, + .unlocked_ioctl = snd_disconnect_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = snd_disconnect_ioctl, + .compat_ioctl = snd_disconnect_ioctl, #endif - .mmap = snd_disconnect_mmap, - .fasync = snd_disconnect_fasync + .mmap = snd_disconnect_mmap, + .fasync = snd_disconnect_fasync };/**
sound/core/jack.c +19 -19
@@ -304,41 +304,41 @@ static ssize_t jack_type_read(struct file *file, }static const struct file_operations jack_type_fops = { - .open = simple_open, - .read = jack_type_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_type_read, + .llseek = default_llseek, };#endif static const struct file_operations sw_inject_enable_fops = { - .open = simple_open, - .read = sw_inject_enable_read, - .write = sw_inject_enable_write, - .llseek = default_llseek, + .open = simple_open, + .read = sw_inject_enable_read, + .write = sw_inject_enable_write, + .llseek = default_llseek, };static const struct file_operations jackin_inject_fops = { - .open = simple_open, - .write = jackin_inject_write, - .llseek = default_llseek, + .open = simple_open, + .write = jackin_inject_write, + .llseek = default_llseek, };static const struct file_operations jack_kctl_id_fops = { - .open = simple_open, - .read = jack_kctl_id_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_kctl_id_read, + .llseek = default_llseek, };static const struct file_operations jack_kctl_mask_bits_fops = { - .open = simple_open, - .read = jack_kctl_mask_bits_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_kctl_mask_bits_read, + .llseek = default_llseek, };static const struct file_operations jack_kctl_status_fops = { - .open = simple_open, - .read = jack_kctl_status_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_kctl_status_read, + .llseek = default_llseek, }; static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack,
sound/core/oss/mixer_oss.c +6 -7
@@ -407,13 +407,12 @@ static long snd_mixer_oss_ioctl_compat(struct file *file, unsigned int cmd,* REGISTRATION PART */ -static const struct file_operations snd_mixer_oss_f_ops = -{ - .owner =THIS_MODULE , - .open = snd_mixer_oss_open, - .release = snd_mixer_oss_release, - .unlocked_ioctl = snd_mixer_oss_ioctl, - .compat_ioctl = snd_mixer_oss_ioctl_compat, +static const struct file_operations snd_mixer_oss_f_ops = { + .owner =THIS_MODULE , + .open = snd_mixer_oss_open, + .release = snd_mixer_oss_release, + .unlocked_ioctl = snd_mixer_oss_ioctl, + .compat_ioctl = snd_mixer_oss_ioctl_compat, };/*
sound/core/oss/pcm_oss.c +10 -11
@@ -3121,17 +3121,16 @@ static inline void snd_pcm_oss_proc_done(struct snd_pcm *pcm)* ENTRY functions */ -static const struct file_operations snd_pcm_oss_f_reg = -{ - .owner =THIS_MODULE , - .read = snd_pcm_oss_read, - .write = snd_pcm_oss_write, - .open = snd_pcm_oss_open, - .release = snd_pcm_oss_release, - .poll = snd_pcm_oss_poll, - .unlocked_ioctl = snd_pcm_oss_ioctl, - .compat_ioctl = snd_pcm_oss_ioctl_compat, - .mmap = snd_pcm_oss_mmap, +static const struct file_operations snd_pcm_oss_f_reg = { + .owner =THIS_MODULE , + .read = snd_pcm_oss_read, + .write = snd_pcm_oss_write, + .open = snd_pcm_oss_open, + .release = snd_pcm_oss_release, + .poll = snd_pcm_oss_poll, + .unlocked_ioctl = snd_pcm_oss_ioctl, + .compat_ioctl = snd_pcm_oss_ioctl_compat, + .mmap = snd_pcm_oss_mmap, };static void register_oss_dsp (struct snd_pcm *pcm,int index)
sound/core/pcm_native.c +22 -22
51 lines not on this page · raw message
sound/core/rawmidi.c +8 -8
@@ -1784,14 +1784,14 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,*/ static const struct file_operations snd_rawmidi_f_ops = { - .owner =THIS_MODULE , - .read = snd_rawmidi_read, - .write = snd_rawmidi_write, - .open = snd_rawmidi_open, - .release = snd_rawmidi_release, - .poll = snd_rawmidi_poll, - .unlocked_ioctl = snd_rawmidi_ioctl, - .compat_ioctl = snd_rawmidi_ioctl_compat, + .owner =THIS_MODULE , + .read = snd_rawmidi_read, + .write = snd_rawmidi_write, + .open = snd_rawmidi_open, + .release = snd_rawmidi_release, + .poll = snd_rawmidi_poll, + .unlocked_ioctl = snd_rawmidi_ioctl, + .compat_ioctl = snd_rawmidi_ioctl_compat, }; static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
sound/core/seq/oss/seq_oss.c +10 -11
@@ -211,17 +211,16 @@ odev_poll(struct file *file, poll_table * wait)* registration of sequencer minor device */ -static const struct file_operations seq_oss_f_ops = -{ - .owner =THIS_MODULE , - .read = odev_read, - .write = odev_write, - .open = odev_open, - .release = odev_release, - .poll = odev_poll, - .unlocked_ioctl = odev_ioctl, - .compat_ioctl = odev_ioctl_compat, - .llseek = noop_llseek, +static const struct file_operations seq_oss_f_ops = { + .owner =THIS_MODULE , + .read = odev_read, + .write = odev_write, + .open = odev_open, + .release = odev_release, + .poll = odev_poll, + .unlocked_ioctl = odev_ioctl, + .compat_ioctl = odev_ioctl_compat, + .llseek = noop_llseek, }; static int __init
sound/core/seq/seq_clientmgr.c +9 -10
@@ -2785,16 +2785,15 @@ void snd_seq_info_clients_read(struct snd_info_entry *entry,* REGISTRATION PART */ -static const struct file_operations snd_seq_f_ops = -{ - .owner =THIS_MODULE , - .read = snd_seq_read, - .write = snd_seq_write, - .open = snd_seq_open, - .release = snd_seq_release, - .poll = snd_seq_poll, - .unlocked_ioctl = snd_seq_ioctl, - .compat_ioctl = snd_seq_ioctl_compat, +static const struct file_operations snd_seq_f_ops = { + .owner =THIS_MODULE , + .read = snd_seq_read, + .write = snd_seq_write, + .open = snd_seq_open, + .release = snd_seq_release, + .poll = snd_seq_poll, + .unlocked_ioctl = snd_seq_ioctl, + .compat_ioctl = snd_seq_ioctl_compat, };static struct device *seq_dev;
sound/core/sound.c +4 -5
@@ -167,11 +167,10 @@ static int snd_open(struct inode *inode, struct file *file)return err; } -static const struct file_operations snd_fops = -{ - .owner =THIS_MODULE , - .open = snd_open, - .llseek = noop_llseek, +static const struct file_operations snd_fops = { + .owner =THIS_MODULE , + .open = snd_open, + .llseek = noop_llseek, };#ifdef CONFIG_SND_DYNAMIC_MINORS
sound/core/timer.c +12 -13
@@ -2101,9 +2101,9 @@ static long snd_utimer_ioctl(struct file *file, unsigned int ioctl, unsigned lon }static const struct file_operations snd_utimer_fops = { - .llseek = noop_llseek, - .release = snd_utimer_release, - .unlocked_ioctl = snd_utimer_ioctl, + .llseek = noop_llseek, + .release = snd_utimer_release, + .unlocked_ioctl = snd_utimer_ioctl, };static int snd_utimer_start (struct snd_timer *t)
@@ -2455,16 +2455,15 @@ static __poll_t snd_timer_user_poll(struct file *file, poll_table * wait)#define snd_timer_user_ioctl_compat NULL#endif -static const struct file_operations snd_timer_f_ops = -{ - .owner =THIS_MODULE , - .read = snd_timer_user_read, - .open = snd_timer_user_open, - .release = snd_timer_user_release, - .poll = snd_timer_user_poll, - .unlocked_ioctl = snd_timer_user_ioctl, - .compat_ioctl = snd_timer_user_ioctl_compat, - .fasync = snd_timer_user_fasync, +static const struct file_operations snd_timer_f_ops = { + .owner =THIS_MODULE , + .read = snd_timer_user_read, + .open = snd_timer_user_open, + .release = snd_timer_user_release, + .poll = snd_timer_user_poll, + .unlocked_ioctl = snd_timer_user_ioctl, + .compat_ioctl = snd_timer_user_ioctl_compat, + .fasync = snd_timer_user_fasync, };/* unregister the system timer */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/670 ALSA: timer: Handle userspace-driven timer ioctls from 32-bit tasks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit 1bbc033983b76f41d51d4a48838bf94c5e6b6f50 ]
32-bit tasks on a 64-bit kernel can't use userspace-driven timers. The compat handler for /dev/snd/timer doesn't list SNDRV_TIMER_IOCTL_CREATE, so creating a timer fails with -ENOTTY. The file returned for a timer has no .compat_ioctl either, so SNDRV_TIMER_IOCTL_TRIGGER fails with -ENOTTY too.
struct snd_timer_uinfo has the same layout for 32-bit and 64-bit tasks, and SNDRV_TIMER_IOCTL_TRIGGER takes no argument, so both commands can be passed through unchanged.
The utimer selftest doesn't catch this when built with -m32: it takes -ENOTTY from SNDRV_TIMER_IOCTL_CREATE to mean CONFIG_SND_UTIMER=n and skips.
--- sound/core/timer.c | 1 + sound/core/timer_compat.c | 1 + 2 files changed, 2 insertions(+)
sound/core/timer.c +1 -0
@@ -2104,6 +2104,7 @@ static const struct file_operations snd_utimer_fops = { .llseek = noop_llseek, .release = snd_utimer_release, .unlocked_ioctl = snd_utimer_ioctl, + .compat_ioctl = snd_utimer_ioctl, };static int snd_utimer_start (struct snd_timer *t)
sound/core/timer_compat.c +1 -0
@@ -98,6 +98,7 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,case SNDRV_TIMER_IOCTL_PAUSE :case SNDRV_TIMER_IOCTL_PAUSE_OLD :case SNDRV_TIMER_IOCTL_NEXT_DEVICE : +case SNDRV_TIMER_IOCTL_CREATE :return __snd_timer_user_ioctl (file, cmd, (unsigned long )argp, true);case SNDRV_TIMER_IOCTL_GPARAMS32 :return snd_timer_user_gparams_compat (file, argp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/670 KVM: arm64: timers: Compute an offset-applied CVAL from the current count
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 49930b1b557ceb698e0ab7f985ea41c99dc8bf22 ]
When the hardware won't apply a timer's offset, KVM programs CVAL + offset and lets it compare that against the raw counter. The compare is unsigned (IsTimerConditionMet, DDI0487M_c J1.4.3.29):
condition_met = (UInt(PhysicalCountInt() - offset) -
UInt(compare_value)) >= 0;so adding the offset to both sides holds only while both sums wrap or neither does. A guest whose counter is ahead of the host's by more than CVAL has an expired timer that never fires, and one behind it can have a far-future timer fire at once.
On a CNTPOFF_EL2 host the first case livelocks: each entry reloads the guest's CVAL, the timer fires, and the exit rewrites it as CVAL + offset before the host can take the interrupt. Without CNTPOFF_EL2 the timer hangs until the vCPU is next loaded, which is what Zenghui reported on a Kunpeng920.
Program the value from the current count instead: CVAL + offset while the deadline is ahead, 0 once the timer has expired for the guest, ~0 past the counter's wrap. KVM recomputes it at load, at exit and on a trapped CVAL write, and an expired timer stays expired in between. The value can't be inverted, so with an offset timer_save_state() keeps the memory copy, and kvm_hyp_handle_timer() returns that copy for a guest hypervisor's read of its physical CVAL rather than subtracting the offset back out.
--- arch/arm64/kvm/arch_timer.c | 16 ++++++++-------- arch/arm64/kvm/hyp/vhe/switch.c | 3 ++- include/kvm/arm_arch_timer.h | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-)
arch/arm64/kvm/arch_timer.c +8 -8
@@ -506,8 +506,6 @@ static void timer_save_state(struct arch_timer_context *ctx) goto out;switch (index) { -u64 cval; -case TIMER_VTIMER :case TIMER_HVTIMER :timer_set_ctl (ctx,read_sysreg_el0 (SYS_CNTV_CTL ));
@@ -537,11 +535,12 @@ static void timer_save_state(struct arch_timer_context *ctx)case TIMER_PTIMER :case TIMER_HPTIMER :timer_set_ctl (ctx,read_sysreg_el0 (SYS_CNTP_CTL )); - cval =read_sysreg_el0 (SYS_CNTP_CVAL ); - - cval -=timer_get_offset (ctx); - -timer_set_cval (ctx, cval); +/* +* With an offset, memory already holds the guest's CVAL (the +* trap handler or __deactivate_traps() wrote it). +*/ +if (!timer_get_offset (ctx)) +timer_set_cval (ctx,read_sysreg_el0 (SYS_CNTP_CVAL ));/* Disable the timer */ write_sysreg_el0 (0 ,SYS_CNTP_CTL );
@@ -626,7 +625,8 @@ static void timer_restore_state(struct arch_timer_context *ctx) cval =timer_get_cval (ctx); offset =timer_get_offset (ctx);set_cntpoff (offset); - cval += offset; +if (offset) + cval =timer_apply_offset (cval, offset,kvm_phys_timer_read ());write_sysreg_el0 (cval,SYS_CNTP_CVAL );isb ();write_sysreg_el0 (timer_get_ctl (ctx),SYS_CNTP_CTL );
arch/arm64/kvm/hyp/vhe/switch.c +2 -1
@@ -195,7 +195,8 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) offset =read_sysreg_s (SYS_CNTPOFF_EL2 );if (map.direct_ptimer && offset) { -write_sysreg_el0 (val + offset,SYS_CNTP_CVAL ); + val =timer_apply_offset (val, offset,arch_timer_read_cntpct_el0 ()); +write_sysreg_el0 (val,SYS_CNTP_CVAL );isb (); } }
include/kvm/arm_arch_timer.h +15 -0
@@ -152,4 +152,19 @@ static inline bool has_cntpoff(void) return (has_vhe() && cpus_have_final_cap(ARM64_HAS_ECV_CNTPOFF)); } +/* +* CVAL to program when the hardware won't apply the timer's offset, so that +* its compare against the raw counter matches the guest's at 'now'. An +* expired timer stays expired; one past the wrap never fires. +*/ +static inline u64 timer_apply_offset (u64 cval,u64 offset,u64 now) +{ +u64 hw = cval + offset; + +if (now - offset >= cval) +return 0 ; + +return hw > now ? hw :U64_MAX ; +} +#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/670 power: supply: pmi8998_charger: rename to qcom_smbx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Casey Connolly <[email protected]>
[ Upstream commit 5ec53bcc7fce6801977a0c125fb726d7b0e9102c ]
Prepare to add smb5 support by making variables and the file name more generic. Also take the opportunity to remove the "_charger" suffix since smb2 always refers to a charger.
Stable-dep-of: a2d7dc538da2 ("power: supply: qcom_smbx: validate battery float voltage")
---
drivers/power/supply/Makefile | 2 +-
.../{qcom_pmi8998_charger.c => qcom_smbx.c} | 148 +++++++++---------
2 files changed, 75 insertions(+), 75 deletions(-)
rename drivers/power/supply/{qcom_pmi8998_charger.c => qcom_smbx.c} (88%)drivers/power/supply/Makefile +1 -1
@@ -115,5 +115,5 @@ obj-$(CONFIG_BATTERY_ACER_A500) += acer_a500_battery.o obj-$(CONFIG_BATTERY_SURFACE) += surface_battery.o obj-$(CONFIG_CHARGER_SURFACE) += surface_charger.o obj-$(CONFIG_BATTERY_UG3105) += ug3105_battery.o -obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_pmi8998_charger.o +obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_smbx.o obj-$(CONFIG_FUEL_GAUGE_MM8013) += mm8013.o
drivers/power/supply/qcom_smbx.c renamed from drivers/power/supply/qcom_pmi8998_charger.c +74 -74
405 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/670 power: supply: qcom_smbx: validate battery float voltage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robin Snyders <[email protected]>
[ Upstream commit a2d7dc538da2cb4a7426f0742197e762cb635f38 ]
power_supply_get_battery_info() leaves absent optional properties at -EINVAL. The driver uses voltage_max_design_uv without checking it, so a missing or out-of-range value can become an invalid float-voltage selector.
Prefer the constant-charge voltage because it describes the charger's CV target, then fall back to the battery design voltage. Both properties are optional in the simple-battery binding, so preserve the hardware setting when neither is present. Reject a supplied target outside the SMB2 range.
smb_init_hw() enables charging before battery data is parsed and before the remaining fallible probe steps. Save the initial charging-enable bit and install a managed rollback before initialization. Keep the rollback active across battery-info, voltage, IRQ and wake-IRQ setup, then remove it only after probe can no longer fail.
--- drivers/power/supply/qcom_smbx.c | 61 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-)
drivers/power/supply/qcom_smbx.c +58 -3
@@ -350,6 +350,7 @@/* pmi8998 registers represent current in increments of 1/40th of an amp */ #define CURRENT_SCALE_FACTOR 25000#define SMB2_FLOAT_VOLTAGE_MIN_UV 3487500 +#define SMB2_FLOAT_VOLTAGE_MAX_UV 4920000#define SMB2_FLOAT_VOLTAGE_STEP_UV 7500/* clang-format on */
@@ -377,6 +378,7 @@ struct smb_init_register {* @base: Base address for smb registers * @regmap: Register map * @batt_info: Battery data from DT +* @initial_charge_enable: Charging enable state before hardware setup * @status_change_work: Worker to handle plug/unplug events * @cable_irq: USB plugin IRQ * @wakeup_enabled: If the cable IRQ will cause a wakeup
@@ -390,6 +392,7 @@ struct smb_chip {unsigned int base;struct regmap *regmap;struct power_supply_battery_info *batt_info; +u8 initial_charge_enable;struct delayed_work status_change_work;int cable_irq;
@@ -904,6 +907,19 @@ static int smb_init_hw(struct smb_chip *chip)return 0 ; } +static void smb_restore_charge_enable (void *data) +{ +struct smb_chip *chip = data; +int rc; + + rc =regmap_update_bits (chip->regmap, + chip->base +CHARGING_ENABLE_CMD , +CHARGING_ENABLE_CMD_BIT , + chip->initial_charge_enable); +if (rc <0 ) +dev_err (chip->dev,"Couldn't restore charging state: %d\n" , rc); +} +static int smb_init_irq (struct smb_chip *chip,int *irq,const char *name,irqreturn_t (*handler)(int irq,void *data)) {
@@ -931,6 +947,9 @@ static int smb_probe(struct platform_device *pdev)struct power_supply_config supply_config = {};struct power_supply_desc *desc;struct smb_chip *chip; +unsigned int charge_enable; +unsigned int float_voltage_sel; +int float_voltage_uv;int rc, irq; chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL );
@@ -961,6 +980,18 @@ static int smb_probe(struct platform_device *pdev) "Couldn't get usbin_i IIO channel\n"); } + rc =regmap_read (chip->regmap, chip->base +CHARGING_ENABLE_CMD , + &charge_enable); +if (rc <0 ) +return dev_err_probe (chip->dev, rc, +"Couldn't read charging state\n" ); + + chip->initial_charge_enable = charge_enable &CHARGING_ENABLE_CMD_BIT ; + rc =devm_add_action_or_reset (chip->dev, smb_restore_charge_enable, chip); +if (rc) +return dev_err_probe (chip->dev, rc, +"Couldn't register charging state rollback\n" ); + rc =smb_init_hw (chip);if (rc <0 )return rc;
@@ -995,13 +1026,35 @@ static int smb_probe(struct platform_device *pdev)return dev_err_probe (chip->dev, rc,"Failed to init status change work\n" ); - rc = (chip->batt_info->voltage_max_design_uv - -SMB2_FLOAT_VOLTAGE_MIN_UV ) /SMB2_FLOAT_VOLTAGE_STEP_UV ; +if (power_supply_battery_info_has_prop (chip->batt_info, +POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX )) { + float_voltage_uv = + chip->batt_info->constant_charge_voltage_max_uv; + }else if (power_supply_battery_info_has_prop (chip->batt_info, +POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN )) { + float_voltage_uv = chip->batt_info->voltage_max_design_uv; + }else { +dev_warn (chip->dev,"No battery float voltage; preserving hardware setting\n" ); + goto skip_float_voltage; + } + +if (float_voltage_uv <SMB2_FLOAT_VOLTAGE_MIN_UV || + float_voltage_uv >SMB2_FLOAT_VOLTAGE_MAX_UV ) +return dev_err_probe (chip->dev, -EINVAL , +"float voltage %d uV outside %d-%d uV\n" , + float_voltage_uv, +SMB2_FLOAT_VOLTAGE_MIN_UV , +SMB2_FLOAT_VOLTAGE_MAX_UV ); + + float_voltage_sel = + (float_voltage_uv -SMB2_FLOAT_VOLTAGE_MIN_UV ) / +SMB2_FLOAT_VOLTAGE_STEP_UV ; rc =regmap_update_bits (chip->regmap, chip->base +FLOAT_VOLTAGE_CFG , -FLOAT_VOLTAGE_SETTING_MASK , rc); +FLOAT_VOLTAGE_SETTING_MASK , float_voltage_sel);if (rc <0 )return dev_err_probe (chip->dev, rc,"Couldn't set vbat max\n" ); +skip_float_voltage: rc =smb_init_irq (chip, &irq,"bat-ov" , smb_handle_batt_overvoltage);if (rc <0 )return rc;
@@ -1023,6 +1076,8 @@ static int smb_probe(struct platform_device *pdev)if (rc <0 )return dev_err_probe (chip->dev, rc,"Couldn't set wake irq\n" ); +devm_remove_action (chip->dev, smb_restore_charge_enable, chip); +platform_set_drvdata (pdev, chip);/* Initialise charger state */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/670 ALSA: usb-audio: Protect Roland control activation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 19b42c1fff7f220a6346c614d79ce1bda6d95b40 ]
The USB MIDI driver changes the Roland MIDI Input Mode control's access flags directly from the rawmidi open and close paths. These changes are not protected by the ALSA control core and the corresponding notifications can race with control access.
Use snd_ctl_activate_id() so that the control core updates the access flags and sends the notification under its lock. Release the USB MIDI mutex before calling it because the control write path holds controls_rwsem while roland_load_put() takes the USB MIDI mutex.
Keep the state transition and alternate-setting change under the USB MIDI mutex; rawmidi's open mutex serializes the enclosing open and close paths.
--- sound/usb/midi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
sound/usb/midi.c +11 -11
@@ -1152,7 +1152,9 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir, int open) {struct snd_usb_midi *umidi = substream->rmidi->private_data; -struct snd_kcontrol *ctl; +struct snd_ctl_elem_id ctl_id; +bool activate_ctl = false; +bool active;down_read (&umidi->disc_rwsem);if (umidi->disconnected) {
@@ -1164,11 +1166,9 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir,if (open) {if (!umidi->opened[0 ] && !umidi->opened[1 ]) {if (umidi->roland_load_ctl) { - ctl = umidi->roland_load_ctl; - ctl->vd[0 ].access |= -SNDRV_CTL_ELEM_ACCESS_INACTIVE ; -snd_ctl_notify (umidi->card, -SNDRV_CTL_EVENT_MASK_INFO , &ctl->id); + ctl_id = umidi->roland_load_ctl->id; + activate_ctl = true; + active = false;update_roland_altsetting (umidi); } }
@@ -1181,15 +1181,15 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir,snd_usbmidi_input_stop (&umidi->list);if (!umidi->opened[0 ] && !umidi->opened[1 ]) {if (umidi->roland_load_ctl) { - ctl = umidi->roland_load_ctl; - ctl->vd[0 ].access &= - ~SNDRV_CTL_ELEM_ACCESS_INACTIVE ; -snd_ctl_notify (umidi->card, -SNDRV_CTL_EVENT_MASK_INFO , &ctl->id); + ctl_id = umidi->roland_load_ctl->id; + activate_ctl = true; + active = true; } } }mutex_unlock (&umidi->mutex); +if (activate_ctl) +snd_ctl_activate_id (umidi->card, &ctl_id, active);up_read (&umidi->disc_rwsem);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 448/670 ocfs2: restrict OCFS2_INVALID_SLOT suballoc slot to system inodes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 25bf9e549360b656a6763232e0e9e58a00c3aff7 ]
Patch series "ocfs2: validate suballoc slot and bit of metadata blocks", v3.
The ocfs2 metadata validators trust the on-disk suballoc slot and bit without checking them against the slot range of the mounted filesystem and the capacity of the block group bitmap. A corrupted image can carry OCFS2_INVALID_SLOT or another out-of-range slot, or a suballoc bit beyond the bitmap, and once the corresponding inode, extent block, xattr block, dir index root or refcount block gets freed, the bad value goes straight into ocfs2_get_system_file_inode() or _ocfs2_free_suballoc_bits() and hits a BUG_ON() or runs off the end of local_system_inodes[].
This series rejects such values at read time, in the existing validators, so corrupted objects fail with -EROFS (and a read-only remount) instead of crashing:
patch 1 restricts OCFS2_INVALID_SLOT dinodes to system inodes,
completing fe7a283b3916 ("ocfs2: add suballoc slot check in ocfs2_validate_inode_block()"), and turns the "system file state is ambiguous" BUG_ON() in ocfs2_read_locked_inode() into an ocfs2_error();
patch 2 rejects oversized dinode suballoc bits;
patch 3 validates the suballoc slot and bit of xattr and dir index
blocks;
patch 4 validates the suballoc slot and bit of extent and refcount
blocks.
The checks only enforce what the kernel and mkfs.ocfs2 already write: a valid slot from meta_ac->ac_alloc_slot and a bit within the block group bitmap, with system inodes carrying OCFS2_INVALID_SLOT plus OCFS2_SYSTEM_FL and extent blocks using slot 0. Nothing changes for healthy filesystems.
Each new check was exercised under QEMU by corrupting the field in question with an out-of-range value; with the series applied the access fails with -EROFS and the filesystem remounts read-only instead of hitting the BUG_ON().
This patch (of 4):
ocfs2_validate_inode_block() currently permits i_suballoc_slot to be OCFS2_INVALID_SLOT for any dinode. Only system inodes created by mkfs.ocfs2 are allocated from the global allocator and thus legitimately carry this value; regular inodes are always allocated from a per-slot suballocator and hence must have a valid slot.
If a corrupted regular inode with OCFS2_INVALID_SLOT is accepted, ocfs2_remove_inode() will pass the slot to ocfs2_get_system_file_inode() and get_local_system_inode() will hit BUG_ON(slot == OCFS2_INVALID_SLOT) when the inode is deleted. This can be triggered by an unprivileged user unlinking such a corrupted file.
Reject OCFS2_INVALID_SLOT for non-system dinodes during validation, while still accepting it for system inodes. Note that a crafted dinode carrying OCFS2_SYSTEM_FL passes the check above, yet a plain lookup of it still used to BUG() in ocfs2_read_locked_inode() ("system file state is ambiguous"). Since i_flags comes from disk, handle that mismatch with ocfs2_error() instead of BUG_ON() as well.
--- fs/ocfs2/inode.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
fs/ocfs2/inode.c +28 -9
@@ -575,14 +575,18 @@ static int ocfs2_read_locked_inode(struct inode *inode, fe = (struct ocfs2_dinode *) bh->b_data;/* -* This is a code bug. Right now the caller needs to -* understand whether it is asking for a system file inode or -* not so the proper lock names can be built. +* The caller must know whether it is asking for a system file inode +* or not so the proper lock names can be built. Since i_flags comes +* from disk, a mismatch is filesystem corruption instead of a code +* bug, so handle it with ocfs2_error() rather than BUG_ON(). */ -mlog_bug_on_msg (!!(fe->i_flags &cpu_to_le32 (OCFS2_SYSTEM_FL )) != - !!(args->fi_flags &OCFS2_FI_FLAG_SYSFILE ), -"Inode %llu: system file state is ambiguous\n" , - (unsigned long long )args->fi_blkno); +if (!!(fe->i_flags &cpu_to_le32 (OCFS2_SYSTEM_FL )) != + !!(args->fi_flags &OCFS2_FI_FLAG_SYSFILE )) { + status =ocfs2_error (osb->sb, +"Inode %llu: system file state is ambiguous\n" , + (unsigned long long )args->fi_blkno); + goto bail; + }if (S_ISCHR (le16_to_cpu (fe->i_mode)) ||S_ISBLK (le16_to_cpu (fe->i_mode)))
@@ -1599,8 +1603,23 @@ int ocfs2_validate_inode_block(struct super_block *sb, } } -if (le16_to_cpu (di->i_suballoc_slot) != (u16 )OCFS2_INVALID_SLOT && - (u32 )le16_to_cpu (di->i_suballoc_slot) >OCFS2_SB (sb)->max_slots -1 ) { +/* +* Only system inodes created by mkfs.ocfs2 are allocated from the +* global allocator and thus legitimately carry OCFS2_INVALID_SLOT. +* Regular inodes are always allocated from a per-slot suballocator. +* If a regular inode with OCFS2_INVALID_SLOT was accepted here, +* deleting it would pass the slot to get_local_system_inode() via +* ocfs2_remove_inode() and trigger BUG_ON(slot == OCFS2_INVALID_SLOT). +*/ +if (le16_to_cpu (di->i_suballoc_slot) == (u16 )OCFS2_INVALID_SLOT ) { +if (!(le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL )) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: suballoc slot %u for non-system inode\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_suballoc_slot)); + goto bail; + } + }else if ((u32 )le16_to_cpu (di->i_suballoc_slot) >OCFS2_SB (sb)->max_slots -1 ) { rc =ocfs2_error (sb,"Invalid dinode %llu: suballoc slot %u\n" , (unsigned long long )bh->b_blocknr,le16_to_cpu (di->i_suballoc_slot));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/670 usb: core: Add quirk for 255-bytes initial config read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikhil Solanke <[email protected]>
[ Upstream commit 152f174a13618bec1f842d2deb69245cb2ace51f ]
Certain third-party USB game controllers exposing (or spoofing) an Xbox 360-compatible interface (VID:PID 045e:028e) fail to enumerate under Linux. The device disconnects from the bus without responding to the initial GET_DESCRIPTOR(CONFIGURATION) request, and the kernel logs 'unable to read config index 0 descriptor/start: -71'.
The device then falls back to a secondary Android HID mode (with a different VID:PID), losing XInput functionality including rumble support. The failure reproduces across multiple machines, host controller types, and kernel versions including current mainline and LTS. The device enumerates correctly and remains in XInput mode under Windows. Notably, the device enumerates correctly in Android mode when the same 9-byte request is issued for that mode's configuration descriptor, confirming the firmware bug is specific to the XInput mode.
usbmon traces from Linux and Wireshark/USBPcap traces from Windows are identical up to the point of failure, with no visible protocol-level difference explaining the divergence. The root cause was identified when Michal Pecio discovered via a QEMU bus-level capture that Windows does not use wLength=9 for the initial config descriptor request; it uses wLength=255. Alan Stern subsequently confirmed this with a bus analyzer on a different USB 2.0 device, and Michal verified the behavior goes back to Windows 95 OSR2.1.
So, add a new quirk flag USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE which causes usb_get_configuration() to issue a 255 byte sized configuration request instead of USB_DT_CONFIG_SIZE (9) for the initial GET_DESCRIPTOR(CONFIGURATION) request, mimicking long-standing Windows behavior.
This patch intentionally does not add any new VID:PID entries using this quirk. Some affected Xbox 360-compatible controllers spoof Microsoft's VID:PID, while genuine Microsoft controllers already enumerate correctly and do not require this quirk. Other affected clone devices use their own VID:PID pairs and can be added individually as they are identified.
Stable-dep-of: 40224df29729 ("USB: quirks: add USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE for GameSir G7 SE")
--- .../admin-guide/kernel-parameters.txt | 5 +++ drivers/usb/core/config.c | 32 ++++++++++++++----- drivers/usb/core/quirks.c | 4 +++ include/linux/usb/quirks.h | 3 ++ 4 files changed, 36 insertions(+), 8 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -7260,6 +7260,11 @@ q = USB_QUIRK_FORCE_ONE_CONFIG (Device claims zero configurations, forcing to 1); + r = USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE (Device + fails during initialization when asked for + 9-bytes configuration descriptor request. + Ask for 255-bytes request instead to mirror + Windows' behavior); Example: quirks=0781:5580:bk,0a5c:5834:gij usbhid.mousepoll=
drivers/usb/core/config.c +24 -8
@@ -891,6 +891,18 @@ int usb_get_configuration(struct usb_device *dev)unsigned char *bigbuffer;struct usb_config_descriptor *desc;int result; +size_t usb_config_req_size; + +/* +* We usually start by grabbing the first 9-bytes descriptor so we know +* how long the whole configuration is. Some devices with quirky +* firmware will fail enumeration, so if the quirk is set, use 255 instead, +* mirroring the behavior of Windows. +*/ +if (dev->quirks &USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE ) + usb_config_req_size =255 ; +else + usb_config_req_size =USB_DT_CONFIG_SIZE ;if (ncfg >USB_MAXCONFIG ) { dev_notice(ddev, "too many configurations: %d, "
@@ -917,15 +929,13 @@ int usb_get_configuration(struct usb_device *dev)if (!dev->rawdescriptors)return -ENOMEM ; - desc =kmalloc (USB_DT_CONFIG_SIZE ,GFP_KERNEL ); + desc =kmalloc (usb_config_req_size,GFP_KERNEL );if (!desc)return -ENOMEM ;for (cfgno =0 ; cfgno < ncfg; cfgno++) { -/* We grab just the first descriptor so we know how long -* the whole configuration is */ result =usb_get_descriptor (dev,USB_DT_CONFIG , cfgno, - desc,USB_DT_CONFIG_SIZE ); + desc, usb_config_req_size);if (result <0 ) {dev_err (ddev,"unable to read config index %d " "descriptor/%s: %d\n" , cfgno,"start" , result);
@@ -935,16 +945,14 @@ int usb_get_configuration(struct usb_device *dev) dev->descriptor.bNumConfigurations = cfgno;break ; }else if (result <4 ) { -dev_err (ddev,"config index %d descriptor too short " -"(expected %i, got %i)\n" , cfgno, -USB_DT_CONFIG_SIZE , result); +dev_err (ddev,"config index %d descriptor too short (asked for %zu, got %i)\n" , + cfgno, usb_config_req_size, result); result = -EINVAL ; goto err; } length =max ((int )le16_to_cpu (desc->wTotalLength),USB_DT_CONFIG_SIZE ); -/* Now that we know the length, get the whole thing */ bigbuffer =kmalloc (length,GFP_KERNEL );if (!bigbuffer) { result = -ENOMEM ;
@@ -954,6 +962,13 @@ int usb_get_configuration(struct usb_device *dev)if (dev->quirks &USB_QUIRK_DELAY_INIT )msleep (200 ); +/* Skip the second read if we already got everything */ +if (result >= length) { +memcpy (bigbuffer, desc, length); + goto store_and_parse; + } + +/* Get the whole thing */ result =usb_get_descriptor (dev,USB_DT_CONFIG , cfgno, bigbuffer, length);if (result <0 ) {
@@ -968,6 +983,7 @@ int usb_get_configuration(struct usb_device *dev) length = result; } +store_and_parse: dev->rawdescriptors[cfgno] = bigbuffer; result = usb_parse_configuration(dev, cfgno,
drivers/usb/core/quirks.c +4 -0
@@ -143,6 +143,10 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)break ;case 'q' : flags |=USB_QUIRK_FORCE_ONE_CONFIG ; +break ; +case 'r' : + flags |=USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE ; +break ;/* Ignore unrecognized flag characters */ } }
include/linux/usb/quirks.h +3 -0
@@ -81,4 +81,7 @@/* Device claims zero configurations, forcing to 1 */ #define USB_QUIRK_FORCE_ONE_CONFIG BIT(18) +/* Use a 255 bytes config descriptor request mirroring windows behavior */ +#define USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE BIT(19) +#endif /* __LINUX_USB_QUIRKS_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 450/670 USB: quirks: add USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE for GameSir G7 SE
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Resool Tuama <[email protected]>
[ Upstream commit 40224df29729618ecd88c5c0077e71b1e82c7a3a ]
The GameSir G7 SE wired controller first enumerates as 3537:10a0 and then re-enumerates in a mode it picks from how the host enumerated it.
When the configuration descriptor is fetched the Linux way, 9 bytes followed by the full 80, the controller disconnects about 1 ms after its string descriptors have been read, before SET_CONFIGURATION, and comes back as 3537:1082, a generic HID gamepad without force feedback.
When the configuration descriptor is fetched in one 255-byte request, as Windows does, it comes back as 3537:1010 in Xbox One (GIP) mode, which xpad already supports, including rumble.
Skipping the device qualifier requests (USB_QUIRK_DEVICE_QUALIFIER) makes no difference; the configuration descriptor request size alone decides the mode. Add USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE for the 10a0 identity, as is already done for the ShanWan Wireless Gamepad.
--- drivers/usb/core/quirks.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/quirks.c +3 -0
@@ -607,6 +607,9 @@ static const struct usb_device_id usb_quirk_list[] = {/* ezcap401 - BOS descriptor fetch hangs at SuperSpeed Plus */ { USB_DEVICE(0x32ed, 0x0401), .driver_info = USB_QUIRK_NO_BOS }, + /* GameSir G7 SE */ + { USB_DEVICE(0x3537, 0x10a0), .driver_info = USB_QUIRK_WINDOWS_CONFIG_REQ_SIZE }, + /* DELL USB GEN2 */ { USB_DEVICE(0x413c, 0xb062), .driver_info = USB_QUIRK_NO_LPM | USB_QUIRK_RESET_RESUME },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/670 hwmon: (tmp102) Fix jiffies wraparound in conversion-ready check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Verdonck <[email protected]>
[ Upstream commit 56c1d32323e773b8b927316f8beeae9238576335 ]
tmp102 records a one-shot deadline in ->ready_time at probe (and resume) and, on every temperature read, refuses the read with -EAGAIN while time_before(jiffies, ready_time) is true, in order to skip the first ~35 ms conversion.
->ready_time is an unsigned long compared with time_before(), whose signed difference is only meaningful while the two values are within LONG_MAX jiffies of each other. Because ->ready_time is set once and never refreshed, jiffies keeps advancing away from it, and after 2^31 jiffies the difference flips sign. On a 32-bit HZ=100 kernel that happens ~248.5 days after boot: time_before() then permanently reports "not ready" and the driver returns -EAGAIN on every read, without ever touching the sensor, until the next reboot.
Store the deadline as a 64-bit jiffies value and compare it with get_jiffies_64()/time_before64(), which does not wrap in any practical uptime.
--- drivers/hwmon/tmp102.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/tmp102.c +4 -4
@@ -54,7 +54,7 @@struct tmp102 {struct regmap *regmap;u16 config_orig; -unsigned long ready_time; +u64 ready_time; };/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
@@ -79,7 +79,7 @@ static int tmp102_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:/* Is it too early to return a conversion ? */ -if (time_before (jiffies, tmp102->ready_time)) { +if (time_before64 (get_jiffies_64 (), tmp102->ready_time)) {dev_dbg (dev,"%s: Conversion not ready yet..\n" , __func__);return -EAGAIN ; }
@@ -245,7 +245,7 @@ static int tmp102_probe(struct i2c_client *client)* Mark that we are not ready with data until the first * conversion is complete */ - tmp102->ready_time = jiffies +msecs_to_jiffies (CONVERSION_TIME_MS ); + tmp102->ready_time =get_jiffies_64 () +msecs_to_jiffies (CONVERSION_TIME_MS ); hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, tmp102,
@@ -278,7 +278,7 @@ static int tmp102_resume(struct device *dev) err =regmap_update_bits (tmp102->regmap,TMP102_CONF_REG ,TMP102_CONF_SD ,0 ); - tmp102->ready_time = jiffies +msecs_to_jiffies (CONVERSION_TIME_MS ); + tmp102->ready_time =get_jiffies_64 () +msecs_to_jiffies (CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/670 gfs2: reject invalid inode sizes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiaming Zhang <[email protected]>
[ Upstream commit 33ed0a0567e0abe66ea65e89dad2e35082890fbe ]
A corrupted GFS2 image can store a dinode size that is larger than what VFS i_size can represent. gfs2_dinode_in() reads the on-disk di_size as a u64 and writes it directly into inode->i_size. If the value is larger than S64_MAX, the incore i_size becomes negative. That negative value can bypass the existing stuffed inode size check:
inode->i_size > gfs2_max_stuffed_size(ip)
Later, gfs2_quotad may try to sync the quota file and unstuff the quota inode. gfs2_unstuffer_folio() reads the negative i_size into an unsigned length and passes it to memcpy(), turning it into a huge copy size and triggering a out-of-bound issue.
Reject dinodes whose size exceeds sb->s_maxbytes before storing the value in inode->i_size. Also make the stuffed inode check use the raw on-disk size while it is still unsigned.
--- fs/gfs2/glops.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/gfs2/glops.c +8 -2
@@ -395,6 +395,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)umode_t mode =be32_to_cpu (str->di_mode);struct inode *inode = &ip->i_inode;bool is_new = inode->i_state &I_NEW ; +u64 size;if (unlikely (ip->i_no_addr !=be64_to_cpu (str->di_num.no_addr))) {gfs2_consist_inode (ip);
@@ -420,7 +421,12 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)i_uid_write (inode,be32_to_cpu (str->di_uid));i_gid_write (inode,be32_to_cpu (str->di_gid));set_nlink (inode,be32_to_cpu (str->di_nlink)); -i_size_write (inode,be64_to_cpu (str->di_size)); + size =be64_to_cpu (str->di_size); +if (unlikely (size > inode->i_sb->s_maxbytes)) { +gfs2_consist_inode (ip); +return -EIO ; + } +i_size_write (inode, size);gfs2_set_inode_blocks (inode,be64_to_cpu (str->di_blocks)); atime.tv_sec =be64_to_cpu (str->di_atime); atime.tv_nsec =be32_to_cpu (str->di_atime_nsec);
@@ -459,7 +465,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) ip->i_depth = (u8 )depth; ip->i_entries =be32_to_cpu (str->di_entries); -if (gfs2_is_stuffed (ip) && inode->i_size >gfs2_max_stuffed_size (ip)) { +if (gfs2_is_stuffed (ip) && size >gfs2_max_stuffed_size (ip)) {gfs2_consist_inode (ip);return -EIO ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/670 media: i2c: og01a1b: Switch from .s_stream to .enable_streams/.disable_streams
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 3a594bb454ba1ecb005f753007fa1bb5c5e68bae ]
The change allows to simplify the driver code, in particular the explicit locking scheme for stream on/off or format update serialization can be dropped in favour to the one provided by the V4L2 core internals.
Stable-dep-of: a26c5ac46191 ("media: i2c: og01a1b: power off sensor on remove")
--- drivers/media/i2c/og01a1b.c | 90 ++++++++++++++----------------------- 1 file changed, 34 insertions(+), 56 deletions(-)
drivers/media/i2c/og01a1b.c +34 -56
@@ -442,9 +442,6 @@ struct og01a1b {/* Current mode */ const struct og01a1b_mode *cur_mode; - -/* To serialize asynchronus callbacks */ -struct mutex mutex; };static u64 to_pixel_rate (u32 f_index)
@@ -616,7 +613,6 @@ static int og01a1b_init_controls(struct og01a1b *og01a1b)if (ret)return ret; - ctrl_hdlr->lock = &og01a1b->mutex; og01a1b->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &og01a1b_ctrl_ops, V4L2_CID_LINK_FREQ,
@@ -686,74 +682,66 @@ static void og01a1b_update_pad_format(const struct og01a1b_mode *mode, fmt->field =V4L2_FIELD_NONE ; } -static int og01a1b_start_streaming (struct og01a1b *og01a1b) +static int og01a1b_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) { +struct og01a1b *og01a1b =to_og01a1b (sd); +unsigned int link_freq_index = og01a1b->cur_mode->link_freq_index;const struct og01a1b_reg_list *reg_list; -int link_freq_index, ret; +int ret; - link_freq_index = og01a1b->cur_mode->link_freq_index; - reg_list = &link_freq_configs[link_freq_index].reg_list; + ret =pm_runtime_resume_and_get (og01a1b->dev); +if (ret) +return ret; + reg_list = &link_freq_configs[link_freq_index].reg_list; ret =og01a1b_write_reg_list (og01a1b, reg_list);if (ret) { -dev_err (og01a1b->dev,"failed to set plls" ); -return ret; +dev_err (og01a1b->dev,"failed to set plls: %d\n" , ret); + goto error; } reg_list = &og01a1b->cur_mode->reg_list; ret =og01a1b_write_reg_list (og01a1b, reg_list);if (ret) { -dev_err (og01a1b->dev,"failed to set mode" ); -return ret; +dev_err (og01a1b->dev,"failed to set mode: %d\n" , ret); + goto error; } ret =__v4l2_ctrl_handler_setup (og01a1b->sd.ctrl_handler);if (ret) -return ret; + goto error; ret =og01a1b_write_reg (og01a1b,OG01A1B_REG_MODE_SELECT ,OG01A1B_REG_VALUE_08BIT ,OG01A1B_MODE_STREAMING );if (ret) { -dev_err (og01a1b->dev,"failed to set stream" ); -return ret; +dev_err (og01a1b->dev,"failed to start streaming: %d\n" , ret); + goto error; }return 0 ; -} -static void og01a1b_stop_streaming (struct og01a1b *og01a1b) -{ -if (og01a1b_write_reg (og01a1b,OG01A1B_REG_MODE_SELECT , -OG01A1B_REG_VALUE_08BIT ,OG01A1B_MODE_STANDBY )) -dev_err (og01a1b->dev,"failed to set stream" ); +error: +pm_runtime_put_autosuspend (og01a1b->dev); + +return ret; } -static int og01a1b_set_stream (struct v4l2_subdev *sd,int enable) +static int og01a1b_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) {struct og01a1b *og01a1b =to_og01a1b (sd); -int ret =0 ; - -mutex_lock (&og01a1b->mutex); -if (enable) { - ret =pm_runtime_resume_and_get (og01a1b->dev); -if (ret) { -mutex_unlock (&og01a1b->mutex); -return ret; - } +int ret; - ret =og01a1b_start_streaming (og01a1b); -if (ret) { - enable =0 ; -og01a1b_stop_streaming (og01a1b); -pm_runtime_put (og01a1b->dev); - } - }else { -og01a1b_stop_streaming (og01a1b); -pm_runtime_put (og01a1b->dev); - } + ret =og01a1b_write_reg (og01a1b,OG01A1B_REG_MODE_SELECT , +OG01A1B_REG_VALUE_08BIT ,OG01A1B_MODE_STANDBY ); +if (ret) +dev_err (og01a1b->dev,"failed to stop streaming: %d\n" , ret); -mutex_unlock (&og01a1b->mutex); +pm_runtime_put_autosuspend (og01a1b->dev);return ret; }
@@ -771,7 +759,6 @@ static int og01a1b_set_format(struct v4l2_subdev *sd, height, fmt->format.width, fmt->format.height); -mutex_lock (&og01a1b->mutex);og01a1b_update_pad_format (mode, &fmt->format);if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { *v4l2_subdev_state_get_format (sd_state, fmt->pad) = fmt->format;
@@ -794,8 +781,6 @@ static int og01a1b_set_format(struct v4l2_subdev *sd, h_blank); } -mutex_unlock (&og01a1b->mutex); -return 0 ; }
@@ -805,15 +790,12 @@ static int og01a1b_get_format(struct v4l2_subdev *sd, {struct og01a1b *og01a1b =to_og01a1b (sd); -mutex_lock (&og01a1b->mutex);if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) fmt->format = *v4l2_subdev_state_get_format (sd_state, fmt->pad);else og01a1b_update_pad_format (og01a1b->cur_mode, &fmt->format); -mutex_unlock (&og01a1b->mutex); -return 0 ; }
@@ -849,18 +831,14 @@ static int og01a1b_enum_frame_size(struct v4l2_subdev *sd,static int og01a1b_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) { -struct og01a1b *og01a1b =to_og01a1b (sd); - -mutex_lock (&og01a1b->mutex);og01a1b_update_pad_format (&supported_modes[0 ],v4l2_subdev_state_get_format (fh->state,0 )); -mutex_unlock (&og01a1b->mutex);return 0 ; }static const struct v4l2_subdev_video_ops og01a1b_video_ops = { - .s_stream = og01a1b_set_stream, + .s_stream = v4l2_subdev_s_stream_helper, };static const struct v4l2_subdev_pad_ops og01a1b_pad_ops = {
@@ -868,6 +846,8 @@ static const struct v4l2_subdev_pad_ops og01a1b_pad_ops = { .get_fmt = og01a1b_get_format, .enum_mbus_code = og01a1b_enum_mbus_code, .enum_frame_size = og01a1b_enum_frame_size, + .enable_streams = og01a1b_enable_streams, + .disable_streams = og01a1b_disable_streams, };static const struct v4l2_subdev_ops og01a1b_subdev_ops = {
@@ -1062,7 +1042,6 @@ static void og01a1b_remove(struct i2c_client *client)media_entity_cleanup (&sd->entity);v4l2_ctrl_handler_free (sd->ctrl_handler);pm_runtime_disable (og01a1b->dev); -mutex_destroy (&og01a1b->mutex); }static int og01a1b_probe (struct i2c_client *client)
@@ -1146,7 +1125,6 @@ static int og01a1b_probe(struct i2c_client *client) goto power_off; } -mutex_init (&og01a1b->mutex); og01a1b->cur_mode = &supported_modes[0 ]; ret =og01a1b_init_controls (og01a1b);if (ret) {
@@ -1154,6 +1132,7 @@ static int og01a1b_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } + og01a1b->sd.state_lock = og01a1b->ctrl_handler.lock; og01a1b->sd.internal_ops = &og01a1b_internal_ops; og01a1b->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; og01a1b->sd.entity.ops = &og01a1b_subdev_entity_ops;
@@ -1194,7 +1173,6 @@ static int og01a1b_probe(struct i2c_client *client) probe_error_v4l2_ctrl_handler_free:v4l2_ctrl_handler_free (og01a1b->sd.ctrl_handler); -mutex_destroy (&og01a1b->mutex); power_off:og01a1b_power_off (og01a1b->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/670 media: i2c: og01a1b: power off sensor on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit a26c5ac46191ae34b3413f7a45d6241f63e15d42 ]
og01a1b_probe() powers the sensor on explicitly before identifying and initializing it. After a successful probe, runtime PM is enabled and pm_runtime_idle() is used to allow the runtime suspend callback to power the sensor off.
The probe error path explicitly calls og01a1b_power_off(), but the normal remove path only disables runtime PM. pm_runtime_disable() does not guarantee that an active device is runtime suspended, so the sensor can remain powered when the driver is removed. This also leaves the xvclk enable performed by og01a1b_power_on() unbalanced.
After disabling runtime PM, check whether the device is already suspended. If it is still active, power the sensor off explicitly and update the runtime PM state accordingly. Avoid powering it off again when runtime suspend has already done so.
This issue was found by manual code inspection.
--- drivers/media/i2c/og01a1b.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/i2c/og01a1b.c +5 -0
@@ -1042,6 +1042,11 @@ static void og01a1b_remove(struct i2c_client *client)media_entity_cleanup (&sd->entity);v4l2_ctrl_handler_free (sd->ctrl_handler);pm_runtime_disable (og01a1b->dev); + +if (!pm_runtime_status_suspended (og01a1b->dev)) { +og01a1b_power_off (og01a1b->dev); +pm_runtime_set_suspended (og01a1b->dev); + } }static int og01a1b_probe (struct i2c_client *client)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/670 m68k: Fix task info flags handling for 68000
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Palmer <[email protected]>
[ Upstream commit 2c6805145e1605cef39459f78979f7edee251b41 ]
The logic for deciding what to do after a syscall should be checking if any of the lower byte bits are set and then checking if the reschedule bit is set.
Currently we are loading the top word, checking if any bits are set (which never seems to be true) and thus jumping over loading the whole long and checking if the reschedule bit is set.
We get the thread info in two places so split that logic out in a macro and then fix the code so that it loads the byte of the flags we need to check, checks if anything is set and then checks if the reschedule bit in particular is set.
Stable-dep-of: 48859f8018d9 ("m68k: Fix seccomp filtering on ColdFire and 68000")
--- arch/m68k/68000/entry.S | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
arch/m68k/68000/entry.S +13 -8
@@ -18,6 +18,13 @@ .text +/* get thread_info pointer into a2 */ + .macro getthreadinfo + movel %sp,%d1 + andl #-THREAD_SIZE,%d1 + movel %d1,%a2 + .endm + .globl system_call .globl resume .globl ret_from_exception
@@ -70,9 +77,8 @@ ENTRY(system_call) movel %sp@(PT_OFF_ORIG_D0),%d0 - movel %sp,%d1 /* get thread_info pointer */ - andl #-THREAD_SIZE,%d1 - movel %d1,%a2 + /* Doing a trace ? */ + getthreadinfo btst #(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) jne do_trace cmpl #NR_syscalls,%d0
@@ -96,16 +102,15 @@ Luser_return: /* heavy interrupt load*/ andw #ALLOWINT,%sr - movel %sp,%d1 /* get thread_info pointer */ - andl #-THREAD_SIZE,%d1 - movel %d1,%a2 + getthreadinfo 1: - move %a2@(TINFO_FLAGS),%d1 /* thread_info->flags */ + /* check if any of the flags are set */ + moveb %a2@(TINFO_FLAGS + 3),%d1 /* thread_info->flags (low 8 bits) */ jne Lwork_to_do RESTORE_ALL Lwork_to_do: - movel %a2@(TINFO_FLAGS),%d1 /* thread_info->flags */ + /* check if reschedule needs to be called */ btst #TIF_NEED_RESCHED,%d1 jne reschedule
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/670 m68k: Fix seccomp filtering on ColdFire and 68000
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christopher Lusk <[email protected]>
[ Upstream commit 48859f8018d93bd93ef35f7430fdf5b97f2f9715 ]
m68k selects HAVE_ARCH_SECCOMP_FILTER for all configurations, but the ColdFire and 68000 syscall entry paths only branch to syscall_trace_enter() for TIF_SYSCALL_TRACE. TIF_SECCOMP alone falls through to syscall dispatch, leaving installed filters ineffective.
Test the combined TIF_SYSCALL_TRACE and TIF_SECCOMP mask in both paths and route either flag through the existing slow path. Leave the classic MMU syscall entry implementation unchanged.
Validated the combined test under QEMU mcf5208evb (ColdFire): filters denying getpid, openat, unlinkat, and reboot each returned -EPERM. A classic-MMU control (q800) denied the filtered getpid syscall both before and after this change. The 68000 path shares the same source-level omission and receives the identical masked test but was not separately emulated. Compile-tested W=1 with CONFIG_SECCOMP_FILTER=y on both m5208evb_defconfig and a custom no-MMU UCSIMM configuration; the latter built arch/m68k/68000/entry.o and vmlinux.
--- arch/m68k/68000/entry.S | 3 ++- arch/m68k/coldfire/entry.S | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/m68k/68000/entry.S +2 -1
@@ -79,7 +79,8 @@ ENTRY(system_call) /* Doing a trace ? */ getthreadinfo - btst #(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) + moveb %a2@(TINFO_FLAGS+2),%d1 + andl #((_TIF_SYSCALL_TRACE + _TIF_SECCOMP) >> 8),%d1 jne do_trace cmpl #NR_syscalls,%d0 jcc badsys
arch/m68k/coldfire/entry.S +2 -1
@@ -72,7 +72,8 @@ ENTRY(system_call) movel %d2,%a0 movel %a0@,%a1 /* save top of frame */ movel %sp,%a1@(TASK_THREAD+THREAD_ESP0) - btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) + moveb %a0@(TINFO_FLAGS+2),%d2 + andl #((_TIF_SYSCALL_TRACE + _TIF_SECCOMP) >> 8),%d2 bnes 1f movel %d3,%a0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/670 powerpc/pseries/iommu: Add TCEs for 16GB pages when RAM is pre-mapped
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gaurav Batra <[email protected]>
[ Upstream commit 0b8b0c17a8998709ecb2852d56442ea981102941 ]
In powerPC, if Dynamic DMA Window is big enough, RAM is pre-mapped. To determine the size of RAM, a PAPR+ property "ibm,lrdr-capacity" is used. This OF property dictates what is the max size of RAM an LPAR can have, including DR added memory.
In PowerPC, 16GB pages can be allocated at machine level and then assigned to LPARs. These 16GB pages are added to LPAR memory at the time of boot. The address range for these 16GB pages is above MAX RAM an LPAR can have (ibm,lrdr-capacity). In the current implementation, these 16GB pages are being excluded from pre-mapped TCEs. A driver can have DMA buffers allocated from 16GB pages. This results in platform to raise an EEH when DMA is attempted on buffers in 16GB memory range.
commit 6aa989ab2bd0 ("powerpc/pseries/iommu: memory notifier incorrectly adds TCEs for pmemory")
Prior to the above patch, memblock_end_of_DRAM() was being used to determine the MAX memory of an LPAR. This included 16GB pages as well. The issue with using memblock_end_of_DRAM() is that when pmemory is converted to RAM via daxctl command, the DDW engine will incorrectly try to add TCEs for pmemory as well.
Below is the address distribution of RAM, 16GB pages and pmemory for an LPAR with max memory of 256GB, memory allocated 64GB, 2 16GB pages and assigned pmemory of 8GB.
RANGE SIZE STATE REMOVABLE BLOCK
0x0000000000000000-0x0000000fffffffff 64G online yes 0-255 0x0000004000000000-0x00000047ffffffff 32G online yes 1024-1151
cat /sys/bus/nd/devices/region0/resource0x40100000000
cat /sys/bus/nd/devices/region0/size
8589934592
The approach to fix this problem is to revert back the code changes introduced by the above patch and to stash away the MAX memory of an LPAR, including 16GB pages, at the LPAR boot time. This value is then used whenever TCEs are needed to be pre-mapped - enable_DDW() or, iommu_mem_notifier()
--- arch/powerpc/platforms/pseries/iommu.c | 67 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 22 deletions(-)
arch/powerpc/platforms/pseries/iommu.c +45 -22
@@ -69,6 +69,8 @@ static struct iommu_table *iommu_pseries_alloc_table(int node)return tbl; } +static phys_addr_t pseries_ddw_max_ram__ro_after_init ; +#ifdef CONFIG_IOMMU_API static struct iommu_table_group_ops spapr_tce_table_group_ops;#endif
@@ -1284,15 +1286,19 @@ struct failed_ddw_pdn {static LIST_HEAD (failed_ddw_pdn_list); -static phys_addr_t ddw_memory_hotplug_max (void ) +static phys_addr_t __init ddw_memory_hotplug_max (void ) { -resource_size_t max_addr; +resource_size_t max_addr =memory_hotplug_max (); +struct device_node *memory; -#if defined(CONFIG_NUMA ) && defined(CONFIG_MEMORY_HOTPLUG ) - max_addr =hot_add_drconf_memory_max (); -#else - max_addr =memblock_end_of_DRAM (); -#endif +for_each_node_by_type (memory,"memory" ) { +struct resource res; + +if (of_address_to_resource (memory,0 , &res)) +continue ; + + max_addr =max_t (resource_size_t, max_addr, res.end +1 ); + }return max_addr; }
@@ -1447,7 +1453,7 @@ static struct property *ddw_property_create(const char *propname, u32 liobn, u64static bool enable_ddw (struct pci_dev *dev,struct device_node *pdn,u64 dma_mask) {int len =0 , ret; -int max_ram_len =order_base_2 (ddw_memory_hotplug_max ()); +int max_ram_len =order_base_2 (pseries_ddw_max_ram);struct ddw_query_response query;struct ddw_create_response create;int page_shift;
@@ -1617,12 +1623,12 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_masif (default_win_removed && pmem_present && !direct_mapping) {/* DDW is big enough to be split */ if ((1ULL << ddw_sz) >= -MIN_DDW_VPMEM_DMA_WINDOW + (1ULL << max_ram_len)) { +MIN_DDW_VPMEM_DMA_WINDOW + pseries_ddw_max_ram) { direct_mapping = true;/* offset of the Dynamic part of DDW */ - dynamic_offset =1ULL << max_ram_len; + dynamic_offset = pseries_ddw_max_ram; }/* DDW will at least have dynamic allocation */
@@ -1669,7 +1675,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_masif (direct_mapping) {/* DDW maps the whole partition, so enable direct DMA mapping */ - ret =walk_system_ram_range (0 ,ddw_memory_hotplug_max () >>PAGE_SHIFT , + ret =walk_system_ram_range (0 , pseries_ddw_max_ram >>PAGE_SHIFT , win64->value, tce_setrange_multi_pSeriesLP_walk);if (ret) { dev_info(&dev->dev, "failed to map DMA window for %pOF: %d\n",
@@ -1774,8 +1780,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_mas* to directly map both RAM and vPMEM, then we need to set DMA limit. */ if (pmem_present && direct_mapping && len !=MAX_PHYSMEM_BITS ) - dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + - (1ULL << max_ram_len); + dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + pseries_ddw_max_ram;dev_info (&dev->dev,"lsa_required: %x, lsa_enabled: %x, direct mapping: %x\n" , limited_addr_req, limited_addr_enabled, direct_mapping);
@@ -2422,23 +2427,35 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action, {struct dma_win *window;struct memory_notify *arg = data; +unsigned long limit = arg->nr_pages; +unsigned long max_ram_pages = pseries_ddw_max_ram >>PAGE_SHIFT ;int ret =0 ;/* This notifier can get called when onlining persistent memory as well. * TCEs are not pre-mapped for persistent memory. Persistent memory will -* always be above ddw_memory_hotplug_max() +* always be above pseries_ddw_max_ram */ +if (arg->start_pfn >= max_ram_pages) +return NOTIFY_OK ; + +/* RAM is being DLPAR'ed. The range should never exceed max ram. +* Just in case, clamp the range and throw a warning. +*/ +if (arg->start_pfn + limit > max_ram_pages) { + limit = max_ram_pages - arg->start_pfn; +WARN_ONCE (1 ,"Limiting Page Range %lx - %lx to Max Mem Pages: %lx\n" , + arg->start_pfn, arg->start_pfn + arg->nr_pages, + max_ram_pages); + }switch (action) {case MEM_GOING_ONLINE :spin_lock (&dma_win_list_lock);list_for_each_entry (window, &dma_win_list, list) { -if (window->direct && (arg->start_pfn <<PAGE_SHIFT ) < -ddw_memory_hotplug_max ()) { +if (window->direct) { ret |=tce_setrange_multi_pSeriesLP (arg->start_pfn, - arg->nr_pages, window->prop); + limit, window->prop); } -/* XXX log error */ }spin_unlock (&dma_win_list_lock);break ;
@@ -2446,12 +2463,10 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,case MEM_OFFLINE :spin_lock (&dma_win_list_lock);list_for_each_entry (window, &dma_win_list, list) { -if (window->direct && (arg->start_pfn <<PAGE_SHIFT ) < -ddw_memory_hotplug_max ()) { +if (window->direct) { ret |=tce_clearrange_multi_pSeriesLP (arg->start_pfn, - arg->nr_pages, window->prop); + limit, window->prop); } -/* XXX log error */ }spin_unlock (&dma_win_list_lock);break ;
@@ -2535,6 +2550,14 @@ void __init iommu_init_early_pSeries(void)register_memory_notifier (&iommu_mem_nb);set_pci_dma_ops (&dma_iommu_ops); + +/* During init determine the max memory an LPAR can have and set it. This +* will be used for pre-mapping RAM in DDW. memblock_end_of_DRAM() can +* change during the running of LPAR - daxctl can add pmemory as +* "system-ram". This memory range should not be pre-mapped in DDW since +* the address of pmemory can be much higher than the DDW size. +*/ + pseries_ddw_max_ram =ddw_memory_hotplug_max (); }static int __init disable_multitce (char *str)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/670 media: ene_ir: Ensure teardown is done in the correct order
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit ae6cfbad7ca346b78f4cdac38438bbfaed8c18a0 ]
The timer can be re-armed from the irq, so ensure that the timers are deleted after the irq and that we only free the rc device once we are sure that the irq has been silenced.
--- drivers/media/rc/ene_ir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/ene_ir.c +2 -2
@@ -1103,15 +1103,15 @@ static void ene_remove(struct pnp_dev *pnp_dev)unsigned long flags;rc_unregister_device (dev->rdev); -del_timer_sync (&dev->tx_sim_timer);spin_lock_irqsave (&dev->hw_lock, flags);ene_rx_disable (dev);ene_rx_restore_hw_buffer (dev);spin_unlock_irqrestore (&dev->hw_lock, flags); -rc_free_device (dev->rdev);free_irq (dev->irq, dev); +timer_delete_sync (&dev->tx_sim_timer);release_region (dev->hw_io,ENE_IO_SIZE ); +rc_free_device (dev->rdev);kfree (dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/670 f2fs: fix to check continuousness in f2fs_sync_meta_pages() correctly
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit 1383cff4ccf3c8833c6255edffa29eb67c6419bb ]
In f2fs_sync_meta_pages(), whenever i becomes zero inside while loop, below check may be skipped, it failed to check the continuousness:
if (nr_to_write != LONG_MAX && i != 0 &&
folio->index != prev +
folio_nr_pages(fbatch.folios[i-1])) {--- fs/f2fs/checkpoint.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/f2fs/checkpoint.c +4 -5
@@ -423,7 +423,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, long nr_to_write, enum iostat_type io_type) { struct address_space *mapping = META_MAPPING(sbi); -pgoff_t index =0 , prev =ULONG_MAX ; +pgoff_t index =0 , next =ULONG_MAX ;struct folio_batch fbatch;long nwritten =0 ;int nr_folios;
@@ -444,9 +444,8 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,for (i =0 ; i < nr_folios; i++) {struct folio *folio = fbatch.folios[i]; -if (nr_to_write !=LONG_MAX && i !=0 && - folio->index != prev + -folio_nr_pages (fbatch.folios[i-1 ])) { +if (nr_to_write !=LONG_MAX && next !=ULONG_MAX && + folio->index != next) {folio_batch_release (&fbatch); goto stop; }
@@ -475,7 +474,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,break ; } nwritten +=folio_nr_pages (folio); - prev = folio->index; + next = folio->index +folio_nr_pages (folio);if (unlikely (nwritten >= nr_to_write))break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/670 iio: light: ltr501: Power down chip if request irq fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 8a9bcd587d7d768e6c8e9fff88bb89645e412731 ]
In case devm_request_threaded_irq() failed, we were leaving the chip powered instead of powering it down again. Power down the chip switching ALS and PS modes to standby.
--- drivers/iio/light/ltr501.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/ltr501.c +1 -1
@@ -1558,7 +1558,7 @@ static int ltr501_probe(struct i2c_client *client)if (ret) {dev_err (&client->dev,"request irq (%d) failed\n" , client->irq); -return ret; + goto powerdown_on_error; } }else { indio_dev->info = data->chip_info->info_no_irq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/670 media: redrat3: Error path leaves device in transmitting state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 8024d5e84531d828535365718278f1cf0ce67db0 ]
In the allocation failure error path, the transmitting boolean is not cleared. If this error path is followed the transmitter cannot be used again until the device is replugged or the module reloaded.
Fix the error path by moving the assignment statement.
Remove the check for the transmitting state in transmit, since rc-core ensures there is never a reentrant call to the driver transmit function; the transmit function is always called with dev->lock held.
The transmitting boolean is only used for interpretting firmware errors.
--- drivers/media/rc/redrat3.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/media/rc/redrat3.c +3 -8
@@ -773,17 +773,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,u8 curlencheck =0 ;unsigned i, sendbuf_len; -if (rr3->transmitting) { -dev_warn (dev,"%s: transmitter already in use\n" , __func__); -return -EAGAIN ; - } -if (count >RR3_MAX_SIG_SIZE -RR3_TX_TRAILER_LEN )return -EINVAL ; -/* rr3 will disable rc detector on transmit */ - rr3->transmitting = true; - sample_lens =kcalloc (RR3_DRIVER_MAXLENS ,sizeof (*sample_lens),GFP_KERNEL );
@@ -796,6 +788,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, goto out; } +/* rr3 will disable rc detector on transmit */ + rr3->transmitting = true; +for (i =0 ; i < count; i++) { cur_sample_len =redrat3_us_to_len (txbuf[i]);if (cur_sample_len >0xffff ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/670 drm/panel: Add new helpers for refcounted panel allocatons
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anusha Srivatsa <[email protected]>
[ Upstream commit ed9c594d495deb676825489032cee0a03ce29bf9 ]
Introduce reference counted allocations for panels to avoid use-after-free. The patch adds the macro devm_drm_bridge_alloc() to allocate a new refcounted panel. Followed the documentation for drmm_encoder_alloc() and devm_drm_dev_alloc and other similar implementations for this purpose.
Stable-dep-of: 4eeeac9d7c36 ("drm/panel: ebbg-ft8719: Set prepare_prev_first")
--- drivers/gpu/drm/drm_panel.c | 25 +++++++++++++++++++++++++ include/drm/drm_panel.h | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+)
drivers/gpu/drm/drm_panel.c +25 -0
@@ -354,6 +354,31 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np) }EXPORT_SYMBOL (of_drm_find_panel); +void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, +const struct drm_panel_funcs *funcs, +int connector_type) +{ +void *container; +struct drm_panel *panel; + +if (!funcs) { +dev_warn (dev,"Missing funcs pointer\n" ); +return ERR_PTR (-EINVAL ); + } + + container =devm_kzalloc (dev, size,GFP_KERNEL ); +if (!container) +return ERR_PTR (-ENOMEM ); + + panel = container + offset; + panel->funcs = funcs; + +drm_panel_init (panel, dev, funcs, connector_type); + +return container; +} +EXPORT_SYMBOL (__devm_drm_panel_alloc); +/** * of_drm_get_panel_orientation - look up the orientation of the panel through * the "rotation" binding from a device tree node
include/drm/drm_panel.h +22 -0
@@ -269,6 +269,28 @@ struct drm_panel {bool enabled; }; +void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, +const struct drm_panel_funcs *funcs, +int connector_type); + +/** +* devm_drm_panel_alloc - Allocate and initialize a refcounted panel. +* +* @dev: struct device of the panel device +* @type: the type of the struct which contains struct &drm_panel +* @member: the name of the &drm_panel within @type +* @funcs: callbacks for this panel +* @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to +* the panel interface +* +* Returns: +* Pointer to container structure embedding the panel, ERR_PTR on failure. +*/ +#define devm_drm_panel_alloc (dev, type, member, funcs, connector_type) \ + ((type *)__devm_drm_panel_alloc(dev, sizeof(type), \ + offsetof(type, member), funcs, \ + connector_type)) +void drm_panel_init (struct drm_panel *panel,struct device *dev,const struct drm_panel_funcs *funcs,int connector_type);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 463/670 panel/ebbg-ft8719: Use refcounted allocation in place of devm_kzalloc()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anusha Srivatsa <[email protected]>
[ Upstream commit b30a15a4e7e54b676d6c395e71daf5f286997731 ]
Move to using the new API devm_drm_panel_alloc() to allocate the panel.
Stable-dep-of: 4eeeac9d7c36 ("drm/panel: ebbg-ft8719: Set prepare_prev_first")
--- drivers/gpu/drm/panel/panel-ebbg-ft8719.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/panel/panel-ebbg-ft8719.c +5 -6
@@ -198,9 +198,11 @@ static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi)struct ebbg_ft8719 *ctx;int i, ret; - ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); -if (!ctx) -return -ENOMEM ; + ctx = devm_drm_panel_alloc(dev, struct ebbg_ft8719, panel, + &ebbg_ft8719_panel_funcs, +DRM_MODE_CONNECTOR_DSI ); +if (IS_ERR (ctx)) +return PTR_ERR (ctx);for (i =0 ; i <ARRAY_SIZE (ctx->supplies); i++) ctx->supplies[i].supply = regulator_names[i];
@@ -231,9 +233,6 @@ static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi) dsi->mode_flags =MIPI_DSI_MODE_VIDEO |MIPI_DSI_MODE_VIDEO_BURST |MIPI_DSI_CLOCK_NON_CONTINUOUS ; -drm_panel_init (&ctx->panel, dev, &ebbg_ft8719_panel_funcs, -DRM_MODE_CONNECTOR_DSI ); - ret =drm_panel_of_backlight (&ctx->panel);if (ret)return dev_err_probe (dev, ret,"Failed to get backlight\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 464/670 drm/panel: ebbg-ft8719: Set prepare_prev_first
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Casey Connolly <[email protected]>
[ Upstream commit 4eeeac9d7c3600a6cae75b2a7bc9c5b67530923c ]
This corrects the host initialisation sequence so that we can send DSI/DCS commands in prepare().
--- drivers/gpu/drm/panel/panel-ebbg-ft8719.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/panel/panel-ebbg-ft8719.c +2 -0
@@ -233,6 +233,8 @@ static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi) dsi->mode_flags =MIPI_DSI_MODE_VIDEO |MIPI_DSI_MODE_VIDEO_BURST |MIPI_DSI_CLOCK_NON_CONTINUOUS ; + ctx->panel.prepare_prev_first = true; + ret =drm_panel_of_backlight (&ctx->panel);if (ret)return dev_err_probe (dev, ret,"Failed to get backlight\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 465/670 platform/x86: int3472: Fix uninitialised variable warning
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit 70e6384fe0f4cf9768944f81924f6c1478b0ce43 ]
Fix a compiler warning about an uninitialised err_msg variable by printing the error where it is handled:
drivers/platform/x86/intel/int3472/discrete.c:440:24: warning: ‘err_msg’ may be used uninitialized [-Wmaybe-uninitialized]
440 | return dev_err_probe(int3472->dev, ret, err_msg);
--- drivers/platform/x86/intel/int3472/discrete.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +9 -9
@@ -237,7 +237,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,u8 active_value, pin, type;union acpi_object *obj;struct gpio_desc *gpio; -const char *err_msg;const char *func;unsigned long gpio_flags;int ret;
@@ -283,7 +282,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_POWERDOWN : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, func, gpio_flags);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to map GPIO pin to sensor\n" );break ;case INT3472_GPIO_TYPE_CLK_ENABLE :
@@ -292,7 +292,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, func, gpio_flags);if (IS_ERR (gpio)) { ret =PTR_ERR (gpio); - err_msg ="Failed to get GPIO\n" ; +dev_err_probe (int3472->dev, ret,"Failed to get GPIO\n" );break ; }
@@ -300,19 +300,22 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) - err_msg ="Failed to register clock\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to register clock\n" );break ;case INT3472_GPIO_TYPE_PRIVACY_LED : ret =skl_int3472_register_pled (int3472, gpio);if (ret) - err_msg ="Failed to register LED\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE : ret =skl_int3472_register_regulator (int3472, gpio);if (ret) - err_msg ="Failed to map regulator to sensor\n" ; +dev_err_probe (int3472->dev, ret, +"Failed to map regulator to sensor\n" );break ;default :/* Never reached */
@@ -331,9 +334,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, int3472->ngpios++;ACPI_FREE (obj); -if (ret <0 ) -return dev_err_probe (int3472->dev, ret, err_msg); -return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 466/670 drm/panic: Do not use un-escaped URL as format string
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit 6596aae25585b183ebd528206bde6f12efaf8db1 ]
Replace the direct use of DRM_PANIC_SCREEN_QR_CODE_URL in snprintf() with a %s conversion specifier. Avoids a possible vulnerabilty from a crafted URL string.
As the attacker needs to control the kernel at the Kconfig level, the potential for an exploit is likely low.
--- drivers/gpu/drm/drm_panic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_panic.c +2 -1
@@ -507,7 +507,8 @@ static int drm_panic_get_qr_code_url(u8 **qr_image)char *kmsg;int max_qr_data_size, url_len; - url_len =snprintf (url,sizeof (url),CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL "?a=%s&v=%s&zl=" , + url_len =snprintf (url,sizeof (url),"%s?a=%s&v=%s&zl=" , +CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL ,utsname ()->machine,utsname ()->release); max_qr_data_size =drm_panic_qr_max_data_size (panic_qr_version, url_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 467/670 media: i2c: ov5647: fix power cleanup on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 6e81cfc38548109021ab761b94ecdd01f8753154 ]
ov5647_remove() disables runtime PM without powering off the sensor if it is still runtime active. pm_runtime_disable() does not invoke the runtime suspend callback, so the sensor can remain powered on.
If the device is not already runtime suspended, call ov5647_power_off() and mark the runtime PM state as suspended.
This issue was found by manual code inspection.
--- drivers/media/i2c/ov5647.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ov5647.c +4 -0
@@ -1481,6 +1481,10 @@ static void ov5647_remove(struct i2c_client *client)v4l2_ctrl_handler_free (&sensor->ctrls);v4l2_device_unregister_subdev (sd);pm_runtime_disable (&client->dev); +if (!pm_runtime_status_suspended (&client->dev)) { +ov5647_power_off (&client->dev); +pm_runtime_set_suspended (&client->dev); + }mutex_destroy (&sensor->lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 468/670 hte: tegra194-test: shut down timer before GPIO release
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 30167fadbf87fa901a2fee49c30a5c5a506a43e8 ]
tegra_hte_test_remove() releases GPIO descriptors before stopping hte.timer. gpio_timer_cb() accesses hte.gpio_out and rearms the timer, so a callback concurrent with remove can use a released descriptor and rearm after teardown.
Shut down the timer before releasing the GPIO descriptors. timer_shutdown_sync() waits for a running callback and prevents it from being rearmed.
--- drivers/hte/hte-tegra194-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hte/hte-tegra194-test.c +1 -1
@@ -218,10 +218,10 @@ static void tegra_hte_test_remove(struct platform_device *pdev) { (void )pdev; +timer_shutdown_sync (&hte.timer);free_irq (hte.gpio_in_irq, &hte);gpiod_put (hte.gpio_in);gpiod_put (hte.gpio_out); -del_timer_sync (&hte.timer); }static struct platform_driver tegra_hte_test_driver = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 469/670 drm/panel: Fix build error on !CONFIG_OF
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lucas De Marchi <[email protected]>
[ Upstream commit 8f47efd68db3bd87941df1ea3a5b77c62db5632e ]
Move helpers outside of CONFIG_OF, so basic allocation also works without it.
--- drivers/gpu/drm/drm_panel.c | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_panel.c +25 -25
@@ -316,6 +316,31 @@ int drm_panel_get_modes(struct drm_panel *panel, }EXPORT_SYMBOL (drm_panel_get_modes); +void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, +const struct drm_panel_funcs *funcs, +int connector_type) +{ +void *container; +struct drm_panel *panel; + +if (!funcs) { +dev_warn (dev,"Missing funcs pointer\n" ); +return ERR_PTR (-EINVAL ); + } + + container =devm_kzalloc (dev, size,GFP_KERNEL ); +if (!container) +return ERR_PTR (-ENOMEM ); + + panel = container + offset; + panel->funcs = funcs; + +drm_panel_init (panel, dev, funcs, connector_type); + +return container; +} +EXPORT_SYMBOL (__devm_drm_panel_alloc); +#ifdef CONFIG_OF /** * of_drm_find_panel - look up a panel using a device tree node
@@ -354,31 +379,6 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np) }EXPORT_SYMBOL (of_drm_find_panel); -void *__devm_drm_panel_alloc (struct device *dev,size_t size,size_t offset, -const struct drm_panel_funcs *funcs, -int connector_type) -{ -void *container; -struct drm_panel *panel; - -if (!funcs) { -dev_warn (dev,"Missing funcs pointer\n" ); -return ERR_PTR (-EINVAL ); - } - - container =devm_kzalloc (dev, size,GFP_KERNEL ); -if (!container) -return ERR_PTR (-ENOMEM ); - - panel = container + offset; - panel->funcs = funcs; - -drm_panel_init (panel, dev, funcs, connector_type); - -return container; -} -EXPORT_SYMBOL (__devm_drm_panel_alloc); -/** * of_drm_get_panel_orientation - look up the orientation of the panel through * the "rotation" binding from a device tree node
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 470/670 mm/hugetlb: remove unnecessary holding of hugetlb_lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ge Yang <[email protected]>
[ Upstream commit 344ef45b03336e7f74658814f66483b5417c9cf1 ]
In isolate_or_dissolve_huge_folio(), after acquiring the hugetlb_lock, it is only for the purpose of obtaining the correct hstate, which is then passed to alloc_and_dissolve_hugetlb_folio().
alloc_and_dissolve_hugetlb_folio() itself also acquires the hugetlb_lock. We can have alloc_and_dissolve_hugetlb_folio() obtain the hstate by itself, so that isolate_or_dissolve_huge_folio() no longer needs to acquire the hugetlb_lock. In addition, we keep the folio_test_hugetlb() check within isolate_or_dissolve_huge_folio(). By doing so, we can avoid disrupting the normal path by vainly holding the hugetlb_lock.
replace_free_hugepage_folios() has the same issue, and we should address it as well.
Addresses a possible performance problem which was added by the hotfix 113ed54ad276 ("mm/hugetlb: fix kernel NULL pointer dereference when replacing free hugetlb folios").
--- mm/hugetlb.c | 54 +++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-)
mm/hugetlb.c +17 -37
@@ -2866,20 +2866,24 @@ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,/* * alloc_and_dissolve_hugetlb_folio - Allocate a new folio and dissolve * the old one -* @h: struct hstate old page belongs to * @old_folio: Old folio to dissolve * @list: List to isolate the page in case we need to * Returns 0 on success, otherwise negated error. */ -static int alloc_and_dissolve_hugetlb_folio (struct hstate *h, -struct folio *old_folio,struct list_head *list) +static int alloc_and_dissolve_hugetlb_folio (struct folio *old_folio, +struct list_head *list) { -gfp_t gfp_mask =htlb_alloc_mask (h) | __GFP_THISNODE; +gfp_t gfp_mask; +struct hstate *h;int nid =folio_nid (old_folio);struct folio *new_folio =NULL ;int ret =0 ; retry: +/* +* The old_folio might have been dissolved from under our feet, so make sure +* to carefully check the state under the lock. +*/ spin_lock_irq (&hugetlb_lock);if (!folio_test_hugetlb (old_folio)) {/*
@@ -2908,8 +2912,10 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h,cond_resched (); goto retry; }else { + h =folio_hstate (old_folio);if (!new_folio) {spin_unlock_irq (&hugetlb_lock); + gfp_mask =htlb_alloc_mask (h) | __GFP_THISNODE; new_folio =alloc_buddy_hugetlb_folio (h, gfp_mask, nid,NULL ,NULL );if (!new_folio)
@@ -2953,36 +2959,25 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h,int isolate_or_dissolve_huge_page (struct page *page,struct list_head *list) { -struct hstate *h;struct folio *folio =page_folio (page);int ret = -EBUSY ; -/* -* The page might have been dissolved from under our feet, so make sure -* to carefully check the state under the lock. -* Return success when racing as if we dissolved the page ourselves. -*/ -spin_lock_irq (&hugetlb_lock); -if (folio_test_hugetlb (folio)) { - h =folio_hstate (folio); - }else { -spin_unlock_irq (&hugetlb_lock); +/* Not to disrupt normal path by vainly holding hugetlb_lock */ +if (!folio_test_hugetlb (folio))return 0 ; - } -spin_unlock_irq (&hugetlb_lock);/* * Fence off gigantic pages as there is a cyclic dependency between * alloc_contig_range and them. Return -ENOMEM as this has the effect * of bailing out right away without further retrying. */ -if (hstate_is_gigantic (h)) +if (folio_order (folio) >MAX_PAGE_ORDER )return -ENOMEM ;if (folio_ref_count (folio) &&isolate_hugetlb (folio, list)) ret =0 ;else if (!folio_ref_count (folio)) - ret =alloc_and_dissolve_hugetlb_folio (h, folio, list); + ret =alloc_and_dissolve_hugetlb_folio (folio, list);return ret; }
@@ -3004,7 +2999,6 @@ void wait_for_freed_hugetlb_folios(void)*/ int replace_free_hugepage_folios (unsigned long start_pfn,unsigned long end_pfn) { -struct hstate *h;struct folio *folio;int ret =0 ;
@@ -3013,23 +3007,9 @@ int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn)while (start_pfn < end_pfn) { folio =pfn_folio (start_pfn); -/* -* The folio might have been dissolved from under our feet, so make sure -* to carefully check the state under the lock. -*/ -spin_lock_irq (&hugetlb_lock); -if (folio_test_hugetlb (folio)) { - h =folio_hstate (folio); - }else { -spin_unlock_irq (&hugetlb_lock); - start_pfn++; -continue ; - } -spin_unlock_irq (&hugetlb_lock); - -if (!folio_ref_count (folio)) { - ret =alloc_and_dissolve_hugetlb_folio (h, folio, - &isolate_list); +/* Not to disrupt normal path by vainly holding hugetlb_lock */ +if (folio_test_hugetlb (folio) && !folio_ref_count (folio)) { + ret =alloc_and_dissolve_hugetlb_folio (folio, &isolate_list);if (ret)break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 471/670 KVM: guest_memfd: Establish memslot<=>guest_memfd bindings *after* memslot is ready
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 3fe5d2944e5ac3fc5073344b0982c73703332e18 ]
Wait to bind a memslot to a guest_memfd instance until *after* the memslot is fully prepared, as creating the binding in guest_memfd will effectively expose the memslot to readers. As pointed out by Sashiko, binding the memslot before it's ready to be exposed to the rest of the world can break various memslot assumption and rules. E.g. x86 could observe a NULL rmap pointer if a PUNCH_HOLE hit the guest_memfd after the binding was created, but before KVM made it through kvm_prepare_memory_region().
--- virt/kvm/kvm_main.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
virt/kvm/kvm_main.c +18 -16
@@ -1932,6 +1932,15 @@ static int kvm_set_memslot(struct kvm *kvm,if (r) goto err; +if (change ==KVM_MR_CREATE && (new->flags &KVM_MEM_GUEST_MEMFD )) { + r =kvm_gmem_commit_memory_region (kvm, new); +if (r) { +kvm_arch_free_memslot (kvm, new); +kvm_destroy_dirty_bitmap (new); + goto err; + } + } +/* * For DELETE and MOVE, the working slot is now active as the INVALID * version of the old slot. MOVE is particularly special as it reuses
@@ -2107,32 +2116,25 @@ int __kvm_set_memory_region(struct kvm *kvm, mem->guest_memfd_offset);if (r) goto out; + } - r =kvm_gmem_commit_memory_region (kvm, new); + r =kvm_set_memslot (kvm, old, new, change); -/* -* Drop the reference to the file, even on success. The file -* pins KVM, not the other way 'round. Active bindings are -* invalidated if the file is closed before memslots are -* destroyed. -*/ +/* +* Drop the reference to the gmem file, even on success. The file pins +* KVM, not the other way 'round. Active bindings are invalidated if +* the file is closed before memslots are destroyed. +*/ #ifdef CONFIG_KVM_PRIVATE_MEM +if (change ==KVM_MR_CREATE && (mem->flags &KVM_MEM_GUEST_MEMFD ))fput (new->gmem.file);#endif -if (r) - goto out; - } - - r =kvm_set_memslot (kvm, old, new, change);if (r) - goto out_unbind; + goto out;return 0 ; -out_unbind: -if (change ==KVM_MR_CREATE && (mem->flags &KVM_MEM_GUEST_MEMFD )) -kvm_gmem_unbind (new); out:kfree (new);return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 472/670 misc: fastrpc: Rename phys to dma_addr for clarity
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumari Pallavi <[email protected]>
[ Upstream commit 428b2f2b60c37f69e0723a225135da1f352d2602 ]
The fields buf->phys and map->phys currently store DMA addresses returned by dma_map_*() APIs, not physical addresses. This naming is misleading and may lead to incorrect assumptions about the address type and its translation.
Rename these fields from phys to dma_addr to improve code clarity and align with kernel conventions for dma_addr_t usage.
Stable-dep-of: 09fa66ec1b48 ("misc: fastrpc: fix double-free in fastrpc_map_attach() error path")
--- drivers/misc/fastrpc.c | 77 ++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 36 deletions(-)
drivers/misc/fastrpc.c +41 -36
@@ -109,7 +109,7 @@static const char *domains[FASTRPC_DEV_MAX ] = {"adsp" ,"mdsp" ,"sdsp" ,"cdsp" ,"cdsp1" };struct fastrpc_phy_page { -u64 addr;/* physical address */ +dma_addr_t addr;/* dma address */ u64 size;/* size of contiguous region */ };
@@ -174,7 +174,7 @@ struct fastrpc_msg {u64 ctx;/* invoke caller context */ u32 handle;/* handle to invoke */ u32 sc;/* scalars structure describing the data */ -u64 addr;/* physical address */ +dma_addr_t addr;/* dma address */ u64 size;/* size of contiguous region */ };
@@ -197,7 +197,7 @@ struct fastrpc_buf {struct dma_buf *dmabuf;struct device *dev;void *virt; -u64 phys; +dma_addr_t dma_addr;u64 size;/* Lock for dma buf attachments */ struct mutex lock;
@@ -220,7 +220,7 @@ struct fastrpc_map {struct dma_buf *buf;struct sg_table *table;struct dma_buf_attachment *attach; -u64 phys; +dma_addr_t dma_addr;u64 size;void *va;u64 len;
@@ -325,11 +325,12 @@ static void fastrpc_free_map(struct kref *ref) perm.vmid =QCOM_SCM_VMID_HLOS ; perm.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (map->phys, map->len, + err =qcom_scm_assign_mem (map->dma_addr, map->len, &src_perms, &perm,1 );if (err) { -dev_err (map->fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d\n" , - map->phys, map->len, err); +dev_err (map->fl->sctx->dev, +"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , + &map->dma_addr, map->len, err);return ; } }
@@ -400,7 +401,7 @@ static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,static void fastrpc_buf_free (struct fastrpc_buf *buf) {dma_free_coherent (buf->dev, buf->size, buf->virt, -FASTRPC_PHYS (buf->phys)); +FASTRPC_PHYS (buf->dma_addr));kfree (buf); }
@@ -419,12 +420,12 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf->fl = fl; buf->virt =NULL ; - buf->phys =0 ; + buf->dma_addr =0 ; buf->size = size; buf->dev = dev; buf->raddr =0 ; - buf->virt =dma_alloc_coherent (dev, buf->size, (dma_addr_t *)&buf->phys, + buf->virt =dma_alloc_coherent (dev, buf->size, &buf->dma_addr,GFP_KERNEL );if (!buf->virt) {mutex_destroy (&buf->lock);
@@ -450,7 +451,7 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf = *obuf;if (fl->sctx && fl->sctx->sid) - buf->phys += ((u64 )fl->sctx->sid <<32 ); + buf->dma_addr += ((u64 )fl->sctx->sid <<32 );return 0 ; }
@@ -743,7 +744,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,return -ENOMEM ; ret =dma_get_sgtable (buffer->dev, &a->sgt, buffer->virt, -FASTRPC_PHYS (buffer->phys), buffer->size); +FASTRPC_PHYS (buffer->dma_addr), buffer->size);if (ret <0 ) {dev_err (buffer->dev,"failed to get scatterlist from DMA API\n" );kfree (a);
@@ -792,7 +793,7 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,dma_resv_assert_held (dmabuf->resv);return dma_mmap_coherent (buf->dev, vma, buf->virt, -FASTRPC_PHYS (buf->phys), size); +FASTRPC_PHYS (buf->dma_addr), size); }static const struct dma_buf_ops fastrpc_dma_buf_ops = {
@@ -844,10 +845,10 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, map->table = table;if (attr &FASTRPC_ATTR_SECUREMAP ) { - map->phys =sg_phys (map->table->sgl); + map->dma_addr =sg_phys (map->table->sgl); }else { - map->phys =sg_dma_address (map->table->sgl); - map->phys += ((u64 )fl->sctx->sid <<32 ); + map->dma_addr =sg_dma_address (map->table->sgl); + map->dma_addr += ((u64 )fl->sctx->sid <<32 ); }for_each_sg (map->table->sgl, sgl, map->table->nents, sgl_index)
@@ -874,10 +875,11 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, dst_perms[1 ].vmid = fl->cctx->vmperms[0 ].vmid; dst_perms[1 ].perm =QCOM_SCM_PERM_RWX ; map->attr = attr; - err =qcom_scm_assign_mem (map->phys, (u64 )map->len, &src_perms, dst_perms,2 ); + err =qcom_scm_assign_mem (map->dma_addr, (u64 )map->len, &src_perms, dst_perms,2 );if (err) { -dev_err (sess->dev,"Failed to assign memory with phys 0x%llx size 0x%llx err %d\n" , - map->phys, map->len, err); +dev_err (sess->dev, +"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , + &map->dma_addr, map->len, err); goto map_err; } }
@@ -1059,7 +1061,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)struct vm_area_struct *vma =NULL ; rpra[i].buf.pv = (u64 ) ctx->args[i].ptr; - pages[i].addr = ctx->maps[i]->phys; + pages[i].addr = ctx->maps[i]->dma_addr;mmap_read_lock (current->mm); vma =vma_lookup (current->mm, ctx->args[i].ptr);
@@ -1086,7 +1088,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) goto bail; rpra[i].buf.pv = args - ctx->olaps[oix].offset; - pages[i].addr = ctx->buf->phys - + pages[i].addr = ctx->buf->dma_addr - ctx->olaps[oix].offset + (pkt_size - rlen); pages[i].addr = pages[i].addr &PAGE_MASK ;
@@ -1118,7 +1120,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) list[i].num = ctx->args[i].length ?1 :0 ; list[i].pgidx = i;if (ctx->maps[i]) { - pages[i].addr = ctx->maps[i]->phys; + pages[i].addr = ctx->maps[i]->dma_addr; pages[i].size = ctx->maps[i]->size; } rpra[i].dma.fd = ctx->args[i].fd;
@@ -1200,7 +1202,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, msg->ctx = ctx->ctxid | fl->pd; msg->handle = handle; msg->sc = ctx->sc; - msg->addr = ctx->buf ? ctx->buf->phys :0 ; + msg->addr = ctx->buf ? ctx->buf->dma_addr :0 ; msg->size =roundup (ctx->msg_sz,PAGE_SIZE );fastrpc_context_get (ctx);
@@ -1358,13 +1360,15 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,if (fl->cctx->vmcount) {u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - err =qcom_scm_assign_mem (fl->cctx->remote_heap->phys, + err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, (u64 )fl->cctx->remote_heap->size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount);if (err) { -dev_err (fl->sctx->dev,"Failed to assign memory with phys 0x%llx size 0x%llx err %d\n" , - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); +dev_err (fl->sctx->dev, +"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , + &fl->cctx->remote_heap->dma_addr, + fl->cctx->remote_heap->size, err); goto err_map; } scm_done = true;
@@ -1384,7 +1388,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, args[1 ].length = inbuf.namelen; args[1 ].fd =-1 ; - pages[0 ].addr = fl->cctx->remote_heap->phys; + pages[0 ].addr = fl->cctx->remote_heap->dma_addr; pages[0 ].size = fl->cctx->remote_heap->size; args[2 ].ptr = (u64 )(uintptr_t ) pages;
@@ -1413,12 +1417,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, dst_perms.vmid =QCOM_SCM_VMID_HLOS ; dst_perms.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (fl->cctx->remote_heap->phys, + err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, (u64 )fl->cctx->remote_heap->size, &src_perms, &dst_perms,1 );if (err) -dev_err (fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d\n" , - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); +dev_err (fl->sctx->dev,"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , + &fl->cctx->remote_heap->dma_addr, fl->cctx->remote_heap->size, err); } err_map:fastrpc_buf_free (fl->cctx->remote_heap);
@@ -1508,7 +1512,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, args[2 ].length = inbuf.filelen; args[2 ].fd = init.filefd; - pages[0 ].addr = imem->phys; + pages[0 ].addr = imem->dma_addr; pages[0 ].size = imem->size; args[3 ].ptr = (u64 )(uintptr_t ) pages;
@@ -1962,7 +1966,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) args[0 ].ptr = (u64) (uintptr_t) &req_msg; args[0 ].length =sizeof (req_msg); - pages.addr = buf->phys; + pages.addr = buf->dma_addr; pages.size = buf->size; args[1 ].ptr = (u64) (uintptr_t) &pages;
@@ -1990,11 +1994,12 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)if (req.flags ==ADSP_MMAP_REMOTE_HEAP_ADDR && fl->cctx->vmcount) {u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - err =qcom_scm_assign_mem (buf->phys, (u64 )buf->size, + err =qcom_scm_assign_mem (buf->dma_addr, (u64 )buf->size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount);if (err) { -dev_err (fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d" , - buf->phys, buf->size, err); +dev_err (fl->sctx->dev, +"Failed to assign memory dma_addr %pad size 0x%llx err %d" , + &buf->dma_addr, buf->size, err); goto err_assign; } }
@@ -2108,7 +2113,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp) args[0 ].ptr = (u64) (uintptr_t) &req_msg; args[0 ].length =sizeof (req_msg); - pages.addr = map->phys; + pages.addr = map->dma_addr; pages.size = map->len; args[1 ].ptr = (u64) (uintptr_t) &pages;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 473/670 misc: fastrpc: fix double-free in fastrpc_map_attach() error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifei Gao <[email protected]>
[ Upstream commit 09fa66ec1b4896ab841da085ca58b6433f28f07f ]
map->table is assigned right after dma_buf_map_attachment_unlocked() succeeds. The two failure checks that follow, the len > map->size test and, where subsystem VMIDs are configured, a failed qcom_scm_assign_mem(), jump to map_err with map->table already set.
map_err manually calls dma_buf_detach() and dma_buf_put() and then falls through to fastrpc_map_put(). Since that change the error path tail is fastrpc_map_put() -> fastrpc_free_map(), and fastrpc_free_map() already unmaps, detaches and puts the dma-buf whenever map->table is set. The two operations therefore run twice: the second dma_buf_put() drops an extra reference on map->buf, and dma_buf_unmap_attachment_unlocked() dereferences the map->attach already freed by the manual dma_buf_detach(). kref_init() sets the refcount to 1 with no intervening get, so the final fastrpc_map_put() frees the map synchronously and the redundant cleanup is deterministic.
The len > map->size branch is reachable by an unprivileged process via FASTRPC_IOCTL_MEM_MAP with an fd whose dma-buf is smaller than the requested length, before any DSP invocation.
Route both map->table-is-set failure branches to get_err instead of map_err, so fastrpc_free_map() is the single owner of the unmap/detach/put sequence. map_err is retained for the dma_buf_map_attachment_unlocked() failure, which is reached with map->table still NULL and an attachment that fastrpc_free_map() will not clean up, so its dma_buf_detach()/dma_buf_put() must still run manually.
--- drivers/misc/fastrpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/fastrpc.c +2 -2
@@ -857,7 +857,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd,dev_dbg (sess->dev,"Bad size passed len 0x%llx map size 0x%llx\n" , len, map->size); err = -EINVAL ; - goto map_err; + goto get_err; } map->va =sg_virt (map->table->sgl); map->len = len;
@@ -880,7 +880,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd,dev_err (sess->dev,"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , &map->dma_addr, map->len, err); - goto map_err; + goto get_err; } }spin_lock (&fl->lock);
Signature · 1 line
2.53.0