staging: gpib: Use min for calculating transfer length
Subsystems (16)
Sasha Levin
maintainerPATCH 1/28 staging: gpib: Use min for calculating transfer length
From: Dave Penkler <[email protected]>
[ Upstream commit 76d54fd5471b10ee993c217928a39d7351eaff5c ]
In the accel read and write functions the transfer length was being calculated by an if statement setting it to the lesser of the remaining bytes to read/write and the fifo size.
Replace both instances with min() which is clearer and more compact.
--- drivers/staging/gpib/agilent_82350b/agilent_82350b.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/gpib/agilent_82350b/agilent_82350b.c +2 -8
@@ -69,10 +69,7 @@ int agilent_82350b_accel_read(gpib_board_t *board, uint8_t *buffer, size_t lengtint j;int count; -if (num_fifo_bytes - i < agilent_82350b_fifo_size) - block_size = num_fifo_bytes - i; -else - block_size = agilent_82350b_fifo_size; + block_size =min (num_fifo_bytes - i, agilent_82350b_fifo_size);set_transfer_counter (a_priv, block_size);writeb (ENABLE_TI_TO_SRAM |DIRECTION_GPIB_TO_HOST , a_priv->gpib_base +SRAM_ACCESS_CONTROL_REG );
@@ -203,10 +200,7 @@ int agilent_82350b_accel_write(gpib_board_t *board, uint8_t *buffer, size_t lengfor (i =1 ; i < fifotransferlength;) {clear_bit (WRITE_READY_BN , &tms_priv->state); -if (fifotransferlength - i < agilent_82350b_fifo_size) - block_size = fifotransferlength - i; -else - block_size = agilent_82350b_fifo_size; + block_size =min (fifotransferlength - i, agilent_82350b_fifo_size);set_transfer_counter (a_priv, block_size);for (j =0 ; j < block_size; ++j, ++i) {// load data into board's sram
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 2/28 usb: host: max3421-hcd: Add missing spi_device_id table
From: Alexander Stein <[email protected]>
[ Upstream commit 41d5e3806cf589f658f92c75195095df0b66f66a ]
"maxim,max3421" DT compatible is missing its SPI device ID entry, not allowing module autoloading and leading to the following message:
"SPI driver max3421-hcd has no spi_device_id for maxim,max3421"
Fix this by adding the spi_device_id table.
--- drivers/usb/host/max3421-hcd.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/usb/host/max3421-hcd.c +7 -0
@@ -1946,6 +1946,12 @@ max3421_remove(struct spi_device *spi)usb_put_hcd (hcd); } +static const struct spi_device_id max3421_spi_ids[] = { + {"max3421" }, + { }, +}; +MODULE_DEVICE_TABLE (spi, max3421_spi_ids); +static const struct of_device_id max3421_of_match_table[] = { { .compatible ="maxim,max3421" , }, {},
@@ -1955,6 +1961,7 @@ MODULE_DEVICE_TABLE(of, max3421_of_match_table);static struct spi_driver max3421_driver = { .probe = max3421_probe, .remove = max3421_remove, + .id_table = max3421_spi_ids, .driver = { .name ="max3421-hcd" , .of_match_table = max3421_of_match_table,
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 3/28 iio: adc: ad4695: make ad4695_exit_conversion_mode() more robust
In reply to Sasha LevinFrom: Trevor Gamblin <[email protected]>
[ Upstream commit 998d20e4e99d909f14d96fdf0bdcf860f7efe3ef ]
Ensure that conversion mode is successfully exited when the command is issued by adding an extra transfer beforehand, matching the minimum CNV high and low times from the AD4695 datasheet. The AD4695 has a quirk where the exit command only works during a conversion, so guarantee this happens by triggering a conversion in ad4695_exit_conversion_mode(). Then make this even more robust by ensuring that the exit command is run at AD4695_REG_ACCESS_SCLK_HZ rather than the bus maximum.
--- drivers/iio/adc/ad4695.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
drivers/iio/adc/ad4695.c +28 -6
@@ -92,6 +92,8 @@#define AD4695_T_REFBUF_MS 100#define AD4695_T_REGCONFIG_NS 20#define AD4695_T_SCK_CNV_DELAY_NS 80 +#define AD4695_T_CNVL_NS 80 +#define AD4695_T_CNVH_NS 10#define AD4695_REG_ACCESS_SCLK_HZ (10 * MEGA)/* Max number of voltage input channels. */
@@ -364,11 +366,31 @@ static int ad4695_enter_advanced_sequencer_mode(struct ad4695_state *st, u32 n)*/ static int ad4695_exit_conversion_mode (struct ad4695_state *st) { -struct spi_transfer xfer = { - .tx_buf = &st->cnv_cmd2, - .len =1 , - .delay.value =AD4695_T_REGCONFIG_NS , - .delay.unit =SPI_DELAY_UNIT_NSECS , +/* +* An extra transfer is needed to trigger a conversion here so +* that we can be 100% sure the command will be processed by the +* ADC, rather than relying on it to be in the correct state +* when this function is called (this chip has a quirk where the +* command only works when reading a conversion, and if the +* previous conversion was already read then it won't work). The +* actual conversion command is then run at the slower +* AD4695_REG_ACCESS_SCLK_HZ speed to guarantee this works. +*/ +struct spi_transfer xfers[] = { + { + .delay.value =AD4695_T_CNVL_NS , + .delay.unit =SPI_DELAY_UNIT_NSECS , + .cs_change =1 , + .cs_change_delay.value =AD4695_T_CNVH_NS , + .cs_change_delay.unit =SPI_DELAY_UNIT_NSECS , + }, + { + .speed_hz =AD4695_REG_ACCESS_SCLK_HZ , + .tx_buf = &st->cnv_cmd2, + .len =1 , + .delay.value =AD4695_T_REGCONFIG_NS , + .delay.unit =SPI_DELAY_UNIT_NSECS , + }, };/*
@@ -377,7 +399,7 @@ static int ad4695_exit_conversion_mode(struct ad4695_state *st)*/ st->cnv_cmd2 =AD4695_CMD_EXIT_CNV_MODE <<3 ; -return spi_sync_transfer (st->spi, &xfer,1 ); +return spi_sync_transfer (st->spi, xfers,ARRAY_SIZE (xfers)); }static int ad4695_set_ref_voltage (struct ad4695_state *st,int vref_mv)
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 4/28 fs/ntfs3: Keep write operations atomic
In reply to Sasha LevinFrom: Lizhi Xu <[email protected]>
[ Upstream commit 285cec318bf5a7a6c8ba999b2b6ec96f9a20590f ]
syzbot reported a NULL pointer dereference in __generic_file_write_iter. [1]
Before the write operation is completed, the user executes ioctl[2] to clear the compress flag of the file, which causes the is_compressed() judgment to return 0, further causing the program to enter the wrong process and call the wrong ops ntfs_aops_cmpr, which triggers the null pointer dereference of write_begin.
Use inode lock to synchronize ioctl and write to avoid this case.
[1]
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
Mem abort info:
ESR = 0x0000000086000006
EC = 0x21: IABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x06: level 2 translation fault
user pgtable: 4k pages, 48-bit VAs, pgdp=000000011896d000
[0000000000000000] pgd=0800000118b44403, p4d=0800000118b44403, pud=0800000117517403, pmd=0000000000000000
Internal error: Oops: 0000000086000006 [#1] PREEMPT SMP Modules linked in: CPU: 0 UID: 0 PID: 6427 Comm: syz-executor347 Not tainted 6.13.0-rc3-syzkaller-g573067a5a685 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : 0x0 lr : generic_perform_write+0x29c/0x868 mm/filemap.c:4055
sp : ffff80009d4978a0
x29: ffff80009d4979c0 x28: dfff800000000000 x27: ffff80009d497bc8
x26: 0000000000000000 x25: ffff80009d497960 x24: ffff80008ba71c68
x23: 0000000000000000 x22: ffff0000c655dac0 x21: 0000000000001000
x20: 000000000000000c x19: 1ffff00013a92f2c x18: ffff0000e183aa1c
x17: 0004060000000014 x16: ffff800083275834 x15: 0000000000000001
x14: 0000000000000000 x13: 0000000000000001 x12: ffff0000c655dac0
x11: 0000000000ff0100 x10: 0000000000ff0100 x9 : 0000000000000000 x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000 x5 : ffff80009d497980 x4 : ffff80009d497960 x3 : 0000000000001000 x2 : 0000000000000000 x1 : ffff0000e183a928 x0 : ffff0000d60b0fc0
Call trace: 0x0 (P) __generic_file_write_iter+0xfc/0x204 mm/filemap.c:4156 ntfs_file_write_iter+0x54c/0x630 fs/ntfs3/file.c:1267 new_sync_write fs/read_write.c:586 [inline] vfs_write+0x920/0xcf4 fs/read_write.c:679 ksys_write+0x15c/0x26c fs/read_write.c:731 __do_sys_write fs/read_write.c:742 [inline] __se_sys_write fs/read_write.c:739 [inline] __arm64_sys_write+0x7c/0x90 fs/read_write.c:739 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:49 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:132 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:151 el0_svc+0x54/0x168 arch/arm64/kernel/entry-common.c:744 el0t_64_sync_handler+0x84/0x108 arch/arm64/kernel/entry-common.c:762
[2]
ioctl$FS_IOC_SETFLAGS(r0, 0x40086602, &(0x7f00000000c0)=0x20)
--- fs/ntfs3/file.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
fs/ntfs3/file.c +10 -9
@@ -1228,21 +1228,22 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)ssize_t ret;int err; - err =check_write_restriction (inode); -if (err) -return err; - -if (is_compressed (ni) && (iocb->ki_flags &IOCB_DIRECT )) { -ntfs_inode_warn (inode,"direct i/o + compressed not supported" ); -return -EOPNOTSUPP ; - } -if (!inode_trylock (inode)) {if (iocb->ki_flags &IOCB_NOWAIT )return -EAGAIN ;inode_lock (inode); } + ret =check_write_restriction (inode); +if (ret) + goto out; + +if (is_compressed (ni) && (iocb->ki_flags &IOCB_DIRECT )) { +ntfs_inode_warn (inode,"direct i/o + compressed not supported" ); + ret = -EOPNOTSUPP ; + goto out; + } + ret =generic_write_checks (iocb, from);if (ret <=0 ) goto out;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 5/28 fs/ntfs3: Fix WARNING in ntfs_extend_initialized_size
In reply to Sasha LevinFrom: Edward Adam Davis <[email protected]>
[ Upstream commit ff355926445897cc9fdea3b00611e514232c213c ]
Syzbot reported a WARNING in ntfs_extend_initialized_size. The data type of in->i_valid and to is u64 in ntfs_file_mmap(). If their values are greater than LLONG_MAX, overflow will occur because the data types of the parameters valid and new_valid corresponding to the function ntfs_extend_initialized_size() are loff_t.
Before calling ntfs_extend_initialized_size() in the ntfs_file_mmap(), the "ni->i_valid < to" has been determined, so the same WARN_ON determination is not required in ntfs_extend_initialized_size().
Just execute the ntfs_extend_initialized_size() in ntfs_extend() to make a WARN_ON check.
--- fs/ntfs3/file.c | 1 + 1 file changed, 1 insertion(+)
fs/ntfs3/file.c +1 -0
@@ -412,6 +412,7 @@ static int ntfs_extend(struct inode *inode, loff_t pos, size_t count, }if (extend_init && !is_compressed (ni)) { +WARN_ON (ni->i_valid >= pos); err =ntfs_extend_initialized_size (file, ni, ni->i_valid, pos);if (err) goto out;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 6/28 phy: qcom: qmp-pcie: Add X1P42100 Gen4x4 PHY
In reply to Sasha LevinFrom: Konrad Dybcio <[email protected]>
[ Upstream commit 0d8db251dd15d2e284f5a6a53bc2b869f3eca711 ]
Add a new, common configuration for Gen4x4 V6 PHYs without an init sequence.
The bootloader configures the hardware once and the OS retains that configuration by using the NOCSR reset line (which doesn't drop register state on assert) in place of the "full reset" one.
Use this new configuration for X1P42100's Gen4x4 PHY.
--- drivers/phy/qualcomm/phy-qcom-qmp-pcie.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/phy/qualcomm/phy-qcom-qmp-pcie.c +18 -0
@@ -3905,6 +3905,21 @@ static const struct qmp_phy_cfg x1e80100_qmp_gen4x8_pciephy_cfg = { .has_nocsr_reset = true, }; +static const struct qmp_phy_cfg qmp_v6_gen4x4_pciephy_cfg = { + .lanes =4 , + + .offsets = &qmp_pcie_offsets_v6_20, + + .reset_list = sdm845_pciephy_reset_l, + .num_resets =ARRAY_SIZE (sdm845_pciephy_reset_l), + .vreg_list = qmp_phy_vreg_l, + .num_vregs =ARRAY_SIZE (qmp_phy_vreg_l), + .regs = pciephy_v6_regs_layout, + + .pwrdn_ctrl =SW_PWRDN |REFCLK_DRV_DSBL , + .phy_status =PHYSTATUS_4_20 , +}; +static void qmp_pcie_init_port_b (struct qmp_pcie *qmp,const struct qmp_phy_cfg_tbls *tbls) {const struct qmp_phy_cfg *cfg = qmp->cfg;
@@ -4692,6 +4707,9 @@ static const struct of_device_id qmp_pcie_of_match_table[] = { }, { .compatible = "qcom,x1e80100-qmp-gen4x8-pcie-phy", .data = &x1e80100_qmp_gen4x8_pciephy_cfg, + }, { + .compatible = "qcom,x1p42100-qmp-gen4x4-pcie-phy", + .data = &qmp_v6_gen4x4_pciephy_cfg, }, { }, };
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 7/28 usb: dwc3: gadget: Refactor loop to avoid NULL endpoints
In reply to Sasha LevinFrom: Andy Shevchenko <[email protected]>
[ Upstream commit eafba0205426091354f050381c32ad1567c35844 ]
Prepare the gadget driver to handle the reserved endpoints that will be not allocated at the initialisation time.
While at it, add a warning where the NULL endpoint should never happen.
--- drivers/usb/dwc3/gadget.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/usb/dwc3/gadget.c +18 -4
@@ -547,6 +547,7 @@ static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep)int dwc3_gadget_start_config (struct dwc3 *dwc,unsigned int resource_index) {struct dwc3_gadget_ep_cmd_params params; +struct dwc3_ep *dep;u32 cmd;int i;int ret;
@@ -563,8 +564,13 @@ int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index)return ret;/* Reset resource allocation flags */ -for (i = resource_index; i < dwc->num_eps && dwc->eps[i]; i++) - dwc->eps[i]->flags &= ~DWC3_EP_RESOURCE_ALLOCATED ; +for (i = resource_index; i < dwc->num_eps; i++) { + dep = dwc->eps[i]; +if (!dep) +continue ; + + dep->flags &= ~DWC3_EP_RESOURCE_ALLOCATED ; + }return 0 ; }
@@ -751,9 +757,11 @@ void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) dwc->last_fifo_depth = fifo_depth;/* Clear existing TXFIFO for all IN eps except ep0 */ -for (num =3 ; num <min_t (int, dwc->num_eps,DWC3_ENDPOINTS_NUM ); - num +=2 ) { +for (num =3 ; num <min_t (int, dwc->num_eps,DWC3_ENDPOINTS_NUM ); num +=2 ) { dep = dwc->eps[num]; +if (!dep) +continue ; +/* Don't change TXFRAMNUM on usb31 version */ size =DWC3_IP_IS (DWC3 ) ?0 : dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) &
@@ -3657,6 +3665,8 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,for (i =0 ; i <DWC3_ENDPOINTS_NUM ; i++) { dep = dwc->eps[i]; +if (!dep) +continue ;if (!(dep->flags &DWC3_EP_ENABLED ))continue ;
@@ -3845,6 +3855,10 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,u8 epnum = event->endpoint_number; dep = dwc->eps[epnum]; +if (!dep) { +dev_warn (dwc->dev,"spurious event, endpoint %u is not allocated\n" , epnum); +return ; + }if (!(dep->flags &DWC3_EP_ENABLED )) {if ((epnum >1 ) && !(dep->flags &DWC3_EP_TRANSFER_STARTED ))
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 8/28 usb: dwc3: gadget: Avoid using reserved endpoints on Intel Merrifield
In reply to Sasha LevinFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 461f24bff86808ee5fbfe74751a825f8a7ab24e0 ]
Intel Merrifield SoC uses these endpoints for tracing and they cannot be re-allocated if being used because the side band flow control signals are hard wired to certain endpoints:
• 1 High BW Bulk IN (IN#1) (RTIT)
• 1 1KB BW Bulk IN (IN#8) + 1 1KB BW Bulk OUT (Run Control) (OUT#8)
In device mode, since RTIT (EP#1) and EXI/RunControl (EP#8) uses External Buffer Control (EBC) mode, these endpoints are to be mapped to EBC mode (to be done by EXI target driver). Additionally TRB for RTIT and EXI are maintained in STM (System Trace Module) unit and the EXI target driver will as well configure the TRB location for EP #1 IN and EP#8 (IN and OUT). Since STM/PTI and EXI hardware blocks manage these endpoints and interface to OTG3 controller through EBC interface, there is no need to enable any events (such as XferComplete etc) for these end points.
--- drivers/usb/dwc3/dwc3-pci.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/usb/dwc3/dwc3-pci.c +10 -0
@@ -148,11 +148,21 @@ static const struct property_entry dwc3_pci_intel_byt_properties[] = { {} }; +/* +* Intel Merrifield SoC uses these endpoints for tracing and they cannot +* be re-allocated if being used because the side band flow control signals +* are hard wired to certain endpoints: +* - 1 High BW Bulk IN (IN#1) (RTIT) +* - 1 1KB BW Bulk IN (IN#8) + 1 1KB BW Bulk OUT (Run Control) (OUT#8) +*/ +static const u8 dwc3_pci_mrfld_reserved_endpoints[] = {3 ,16 ,17 }; +static const struct property_entry dwc3_pci_mrfld_properties[] = {PROPERTY_ENTRY_STRING ("dr_mode" ,"otg" ),PROPERTY_ENTRY_STRING ("linux,extcon-name" ,"mrfld_bcove_pwrsrc" ),PROPERTY_ENTRY_BOOL ("snps,dis_u3_susphy_quirk" ),PROPERTY_ENTRY_BOOL ("snps,dis_u2_susphy_quirk" ), +PROPERTY_ENTRY_U8_ARRAY ("snps,reserved-endpoints" , dwc3_pci_mrfld_reserved_endpoints),PROPERTY_ENTRY_BOOL ("snps,usb2-gadget-lpm-disable" ),PROPERTY_ENTRY_BOOL ("linux,sysdev_is_parent" ), {}
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 9/28 sound/virtio: Fix cancel_sync warnings on uninitialized work_structs
In reply to Sasha LevinFrom: John Stultz <[email protected]>
[ Upstream commit 3c7df2e27346eb40a0e86230db1ccab195c97cfe ]
Betty reported hitting the following warning:
[ 8.709131][ T221] WARNING: CPU: 2 PID: 221 at kernel/workqueue.c:4182 ... [ 8.713282][ T221] Call trace: [ 8.713365][ T221] __flush_work+0x8d0/0x914 [ 8.713468][ T221] __cancel_work_sync+0xac/0xfc [ 8.713570][ T221] cancel_work_sync+0x24/0x34 [ 8.713667][ T221] virtsnd_remove+0xa8/0xf8 [virtio_snd ab15f34d0dd772f6d11327e08a81d46dc9c36276] [ 8.713868][ T221] virtsnd_probe+0x48c/0x664 [virtio_snd ab15f34d0dd772f6d11327e08a81d46dc9c36276] [ 8.714035][ T221] virtio_dev_probe+0x28c/0x390 [ 8.714139][ T221] really_probe+0x1bc/0x4c8
...
It seems we're hitting the error path in virtsnd_probe(), which triggers a virtsnd_remove() which iterates over the substreams calling cancel_work_sync() on the elapsed_period work_struct.
Looking at the code, from earlier in:
virtsnd_probe()->virtsnd_build_devs()->virtsnd_pcm_parse_cfg()
We set snd->nsubstreams, allocate the snd->substreams, and if we then hit an error on the info allocation or something in virtsnd_ctl_query_info() fails, we will exit without having initialized the elapsed_period work_struct.
When that error path unwinds we then call virtsnd_remove() which as long as the substreams array is allocated, will iterate through calling cancel_work_sync() on the uninitialized work struct hitting this warning.
Takashi Iwai suggested this fix, which initializes the substreams structure right after allocation, so that if we hit the error paths we avoid trying to cleanup uninitialized data.
Note: I have not yet managed to reproduce the issue myself, so this patch has had limited testing.
Feedback or thoughts would be appreciated!
Message-Id: <[email protected]>
--- sound/virtio/virtio_pcm.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
sound/virtio/virtio_pcm.c +15 -6
@@ -339,6 +339,21 @@ int virtsnd_pcm_parse_cfg(struct virtio_snd *snd)if (!snd->substreams)return -ENOMEM ; +/* +* Initialize critical substream fields early in case we hit an +* error path and end up trying to clean up uninitialized structures +* elsewhere. +*/ +for (i =0 ; i < snd->nsubstreams; ++i) { +struct virtio_pcm_substream *vss = &snd->substreams[i]; + + vss->snd = snd; + vss->sid = i; +INIT_WORK (&vss->elapsed_period, virtsnd_pcm_period_elapsed); +init_waitqueue_head (&vss->msg_empty); +spin_lock_init (&vss->lock); + } + info =kcalloc (snd->nsubstreams,sizeof (*info),GFP_KERNEL );if (!info)return -ENOMEM ;
@@ -352,12 +367,6 @@ int virtsnd_pcm_parse_cfg(struct virtio_snd *snd)struct virtio_pcm_substream *vss = &snd->substreams[i];struct virtio_pcm *vpcm; - vss->snd = snd; - vss->sid = i; -INIT_WORK (&vss->elapsed_period, virtsnd_pcm_period_elapsed); -init_waitqueue_head (&vss->msg_empty); -spin_lock_init (&vss->lock); - rc =virtsnd_pcm_build_hw (vss, &info[i]);if (rc) goto on_exit;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 10/28 usb: xhci: Complete 'error mid TD' transfers when handling Missed Service
In reply to Sasha LevinFrom: Michal Pecio <[email protected]>
[ Upstream commit bfa8459942822bdcc86f0e87f237c0723ae64948 ]
Missed Service Error after an error mid TD means that the failed TD has already been passed by the xHC without acknowledgment of the final TRB, a known hardware bug. So don't wait any more and give back the TD.
Reproduced on NEC uPD720200 under conditions of ludicrously bad USB link quality, confirmed to behave as expected using dynamic debug.
--- drivers/usb/host/xhci-ring.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-ring.c +5 -1
@@ -2786,7 +2786,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,xhci_dbg (xhci,"Miss service interval error for slot %u ep %u, set skip flag\n" , slot_id, ep_index); -return 0 ; +break ;case COMP_NO_PING_RESPONSE_ERROR : ep->skip = true; xhci_dbg(xhci,
@@ -2834,6 +2834,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,xhci_dequeue_td (xhci, td, ep_ring, td->status); } +/* Missed TDs will be skipped on the next event */ +if (trb_comp_code ==COMP_MISSED_SERVICE_ERROR ) +return 0 ; +if (list_empty (&ep_ring->td_list)) {/* * Don't print wanings if ring is empty due to a stopped endpoint generating an
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 11/28 usb: xhci: Fix isochronous Ring Underrun/Overrun event handling
In reply to Sasha LevinFrom: Michal Pecio <[email protected]>
[ Upstream commit 906dec15b9b321b546fd31a3c99ffc13724c7af4 ]
The TRB pointer of these events points at enqueue at the time of error occurrence on xHCI 1.1+ HCs or it's NULL on older ones. By the time we are handling the event, a new TD may be queued at this ring position.
I can trigger this race by rising interrupt moderation to increase IRQ handling delay. Similar delay may occur naturally due to system load.
If this ever happens after a Missed Service Error, missed TDs will be skipped and the new TD processed as if it matched the event. It could be given back prematurely, risking data loss or buffer UAF by the xHC.
Don't complete TDs on xrun events and don't warn if queued TDs don't match the event's TRB pointer, which can be NULL or a link/no-op TRB. Don't warn if there are no queued TDs at all.
Now that it's safe, also handle xrun events if the skip flag is clear. This ensures completion of any TD stuck in 'error mid TD' state right before the xrun event, which could happen if a driver submits a finite number of URBs to a buggy HC and then an error occurs on the last TD.
--- drivers/usb/host/xhci-ring.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/usb/host/xhci-ring.c +14 -6
@@ -2661,6 +2661,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,int status = -EINPROGRESS ;struct xhci_ep_ctx *ep_ctx;u32 trb_comp_code; +bool ring_xrun_event = false; slot_id =TRB_TO_SLOT_ID (le32_to_cpu (event->flags)); ep_index =TRB_TO_EP_ID (le32_to_cpu (event->flags)) -1 ;
@@ -2767,14 +2768,12 @@ static int handle_tx_event(struct xhci_hcd *xhci,* Underrun Event for OUT Isoch endpoint. */ xhci_dbg (xhci,"Underrun event on slot %u ep %u\n" , slot_id, ep_index); -if (ep->skip) -break ; -return 0 ; + ring_xrun_event = true; +break ;case COMP_RING_OVERRUN :xhci_dbg (xhci,"Overrun event on slot %u ep %u\n" , slot_id, ep_index); -if (ep->skip) -break ; -return 0 ; + ring_xrun_event = true; +break ;case COMP_MISSED_SERVICE_ERROR :/* * When encounter missed service error, one or more isoc tds
@@ -2847,6 +2846,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,*/ if (trb_comp_code !=COMP_STOPPED && trb_comp_code !=COMP_STOPPED_LENGTH_INVALID && + !ring_xrun_event && !ep_ring->last_td_was_short) {xhci_warn (xhci,"Event TRB for slot %u ep %u with no TDs queued\n" , slot_id, ep_index);
@@ -2877,6 +2877,10 @@ static int handle_tx_event(struct xhci_hcd *xhci, goto check_endpoint_halted; } +/* TD was queued after xrun, maybe xrun was on a link, don't panic yet */ +if (ring_xrun_event) +return 0 ; +/* * Skip the Force Stopped Event. The 'ep_trb' of FSE is not in the current * TD pointed by 'ep_ring->dequeue' because that the hardware dequeue
@@ -2923,6 +2927,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,*/ }while (ep->skip); +/* Get out if a TD was queued at enqueue after the xrun occurred */ +if (ring_xrun_event) +return 0 ; +if (trb_comp_code ==COMP_SHORT_PACKET ) ep_ring->last_td_was_short = true;else
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 12/28 xhci: Handle spurious events on Etron host isoc enpoints
In reply to Sasha LevinFrom: Mathias Nyman <[email protected]>
[ Upstream commit b331a3d8097fad4e541d212684192f21fedbd6e5 ]
Unplugging a USB3.0 webcam from Etron hosts while streaming results in errors like this:
[ 2.646387] xhci_hcd 0000:03:00.0: ERROR Transfer event TRB DMA ptr not part of current TD ep_index 18 comp_code 13 [ 2.646446] xhci_hcd 0000:03:00.0: Looking for event-dma 000000002fdf8630 trb-start 000000002fdf8640 trb-end 000000002fdf8650 [ 2.646560] xhci_hcd 0000:03:00.0: ERROR Transfer event TRB DMA ptr not part of current TD ep_index 18 comp_code 13 [ 2.646568] xhci_hcd 0000:03:00.0: Looking for event-dma 000000002fdf8660 trb-start 000000002fdf8670 trb-end 000000002fdf8670
Etron xHC generates two transfer events for the TRB if an error is detected while processing the last TRB of an isoc TD.
The first event can be any sort of error (like USB Transaction or Babble Detected, etc), and the final event is Success.
The xHCI driver will handle the TD after the first event and remove it from its internal list, and then print an "Transfer event TRB DMA ptr not part of current TD" error message after the final event.
Commit 5372c65e1311 ("xhci: process isoc TD properly when there was a transaction error mid TD.") is designed to address isoc transaction errors, but unfortunately it doesn't account for this scenario.
This issue is similar to the XHCI_SPURIOUS_SUCCESS case where a success event follows a 'short transfer' event, but the TD the event points to is already given back.
Expand the spurious success 'short transfer' event handling to cover the spurious success after error on Etron hosts.
Kuangyi Chiang reported this issue and submitted a different solution based on using error_mid_td. This commit message is mostly taken from that patch.
--- drivers/usb/host/xhci-ring.c | 38 ++++++++++++++++++++++++------------ drivers/usb/host/xhci.h | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-)
drivers/usb/host/xhci-ring.c +26 -12
@@ -2641,6 +2641,22 @@ static int handle_transferless_tx_event(struct xhci_hcd *xhci, struct xhci_virt_return 0 ; } +static bool xhci_spurious_success_tx_event (struct xhci_hcd *xhci, +struct xhci_ring *ring) +{ +switch (ring->old_trb_comp_code) { +case COMP_SHORT_PACKET : +return xhci->quirks &XHCI_SPURIOUS_SUCCESS ; +case COMP_USB_TRANSACTION_ERROR : +case COMP_BABBLE_DETECTED_ERROR : +case COMP_ISOCH_BUFFER_OVERRUN : +return xhci->quirks &XHCI_ETRON_HOST && + ring->type ==TYPE_ISOC ; +default : +return false; + } +} +/* * If this function returns an error condition, it means it got a Transfer * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address.
@@ -2695,8 +2711,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,case COMP_SUCCESS :if (EVENT_TRB_LEN (le32_to_cpu (event->transfer_len)) !=0 ) { trb_comp_code =COMP_SHORT_PACKET ; -xhci_dbg (xhci,"Successful completion on short TX for slot %u ep %u with last td short %d\n" , - slot_id, ep_index, ep_ring->last_td_was_short); +xhci_dbg (xhci,"Successful completion on short TX for slot %u ep %u with last td comp code %d\n" , + slot_id, ep_index, ep_ring->old_trb_comp_code); }break ;case COMP_SHORT_PACKET :
@@ -2847,7 +2863,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,if (trb_comp_code !=COMP_STOPPED && trb_comp_code !=COMP_STOPPED_LENGTH_INVALID && !ring_xrun_event && - !ep_ring->last_td_was_short) { + !xhci_spurious_success_tx_event (xhci, ep_ring)) {xhci_warn (xhci,"Event TRB for slot %u ep %u with no TDs queued\n" , slot_id, ep_index); }
@@ -2895,11 +2911,12 @@ static int handle_tx_event(struct xhci_hcd *xhci,/* * Some hosts give a spurious success event after a short -* transfer. Ignore it. +* transfer or error on last TRB. Ignore it. */ -if ((xhci->quirks &XHCI_SPURIOUS_SUCCESS ) && - ep_ring->last_td_was_short) { - ep_ring->last_td_was_short = false; +if (xhci_spurious_success_tx_event (xhci, ep_ring)) { +xhci_dbg (xhci,"Spurious event dma %pad, comp_code %u after %u\n" , + &ep_trb_dma, trb_comp_code, ep_ring->old_trb_comp_code); + ep_ring->old_trb_comp_code = trb_comp_code;return 0 ; }
@@ -2927,15 +2944,12 @@ static int handle_tx_event(struct xhci_hcd *xhci,*/ }while (ep->skip); + ep_ring->old_trb_comp_code = trb_comp_code; +/* Get out if a TD was queued at enqueue after the xrun occurred */ if (ring_xrun_event)return 0 ; -if (trb_comp_code ==COMP_SHORT_PACKET ) - ep_ring->last_td_was_short = true; -else - ep_ring->last_td_was_short = false; - ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) /sizeof (*ep_trb)];trace_xhci_handle_transfer (ep_ring, (struct xhci_generic_trb *) ep_trb, ep_trb_dma);
drivers/usb/host/xhci.h +1 -1
@@ -1367,7 +1367,7 @@ struct xhci_ring {unsigned int num_trbs_free;/* used only by xhci DbC */ unsigned int bounce_buf_len;enum xhci_ring_type type; -bool last_td_was_short; +u32 old_trb_comp_code;struct radix_tree_root *trb_address_map; };
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 13/28 i3c: master: svc: Add support for Nuvoton npcm845 i3c
In reply to Sasha LevinFrom: Stanley Chu <[email protected]>
[ Upstream commit 98d87600a04e42282797631aa6b98dd43999e274 ]
Nuvoton npcm845 SoC uses an older IP version, which has specific hardware issues that need to be addressed with a different compatible string.
Add driver data for different compatible strings to define platform specific quirks.
Add compatible string for npcm845 to define its own driver data.
--- drivers/i3c/master/svc-i3c-master.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/i3c/master/svc-i3c-master.c +16 -1
@@ -158,6 +158,10 @@ struct svc_i3c_regs_save {u32 mdynaddr; }; +struct svc_i3c_drvdata { +u32 quirks; +}; +/** * struct svc_i3c_master - Silvaco I3C Master structure * @base: I3C master controller
@@ -183,6 +187,7 @@ struct svc_i3c_regs_save {* @ibi.tbq_slot: To be queued IBI slot * @ibi.lock: IBI lock * @lock: Transfer lock, protect between IBI work thread and callbacks from master +* @drvdata: Driver data * @enabled_events: Bit masks for enable events (IBI, HotJoin). * @mctrl_config: Configuration value in SVC_I3C_MCTRL for setting speed back. */
@@ -214,6 +219,7 @@ struct svc_i3c_master {spinlock_t lock; } ibi;struct mutex lock; +const struct svc_i3c_drvdata *drvdata;u32 enabled_events;u32 mctrl_config; };
@@ -1817,6 +1823,10 @@ static int svc_i3c_master_probe(struct platform_device *pdev)if (!master)return -ENOMEM ; + master->drvdata =of_device_get_match_data (dev); +if (!master->drvdata) +return -EINVAL ; + master->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (master->regs))return PTR_ERR (master->regs);
@@ -1958,8 +1968,13 @@ static const struct dev_pm_ops svc_i3c_pm_ops = { svc_i3c_runtime_resume, NULL) }; +static const struct svc_i3c_drvdata npcm845_drvdata = {}; + +static const struct svc_i3c_drvdata svc_default_drvdata = {}; +static const struct of_device_id svc_i3c_master_of_match_tbl[] = { - { .compatible ="silvaco,i3c-master-v1" }, + { .compatible ="nuvoton,npcm845-i3c" , .data = &npcm845_drvdata }, + { .compatible ="silvaco,i3c-master-v1" , .data = &svc_default_drvdata }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, svc_i3c_master_of_match_tbl);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 14/28 dmaengine: dmatest: Fix dmatest waiting less when interrupted
In reply to Sasha LevinFrom: Vinicius Costa Gomes <[email protected]>
[ Upstream commit e87ca16e99118ab4e130a41bdf12abbf6a87656c ]
Change the "wait for operation finish" logic to take interrupts into account.
When using dmatest with idxd DMA engine, it's possible that during longer tests, the interrupt notifying the finish of an operation happens during wait_event_freezable_timeout(), which causes dmatest to cleanup all the resources, some of which might still be in use.
This fix ensures that the wait logic correctly handles interrupts, preventing premature cleanup of resources.
--- drivers/dma/dmatest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/dmatest.c +3 -3
@@ -841,9 +841,9 @@ static int dmatest_func(void *data) }else {dma_async_issue_pending (chan); -wait_event_freezable_timeout (thread->done_wait, - done->done, -msecs_to_jiffies (params->timeout)); +wait_event_timeout (thread->done_wait, + done->done, +msecs_to_jiffies (params->timeout)); status =dma_async_is_tx_complete (chan, cookie,NULL ,NULL );
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 15/28 usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running
In reply to Sasha LevinFrom: Michal Pecio <[email protected]>
[ Upstream commit 28a76fcc4c85dd39633fb96edb643c91820133e3 ]
Nothing prevents a broken HC from claiming that an endpoint is Running and repeatedly rejecting Stop Endpoint with Context State Error.
Avoid infinite retries and give back cancelled TDs.
No such cases known so far, but HCs have bugs.
--- drivers/usb/host/xhci-ring.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-ring.c +7 -4
@@ -1197,16 +1197,19 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,* Stopped state, but it will soon change to Running. * * Assume this bug on unexpected Stop Endpoint failures. -* Keep retrying until the EP starts and stops again, on -* chips where this is known to help. Wait for 100ms. +* Keep retrying until the EP starts and stops again. */ -if (time_is_before_jiffies (ep->stop_time +msecs_to_jiffies (100 ))) -break ; fallthrough;case EP_STATE_RUNNING :/* Race, HW handled stop ep cmd before ep was running */ xhci_dbg (xhci,"Stop ep completion ctx error, ctx_state %d\n" ,GET_EP_CTX_STATE (ep_ctx)); +/* +* Don't retry forever if we guessed wrong or a defective HC never starts +* the EP or says 'Running' but fails the command. We must give back TDs. +*/ +if (time_is_before_jiffies (ep->stop_time +msecs_to_jiffies (100 ))) +break ; command =xhci_alloc_command (xhci, false,GFP_ATOMIC );if (!command) {
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 16/28 phy: rockchip: usbdp: Avoid call hpd_event_trigger in dp_phy_init
In reply to Sasha LevinFrom: Andy Yan <[email protected]>
[ Upstream commit 28dc672a1a877c77b000c896abd8f15afcdc1b0c ]
Function rk_udphy_dp_hpd_event_trigger will set vogrf let it trigger HPD interrupt to DP by Type-C. This configuration is only required when the DP work in Alternate Mode, and called by typec_mux_set. In standard DP mode, such settings will prevent the DP from receiving HPD interrupts.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 1 - 1 file changed, 1 deletion(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +0 -1
@@ -1045,7 +1045,6 @@ static int rk_udphy_dp_phy_init(struct phy *phy)mutex_lock (&udphy->mutex); udphy->dp_in_use = true; -rk_udphy_dp_hpd_event_trigger (udphy, udphy->dp_sink_hpd_cfg);mutex_unlock (&udphy->mutex);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 17/28 usb: gadget: aspeed: Add NULL pointer check in ast_vhub_init_dev()
In reply to Sasha LevinFrom: Chenyuan Yang <[email protected]>
[ Upstream commit 8c75f3e6a433d92084ad4e78b029ae680865420f ]
The variable d->name, returned by devm_kasprintf(), could be NULL. A pointer check is added to prevent potential NULL pointer dereference. This is similar to the fix in commit 3027e7b15b02
("ice: Fix some null pointer dereference issues in ice_ptp.c").
This issue is found by our static analysis tool
--- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/gadget/udc/aspeed-vhub/dev.c +3 -0
@@ -548,6 +548,9 @@ int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx) d->vhub = vhub; d->index = idx; d->name =devm_kasprintf (parent,GFP_KERNEL ,"port%d" , idx+1 ); +if (!d->name) +return -ENOMEM ; + d->regs = vhub->regs +0x100 +0x10 * idx;ast_vhub_init_ep0 (vhub, &d->ep0, d);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 18/28 usb: host: xhci-plat: mvebu: use ->quirks instead of ->init_quirk() func
In reply to Sasha LevinFrom: Théo Lebrun <[email protected]>
[ Upstream commit 64eb182d5f7a5ec30227bce4f6922ff663432f44 ]
Compatible "marvell,armada3700-xhci" match data uses the struct xhci_plat_priv::init_quirk() function pointer to add XHCI_RESET_ON_RESUME as quirk on XHCI.
Instead, use the struct xhci_plat_priv::quirks field.
--- drivers/usb/host/xhci-mvebu.c | 10 ---------- drivers/usb/host/xhci-mvebu.h | 6 ------ drivers/usb/host/xhci-plat.c | 2 +- 3 files changed, 1 insertion(+), 17 deletions(-)
drivers/usb/host/xhci-mvebu.c +0 -10
@@ -73,13 +73,3 @@ int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)return 0 ; } - -int xhci_mvebu_a3700_init_quirk (struct usb_hcd *hcd) -{ -struct xhci_hcd *xhci =hcd_to_xhci (hcd); - -/* Without reset on resume, the HC won't work at all */ - xhci->quirks |=XHCI_RESET_ON_RESUME ; - -return 0 ; -}
drivers/usb/host/xhci-mvebu.h +0 -6
@@ -12,16 +12,10 @@ struct usb_hcd;#if IS_ENABLED (CONFIG_USB_XHCI_MVEBU )int xhci_mvebu_mbus_init_quirk (struct usb_hcd *hcd); -int xhci_mvebu_a3700_init_quirk (struct usb_hcd *hcd);#else static inline int xhci_mvebu_mbus_init_quirk (struct usb_hcd *hcd) {return 0 ; } - -static inline int xhci_mvebu_a3700_init_quirk (struct usb_hcd *hcd) -{ -return 0 ; -}#endif #endif /* __LINUX_XHCI_MVEBU_H */
drivers/usb/host/xhci-plat.c +1 -1
@@ -106,7 +106,7 @@ static const struct xhci_plat_priv xhci_plat_marvell_armada = { };static const struct xhci_plat_priv xhci_plat_marvell_armada3700 = { - .init_quirk = xhci_mvebu_a3700_init_quirk, + .quirks =XHCI_RESET_ON_RESUME , };static const struct xhci_plat_priv xhci_plat_brcm = {
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 19/28 thunderbolt: Scan retimers after device router has been enumerated
In reply to Sasha LevinFrom: Mika Westerberg <[email protected]>
[ Upstream commit 75749d2c1d8cef439f8b69fa1f4f36d0fc3193e6 ]
Thomas reported connection issues on AMD system with Pluggable UD-4VPD dock. After some experiments it looks like the device has some sort of internal timeout that triggers reconnect. This is completely against the USB4 spec, as there is no requirement for the host to enumerate the device right away or even at all.
In Linux case the delay is caused by scanning of retimers on the link so we can work this around by doing the scanning after the device router has been enumerated.
--- drivers/thunderbolt/tb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/thunderbolt/tb.c +14 -2
@@ -1295,11 +1295,15 @@ static void tb_scan_port(struct tb_port *port) goto out_rpm_put; } -tb_retimer_scan (port, true); - sw =tb_switch_alloc (port->sw->tb, &port->sw->dev,tb_downstream_route (port));if (IS_ERR (sw)) { +/* +* Make the downstream retimers available even if there +* is no router connected. +*/ +tb_retimer_scan (port, true); +/* * If there is an error accessing the connected switch * it may be connected to another domain. Also we allow
@@ -1349,6 +1353,14 @@ static void tb_scan_port(struct tb_port *port) upstream_port =tb_upstream_port (sw);tb_configure_link (port, upstream_port, sw); +/* +* Scan for downstream retimers. We only scan them after the +* router has been enumerated to avoid issues with certain +* Pluggable devices that expect the host to enumerate them +* within certain timeout. +*/ +tb_retimer_scan (port, true); +/* * CL0s and CL1 are enabled and supported together. * Silently ignore CLx enabling in case CLx is not supported.
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 20/28 um: work around sched_yield not yielding in time-travel mode
In reply to Sasha LevinFrom: Benjamin Berg <[email protected]>
[ Upstream commit 887c5c12e80c8424bd471122d2e8b6b462e12874 ]
sched_yield by a userspace may not actually cause scheduling in time-travel mode as no time has passed. In the case seen it appears to be a badly implemented userspace spinlock in ASAN. Unfortunately, with time-travel it causes an extreme slowdown or even deadlock depending on the kernel configuration (CONFIG_UML_MAX_USERSPACE_ITERATIONS).
Work around it by accounting time to the process whenever it executes a sched_yield syscall.
--- arch/um/include/linux/time-internal.h | 2 ++ arch/um/kernel/skas/syscall.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
arch/um/include/linux/time-internal.h +2 -0
@@ -83,6 +83,8 @@ extern void time_travel_not_configured(void);#define time_travel_del_event (...) time_travel_not_configured()#endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */ +extern unsigned long tt_extra_sched_jiffies; +/* * Without CONFIG_UML_TIME_TRAVEL_SUPPORT this is a linker error if used, * which is intentional since we really shouldn't link it in that case.
arch/um/kernel/skas/syscall.c +11 -0
@@ -31,6 +31,17 @@ void handle_syscall(struct uml_pt_regs *r) goto out; syscall =UPT_SYSCALL_NR (r); + +/* +* If no time passes, then sched_yield may not actually yield, causing +* broken spinlock implementations in userspace (ASAN) to hang for long +* periods of time. +*/ +if ((time_travel_mode ==TT_MODE_INFCPU || + time_travel_mode ==TT_MODE_EXTERNAL ) && + syscall == __NR_sched_yield) + tt_extra_sched_jiffies +=1 ; +if (syscall >=0 && syscall < __NR_syscalls) {unsigned long ret =EXECUTE_SYSCALL (syscall, regs);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 21/28 iommu/arm-smmu-v3: Set MEV bit in nested STE for DoS mitigations
In reply to Sasha LevinFrom: Nicolin Chen <[email protected]>
[ Upstream commit da0c56520e880441d0503d0cf0d6853dcfb5f1a4 ]
There is a DoS concern on the shared hardware event queue among devices passed through to VMs, that too many translation failures that belong to VMs could overflow the shared hardware event queue if those VMs or their VMMs don't handle/recover the devices properly.
The MEV bit in the STE allows to configure the SMMU HW to merge similar event records, though there is no guarantee. Set it in a nested STE for DoS mitigations.
In the future, we might want to enable the MEV for non-nested cases too such as domain->type == IOMMU_DOMAIN_UNMANAGED or even IOMMU_DOMAIN_DMA.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 2 ++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +2 -0
@@ -43,6 +43,8 @@ static void arm_smmu_make_nested_cd_table_ste( target->data[0 ] |= nested_domain->ste[0 ] & ~cpu_to_le64 (STRTAB_STE_0_CFG ); target->data[1 ] |= nested_domain->ste[1 ]; +/* Merge events for DoS mitigations on eventq */ + target->data[1 ] |=cpu_to_le64 (STRTAB_STE_1_MEV ); }/*
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -2
@@ -1031,7 +1031,7 @@ void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits)cpu_to_le64 (STRTAB_STE_1_S1DSS |STRTAB_STE_1_S1CIR |STRTAB_STE_1_S1COR |STRTAB_STE_1_S1CSH |STRTAB_STE_1_S1STALLD |STRTAB_STE_1_STRW | -STRTAB_STE_1_EATS ); +STRTAB_STE_1_EATS |STRTAB_STE_1_MEV ); used_bits[2 ] |=cpu_to_le64 (STRTAB_STE_2_S2VMID );/*
@@ -1047,7 +1047,7 @@ void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits)if (cfg &BIT (1 )) { used_bits[1 ] |=cpu_to_le64 (STRTAB_STE_1_S2FWB |STRTAB_STE_1_EATS | -STRTAB_STE_1_SHCFG ); +STRTAB_STE_1_SHCFG |STRTAB_STE_1_MEV ); used_bits[2 ] |= cpu_to_le64(STRTAB_STE_2_S2VMID | STRTAB_STE_2_VTCR | STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2ENDI |
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +1 -0
@@ -266,6 +266,7 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid)#define STRTAB_STE_1_S1COR GENMASK_ULL(5, 4)#define STRTAB_STE_1_S1CSH GENMASK_ULL(7, 6) +#define STRTAB_STE_1_MEV (1UL << 19)#define STRTAB_STE_1_S2FWB (1UL << 25)#define STRTAB_STE_1_S1STALLD (1UL << 27)
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 22/28 um: Switch to the pthread-based helper in sigio workaround
In reply to Sasha LevinFrom: Tiwei Bie <[email protected]>
[ Upstream commit d295beeed2552a987796d627ba7d0985b1e2d72f ]
The write_sigio thread and UML kernel thread share the same errno, which can lead to conflicts when both call syscalls concurrently. Switch to the pthread-based helper to address this issue.
--- arch/um/os-Linux/sigio.c | 44 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-)
arch/um/os-Linux/sigio.c +19 -25
@@ -21,8 +21,7 @@* Protected by sigio_lock(), also used by sigio_cleanup, which is an * exitcall. */ -static int write_sigio_pid =-1 ; -static unsigned long write_sigio_stack; +static struct os_helper_thread *write_sigio_td;/* * These arrays are initialized before the sigio thread is started, and
@@ -48,15 +47,15 @@ static struct pollfds current_poll;static struct pollfds next_poll;static struct pollfds all_sigio_fds; -static int write_sigio_thread (void *unused) +static void *write_sigio_thread (void *unused) {struct pollfds *fds, tmp;struct pollfd *p;int i, n, respond_fd;char c; -os_set_pdeathsig (); -os_fix_helper_signals (); +os_fix_helper_thread_signals (); + fds = ¤t_poll;while (1 ) { n =poll (fds->poll, fds->used,-1 );
@@ -98,7 +97,7 @@ static int write_sigio_thread(void *unused) } } -return 0 ; +return NULL ; }static int need_poll (struct pollfds *polls,int n)
@@ -152,11 +151,10 @@ static void update_thread(void)return ; fail:/* Critical section start */ -if (write_sigio_pid !=-1 ) { -os_kill_process (write_sigio_pid,1 ); -free_stack (write_sigio_stack,0 ); +if (write_sigio_td) { +os_kill_helper_thread (write_sigio_td); + write_sigio_td =NULL ; } - write_sigio_pid =-1 ;close (sigio_private[0 ]);close (sigio_private[1 ]);close (write_sigio_fds[0 ]);
@@ -220,7 +218,7 @@ int __ignore_sigio_fd(int fd)* sigio_cleanup has already run, then update_thread will hang * or fail because the thread is no longer running. */ -if (write_sigio_pid ==-1 ) +if (!write_sigio_td)return -EIO ;for (i =0 ; i < current_poll.used; i++) {
@@ -279,14 +277,14 @@ static void write_sigio_workaround(void)int err;int l_write_sigio_fds[2 ];int l_sigio_private[2 ]; -int l_write_sigio_pid; +struct os_helper_thread *l_write_sigio_td;/* We call this *tons* of times - and most ones we must just fail. */ sigio_lock (); - l_write_sigio_pid = write_sigio_pid; + l_write_sigio_td = write_sigio_td;sigio_unlock (); -if (l_write_sigio_pid !=-1 ) +if (l_write_sigio_td)return ; err =os_pipe (l_write_sigio_fds,1 ,1 );
@@ -312,7 +310,7 @@ static void write_sigio_workaround(void)* Did we race? Don't try to optimize this, please, it's not so likely * to happen, and no more than once at the boot. */ -if (write_sigio_pid !=-1 ) +if (write_sigio_td) goto out_free; current_poll = ((struct pollfds) { .poll = p,
@@ -325,18 +323,15 @@ static void write_sigio_workaround(void)memcpy (write_sigio_fds, l_write_sigio_fds,sizeof (l_write_sigio_fds));memcpy (sigio_private, l_sigio_private,sizeof (l_sigio_private)); - write_sigio_pid =run_helper_thread (write_sigio_thread,NULL , -CLONE_FILES |CLONE_VM , - &write_sigio_stack); - -if (write_sigio_pid <0 ) + err =os_run_helper_thread (&write_sigio_td, write_sigio_thread,NULL ); +if (err <0 ) goto out_clear;sigio_unlock ();return ; out_clear: - write_sigio_pid =-1 ; + write_sigio_td =NULL ; write_sigio_fds[0 ] =-1 ; write_sigio_fds[1 ] =-1 ; sigio_private[0 ] =-1 ;
@@ -394,12 +389,11 @@ void maybe_sigio_broken(int fd)static void sigio_cleanup (void ) { -if (write_sigio_pid ==-1 ) +if (!write_sigio_td)return ; -os_kill_process (write_sigio_pid,1 ); -free_stack (write_sigio_stack,0 ); - write_sigio_pid =-1 ; +os_kill_helper_thread (write_sigio_td); + write_sigio_td =NULL ; }__uml_exitcall (sigio_cleanup);
Signature · 1 line
2.39.5
Re: [PATCH AUTOSEL 6.13 22/28] um: Switch to the pthread-based helper in sigio workaround
Quoted 8 lines · Sasha Levin
From: Tiwei Bie <[email protected]>
[ Upstream commit
d295beeed2552a987796d627ba7d0985b1e2d72f]The
write_sigiothread and UML kernel thread share the same errno, which can lead to conflicts when both call syscalls concurrently. Switch to the pthread-based helper to address this issue.
Quoted 7 lines
Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Johannes Berg <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/um/os-Linux/sigio.c | 44 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-)
Please drop this patch. Thanks! Details can be found here:
https://lore.kernel.org/linux-um/[email protected]/
Regards,
Tiwei
Sasha Levin
maintainerPATCH 23/28 um: Rewrite the sigio workaround based on epoll and tgkill
In reply to Sasha LevinFrom: Tiwei Bie <[email protected]>
[ Upstream commit 33c9da5dfb18c2ff5a88d01aca2cf253cd0ac3bc ]
The existing sigio workaround implementation removes FDs from the poll when events are triggered, requiring users to re-add them via add_sigio_fd() after processing. This introduces a potential race condition between FD removal in write_sigio_thread() and next_poll update in __add_sigio_fd(), and is inefficient due to frequent FD removal and re-addition. Rewrite the implementation based on epoll and tgkill for improved efficiency and reliability.
--- arch/um/drivers/random.c | 2 +- arch/um/drivers/rtc_user.c | 2 +- arch/um/include/shared/os.h | 2 +- arch/um/include/shared/sigio.h | 1 - arch/um/kernel/sigio.c | 26 --- arch/um/os-Linux/sigio.c | 330 +++++---------------------------- 6 files changed, 47 insertions(+), 316 deletions(-)
arch/um/drivers/random.c +1 -1
@@ -79,7 +79,7 @@ static int __init rng_init (void)if (err <0 ) goto err_out_cleanup_hw; -sigio_broken (random_fd); +sigio_broken (); hwrng.name =RNG_MODULE_NAME ; hwrng.read = rng_dev_read;
arch/um/drivers/rtc_user.c +1 -1
@@ -39,7 +39,7 @@ int uml_rtc_start(bool timetravel) }/* apparently timerfd won't send SIGIO, use workaround */ -sigio_broken (uml_rtc_irq_fds[0 ]); +sigio_broken (); err =add_sigio_fd (uml_rtc_irq_fds[0 ]);if (err <0 ) {close (uml_rtc_irq_fds[0 ]);
arch/um/include/shared/os.h +1 -1
@@ -310,7 +310,7 @@ extern void um_irqs_resume(void);extern int add_sigio_fd (int fd);extern int ignore_sigio_fd (int fd);extern void maybe_sigio_broken (int fd); -extern void sigio_broken (int fd); +extern void sigio_broken (void );/* * unlocked versions for IRQ controller code. *
arch/um/include/shared/sigio.h +0 -1
@@ -6,7 +6,6 @@#ifndef __SIGIO_H__#define __SIGIO_H__ -extern int write_sigio_irq (int fd);extern void sigio_lock (void );extern void sigio_unlock (void );
arch/um/kernel/sigio.c +0 -26
@@ -8,32 +8,6 @@#include <os.h> #include <sigio.h> -/* Protected by sigio_lock() called from write_sigio_workaround */ -static int sigio_irq_fd =-1 ; - -static irqreturn_t sigio_interrupt (int irq,void *data) -{ -char c; - -os_read_file (sigio_irq_fd, &c,sizeof (c)); -return IRQ_HANDLED ; -} - -int write_sigio_irq (int fd) -{ -int err; - - err =um_request_irq (SIGIO_WRITE_IRQ , fd,IRQ_READ , sigio_interrupt, -0 ,"write sigio" ,NULL ); -if (err <0 ) { -printk (KERN_ERR "write_sigio_irq : um_request_irq failed, " -"err = %d\n" , err); -return -1 ; - } - sigio_irq_fd = fd; -return 0 ; -} -/* These are called from os-Linux/sigio.c to protect its pollfds arrays. */ static DEFINE_MUTEX (sigio_mutex);
arch/um/os-Linux/sigio.c +44 -286
397 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH AUTOSEL 6.13 23/28] um: Rewrite the sigio workaround based on epoll and tgkill
Quoted 16 lines · Sasha Levin
From: Tiwei Bie <[email protected]>
[ Upstream commit
33c9da5dfb18c2ff5a88d01aca2cf253cd0ac3bc]The existing sigio workaround implementation removes FDs from the poll when events are triggered, requiring users to re-add them via
add_sigio_fd()after processing. This introduces a potential race condition between FD removal inwrite_sigio_thread()andnext_pollupdate in__add_sigio_fd(), and is inefficient due to frequent FD removal and re-addition. Rewrite the implementation based on epoll and tgkill for improved efficiency and reliability.Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Johannes Berg <[email protected]>Signed-off-by Sasha Levin <[email protected]>
Quoted 8 lines
--- arch/um/drivers/random.c | 2 +- arch/um/drivers/rtc_user.c | 2 +- arch/um/include/shared/os.h | 2 +- arch/um/include/shared/sigio.h | 1 - arch/um/kernel/sigio.c | 26 --- arch/um/os-Linux/sigio.c | 330 +++++---------------------------- 6 files changed, 47 insertions(+), 316 deletions(-)
Please drop this patch. Thanks! Details can be found here:
https://lore.kernel.org/linux-um/[email protected]/
Regards,
Tiwei
Sasha Levin
maintainerRe: [PATCH AUTOSEL 6.13 23/28] um: Rewrite the sigio workaround based on epoll and tgkill
Quoted 26 lines · Tiwei Bie
Quoted 16 lines · Sasha Levin
From: Tiwei Bie <[email protected]>
[ Upstream commit
33c9da5dfb18c2ff5a88d01aca2cf253cd0ac3bc]The existing sigio workaround implementation removes FDs from the poll when events are triggered, requiring users to re-add them via
add_sigio_fd()after processing. This introduces a potential race condition between FD removal inwrite_sigio_thread()andnext_pollupdate in__add_sigio_fd(), and is inefficient due to frequent FD removal and re-addition. Rewrite the implementation based on epoll and tgkill for improved efficiency and reliability.Signed-off-by Tiwei Bie <[email protected]>Signed-off-by Johannes Berg <[email protected]>Signed-off-by Sasha Levin <[email protected]>Quoted 8 lines
--- arch/um/drivers/random.c | 2 +- arch/um/drivers/rtc_user.c | 2 +- arch/um/include/shared/os.h | 2 +- arch/um/include/shared/sigio.h | 1 - arch/um/kernel/sigio.c | 26 --- arch/um/os-Linux/sigio.c | 330 +++++---------------------------- 6 files changed, 47 insertions(+), 316 deletions(-)
Quoted 3 lines
Please drop this patch. Thanks! Details can be found here:
Dropped, thanks.
Signature · 2 lines
Thanks, Sasha
Sasha Levin
maintainerPATCH 24/28 objtool: Silence more KCOV warnings
In reply to Sasha LevinFrom: Josh Poimboeuf <[email protected]>
[ Upstream commit 6b023c7842048c4bbeede802f3cf36b96c7a8b25 ]
In the past there were issues with KCOV triggering unreachable instruction warnings, which is why unreachable warnings are now disabled with CONFIG_KCOV.
Now some new KCOV warnings are showing up with GCC 14:
vmlinux.o: warning: objtool: cpuset_write_resmask() falls through to next function cpuset_update_active_cpus.cold() drivers/usb/core/driver.o: error: objtool: usb_deregister() falls through to next function usb_match_device() sound/soc/codecs/snd-soc-wcd934x.o: warning: objtool: .text.wcd934x_slim_irq_handler: unexpected end of section
All are caused by GCC KCOV not finishing an optimization, leaving behind a never-taken conditional branch to a basic block which falls through to the next function (or end of section).
At a high level this is similar to the unreachable warnings mentioned above, in that KCOV isn't fully removing dead code. Treat it the same way by adding these to the list of warnings to ignore with CONFIG_KCOV.
--- tools/objtool/check.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/objtool/check.c +6 -0
@@ -3633,6 +3633,9 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, !strncmp(func->name, "__pfx_", 6))return 0 ; +if (file->ignore_unreachables) +return 0 ; +WARN ("%s() falls through to next function %s()" , func->name,insn_func (insn)->name);return 1 ;
@@ -3852,6 +3855,9 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,if (!next_insn) {if (state.cfi.cfa.base ==CFI_UNDEFINED )return 0 ; +if (file->ignore_unreachables) +return 0 ; +WARN ("%s: unexpected end of section" , sec->name);return 1 ; }
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 25/28 objtool, panic: Disable SMAP in __stack_chk_fail()
In reply to Sasha LevinFrom: Josh Poimboeuf <[email protected]>
[ Upstream commit 72c774aa9d1e16bfd247096935e7dae194d84929 ]
__stack_chk_fail() can be called from uaccess-enabled code. Make sure uaccess gets disabled before calling panic().
Fixes the following warning:
kernel/trace/trace_branch.o: error: objtool: ftrace_likely_update+0x1ea: call to __stack_chk_fail() with UACCESS enabled
--- kernel/panic.c | 6 ++++++ tools/objtool/check.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-)
kernel/panic.c +6 -0
@@ -832,9 +832,15 @@ device_initcall(register_warn_debugfs);*/ __visible noinstr void __stack_chk_fail(void) { +unsigned long flags; +instrumentation_begin (); + flags =user_access_save (); +panic ("stack-protector: Kernel stack is corrupted in: %pB" ,__builtin_return_address (0 )); + +user_access_restore (flags);instrumentation_end (); }EXPORT_SYMBOL (__stack_chk_fail);
tools/objtool/check.c +4 -1
@@ -1242,12 +1242,15 @@ static const char *uaccess_safe_builtin[] = {"__ubsan_handle_load_invalid_value" ,/* STACKLEAK */ "stackleak_track_stack" , +/* TRACE_BRANCH_PROFILING */ +"ftrace_likely_update" , +/* STACKPROTECTOR */ +"__stack_chk_fail" ,/* misc */ "csum_partial_copy_generic" ,"copy_mc_fragile" ,"copy_mc_fragile_handle_tail" ,"copy_mc_enhanced_fast_string" , -"ftrace_likely_update" ,/* CONFIG_TRACE_BRANCH_PROFILING */ "rep_stos_alternative" ,"rep_movs_alternative" , "__copy_user_nocache",
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 26/28 objtool, ASoC: codecs: wcd934x: Remove potential undefined behavior in wcd934x_slim_irq_handler()
In reply to Sasha LevinFrom: Josh Poimboeuf <[email protected]>
[ Upstream commit 060aed9c0093b341480770457093449771cf1496 ]
If 'port_id' is negative, the shift counts in wcd934x_slim_irq_handler() also become negative, resulting in undefined behavior due to shift out of bounds.
If I'm reading the code correctly, that appears to be not possible, but with KCOV enabled, Clang's range analysis isn't always able to determine that and generates undefined behavior.
As a result the code generation isn't optimal, and undefined behavior should be avoided regardless. Improve code generation and remove the undefined behavior by converting the signed variables to unsigned.
Fixes the following warning with UBSAN:
sound/soc/codecs/snd-soc-wcd934x.o: warning: objtool: .text.wcd934x_slim_irq_handler: unexpected end of section
--- sound/soc/codecs/wcd934x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/wcd934x.c +1 -1
@@ -2273,7 +2273,7 @@ static irqreturn_t wcd934x_slim_irq_handler(int irq, void *data) {struct wcd934x_codec *wcd = data;unsigned long status =0 ; -int i, j, port_id; +unsigned int i, j, port_id;unsigned int val, int_val =0 ;irqreturn_t ret =IRQ_NONE ;bool tx;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 27/28 objtool, regulator: rk808: Remove potential undefined behavior in rk806_set_mode_dcdc()
In reply to Sasha LevinFrom: Josh Poimboeuf <[email protected]>
[ Upstream commit 29c578c848402a34e8c8e115bf66cb6008b77062 ]
If 'ctr_bit' is negative, the shift counts become negative, causing a shift of bounds and undefined behavior.
Presumably that's not possible in normal operation, but the code generation isn't optimal. And undefined behavior should be avoided regardless.
Improve code generation and remove the undefined behavior by converting the signed variables to unsigned.
Fixes the following warning with an UBSAN kernel:
vmlinux.o: warning: objtool: rk806_set_mode_dcdc() falls through to next function rk806_get_mode_dcdc() vmlinux.o: warning: objtool: .text.rk806_set_mode_dcdc: unexpected end of section
--- drivers/regulator/rk808-regulator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/rk808-regulator.c +2 -2
@@ -270,8 +270,8 @@ static const unsigned int rk817_buck1_4_ramp_table[] = {static int rk806_set_mode_dcdc (struct regulator_dev *rdev,unsigned int mode) { -int rid =rdev_get_id (rdev); -int ctr_bit, reg; +unsigned int rid =rdev_get_id (rdev); +unsigned int ctr_bit, reg; reg =RK806_POWER_FPWM_EN0 + rid /8 ; ctr_bit = rid %8 ;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 28/28 objtool, lkdtm: Obfuscate the do_nothing() pointer
In reply to Sasha LevinFrom: Josh Poimboeuf <[email protected]>
[ Upstream commit 05026ea01e95ffdeb0e5ac8fb7fb1b551e3a8726 ]
If execute_location()'s memcpy of do_nothing() gets inlined and unrolled by the compiler, it copies one word at a time:
mov 0x0(%rip),%rax R_X86_64_PC32 .text+0x1374
mov %rax,0x38(%rbx)
mov 0x0(%rip),%rax R_X86_64_PC32 .text+0x136c
mov %rax,0x30(%rbx)
...Those .text references point to the middle of the function, causing objtool to complain about their lack of ENDBR.
Prevent that by resolving the function pointer at runtime rather than build time. This fixes the following warning:
drivers/misc/lkdtm/lkdtm.o: warning: objtool: execute_location+0x23: relocation to !ENDBR: .text+0x1378
--- drivers/misc/lkdtm/perms.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/misc/lkdtm/perms.c +11 -3
@@ -28,6 +28,13 @@ static const unsigned long rodata = 0xAA55AA55;/* This is marked __ro_after_init, so it should ultimately be .rodata. */ static unsigned long ro_after_init__ro_after_init =0x55AA5500 ; +/* +* This is a pointer to do_nothing() which is initialized at runtime rather +* than build time to avoid objtool IBT validation warnings caused by an +* inlined unrolled memcpy() in execute_location(). +*/ +static void __ro_after_init *do_nothing_ptr; +/* * This just returns to the caller. It is designed to be copied into * non-executable memory regions.
@@ -65,13 +72,12 @@ static noinline __nocfi void execute_location(void *dst, bool write) {void (*func)(void );func_desc_t fdesc; -void *do_nothing_text =dereference_function_descriptor (do_nothing); -pr_info ("attempting ok execution at %px\n" , do_nothing_text); +pr_info ("attempting ok execution at %px\n" , do_nothing_ptr);do_nothing ();if (write ==CODE_WRITE ) { -memcpy (dst, do_nothing_text,EXEC_SIZE ); +memcpy (dst, do_nothing_ptr,EXEC_SIZE );flush_icache_range ((unsigned long )dst, (unsigned long )dst +EXEC_SIZE ); }
@@ -267,6 +273,8 @@ static void lkdtm_ACCESS_NULL(void)void __init lkdtm_perms_init (void ) { + do_nothing_ptr =dereference_function_descriptor (do_nothing); +/* Make sure we can write to __ro_after_init values during __init */ ro_after_init |=0xAA ; }
Signature · 1 line
2.39.5