drm/amdgpu: fix and cleanup amdgpu_gem_object_close v4
Subsystems (36)
Sasha Levin
maintainerPATCH 151/175 xfs: gut error handling in xfs_trans_unreserve_and_mod_sb()
In reply to Sasha LevinFrom: Dave Chinner <[email protected]>
[ Upstream commit dc3ffbb14060c943469d5e12900db3a60bc3fa64 ]
xfs: gut error handling in xfs_trans_unreserve_and_mod_sb()
From: Dave Chinner <[email protected]>
The error handling in xfs_trans_unreserve_and_mod_sb() is largely incorrect - rolling back the changes in the transaction if only one counter underruns makes all the other counters incorrect. We still allow the change to proceed and committing the transaction, except now we have multiple incorrect counters instead of a single underflow.
Further, we don't actually report the error to the caller, so this is completely silent except on debug kernels that will assert on failure before we even get to the rollback code. Hence this error handling is broken, untested, and largely unnecessary complexity.
Just remove it.
--- fs/xfs/xfs_trans.c | 163 ++++++--------------------------------------- 1 file changed, 20 insertions(+), 143 deletions(-)
fs/xfs/xfs_trans.c +20 -143
@@ -527,57 +527,9 @@ xfs_trans_apply_sb_deltas( sizeof(sbp->sb_frextents) - 1); } -STATIC int -xfs_sb_mod8 ( -uint8_t *field, -int8_t delta) -{ -int8_t counter = *field; - - counter += delta; -if (counter <0 ) { -ASSERT (0 ); -return -EINVAL ; - } - *field = counter; -return 0 ; -} - -STATIC int -xfs_sb_mod32 ( -uint32_t *field, -int32_t delta) -{ -int32_t counter = *field; - - counter += delta; -if (counter <0 ) { -ASSERT (0 ); -return -EINVAL ; - } - *field = counter; -return 0 ; -} - -STATIC int -xfs_sb_mod64 ( -uint64_t *field, -int64_t delta) -{ -int64_t counter = *field; - - counter += delta; -if (counter <0 ) { -ASSERT (0 ); -return -EINVAL ; - } - *field = counter; -return 0 ; -} -/* -* xfs_trans_unreserve_and_mod_sb() is called to release unused reservations -* and apply superblock counter changes to the in-core superblock. The +* xfs_trans_unreserve_and_mod_sb() is called to release unused reservations and +* apply superblock counter changes to the in-core superblock. The * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT * applied to the in-core superblock. The idea is that that has already been * done.
@@ -622,20 +574,17 @@ xfs_trans_unreserve_and_mod_sb(/* apply the per-cpu counters */ if (blkdelta) { error =xfs_mod_fdblocks (mp, blkdelta, rsvd); -if (error) - goto out; +ASSERT (!error); }if (idelta) { error =xfs_mod_icount (mp, idelta); -if (error) - goto out_undo_fdblocks; +ASSERT (!error); }if (ifreedelta) { error =xfs_mod_ifree (mp, ifreedelta); -if (error) - goto out_undo_icount; +ASSERT (!error); }if (rtxdelta ==0 && !(tp->t_flags &XFS_TRANS_SB_DIRTY ))
@@ -643,95 +592,23 @@ xfs_trans_unreserve_and_mod_sb(/* apply remaining deltas */ spin_lock (&mp->m_sb_lock); -if (rtxdelta) { - error =xfs_sb_mod64 (&mp->m_sb.sb_frextents, rtxdelta); -if (error) - goto out_undo_ifree; - } - -if (tp->t_dblocks_delta !=0 ) { - error =xfs_sb_mod64 (&mp->m_sb.sb_dblocks, tp->t_dblocks_delta); -if (error) - goto out_undo_frextents; - } -if (tp->t_agcount_delta !=0 ) { - error =xfs_sb_mod32 (&mp->m_sb.sb_agcount, tp->t_agcount_delta); -if (error) - goto out_undo_dblocks; - } -if (tp->t_imaxpct_delta !=0 ) { - error =xfs_sb_mod8 (&mp->m_sb.sb_imax_pct, tp->t_imaxpct_delta); -if (error) - goto out_undo_agcount; - } -if (tp->t_rextsize_delta !=0 ) { - error =xfs_sb_mod32 (&mp->m_sb.sb_rextsize, - tp->t_rextsize_delta); -if (error) - goto out_undo_imaxpct; - } -if (tp->t_rbmblocks_delta !=0 ) { - error =xfs_sb_mod32 (&mp->m_sb.sb_rbmblocks, - tp->t_rbmblocks_delta); -if (error) - goto out_undo_rextsize; - } -if (tp->t_rblocks_delta !=0 ) { - error =xfs_sb_mod64 (&mp->m_sb.sb_rblocks, tp->t_rblocks_delta); -if (error) - goto out_undo_rbmblocks; - } -if (tp->t_rextents_delta !=0 ) { - error =xfs_sb_mod64 (&mp->m_sb.sb_rextents, - tp->t_rextents_delta); -if (error) - goto out_undo_rblocks; - } -if (tp->t_rextslog_delta !=0 ) { - error =xfs_sb_mod8 (&mp->m_sb.sb_rextslog, - tp->t_rextslog_delta); -if (error) - goto out_undo_rextents; - } + mp->m_sb.sb_frextents += rtxdelta; + mp->m_sb.sb_dblocks += tp->t_dblocks_delta; + mp->m_sb.sb_agcount += tp->t_agcount_delta; + mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta; + mp->m_sb.sb_rextsize += tp->t_rextsize_delta; + mp->m_sb.sb_rbmblocks += tp->t_rbmblocks_delta; + mp->m_sb.sb_rblocks += tp->t_rblocks_delta; + mp->m_sb.sb_rextents += tp->t_rextents_delta; + mp->m_sb.sb_rextslog += tp->t_rextslog_delta;spin_unlock (&mp->m_sb_lock); -return ; -out_undo_rextents: -if (tp->t_rextents_delta) -xfs_sb_mod64 (&mp->m_sb.sb_rextents, -tp->t_rextents_delta); -out_undo_rblocks: -if (tp->t_rblocks_delta) -xfs_sb_mod64 (&mp->m_sb.sb_rblocks, -tp->t_rblocks_delta); -out_undo_rbmblocks: -if (tp->t_rbmblocks_delta) -xfs_sb_mod32 (&mp->m_sb.sb_rbmblocks, -tp->t_rbmblocks_delta); -out_undo_rextsize: -if (tp->t_rextsize_delta) -xfs_sb_mod32 (&mp->m_sb.sb_rextsize, -tp->t_rextsize_delta); -out_undo_imaxpct: -if (tp->t_rextsize_delta) -xfs_sb_mod8 (&mp->m_sb.sb_imax_pct, -tp->t_imaxpct_delta); -out_undo_agcount: -if (tp->t_agcount_delta) -xfs_sb_mod32 (&mp->m_sb.sb_agcount, -tp->t_agcount_delta); -out_undo_dblocks: -if (tp->t_dblocks_delta) -xfs_sb_mod64 (&mp->m_sb.sb_dblocks, -tp->t_dblocks_delta); -out_undo_frextents: -if (rtxdelta) -xfs_sb_mod64 (&mp->m_sb.sb_frextents, -rtxdelta); -out_undo_ifree: -spin_unlock (&mp->m_sb_lock); -if (ifreedelta) -xfs_mod_ifree (mp, -ifreedelta); -out_undo_icount: -if (idelta) -xfs_mod_icount (mp, -idelta); -out_undo_fdblocks: -if (blkdelta) -xfs_mod_fdblocks (mp, -blkdelta, rsvd); -out: -ASSERT (error ==0 ); +/* +* Debug checks outside of the spinlock so they don't lock up the +* machine if they fail. +*/ +ASSERT (mp->m_sb.sb_imax_pct >=0 ); +ASSERT (mp->m_sb.sb_rextslog >=0 );return ; }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 152/175 xfs: measure all contiguous previous extents for prealloc size
In reply to Sasha LevinFrom: "Darrick J. Wong" <[email protected]>
[ Upstream commit f0322c7cc05eb23ef034775f9b39254cbd4f3678 ]
When we're estimating a new speculative preallocation length for an extending write, we should walk backwards through the extent list to determine the number of number of blocks that are physically and logically contiguous with the write offset, and use that as an input to the preallocation size computation.
This way, preallocation length is truly measured by the effectiveness of the allocator in giving us contiguous allocations without being influenced by the state of a given extent. This fixes both the problem where ZERO_RANGE within an EOF can reduce preallocation, and prevents the unnecessary shrinkage of preallocation when delalloc extents are turned into unwritten extents.
This was found as a regression in xfs/014 after changing delalloc writes to create unwritten extents during writeback.
--- fs/xfs/xfs_iomap.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
fs/xfs/xfs_iomap.c +27 -13
@@ -397,15 +397,17 @@ xfs_iomap_prealloc_size(loff_t count, struct xfs_iext_cursor *icur) { + struct xfs_iext_cursor ncur = *icur; +struct xfs_bmbt_irec prev, got;struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);xfs_fileoff_t offset_fsb =XFS_B_TO_FSBT (mp, offset); -struct xfs_bmbt_irec prev; -int shift =0 ;int64_t freesp;xfs_fsblock_t qblocks; -int qshift =0 ;xfs_fsblock_t alloc_blocks =0 ; +xfs_extlen_t plen; +int shift =0 ; +int qshift =0 ;if (offset + count <=XFS_ISIZE (ip))return 0 ;
@@ -420,7 +422,7 @@ xfs_iomap_prealloc_size(*/ if ((mp->m_flags &XFS_MOUNT_DFLT_IOSIZE ) ||XFS_ISIZE (ip) <XFS_FSB_TO_B (mp, mp->m_dalign) || - !xfs_iext_peek_prev_extent (ifp, icur, &prev) || + !xfs_iext_prev_extent (ifp, &ncur, &prev) || prev.br_startoff + prev.br_blockcount < offset_fsb)return mp->m_writeio_blocks;
@@ -433,16 +435,28 @@ xfs_iomap_prealloc_size(* preallocation size. * * If the extent is a hole, then preallocation is essentially disabled. -* Otherwise we take the size of the preceding data extent as the basis -* for the preallocation size. If the size of the extent is greater than -* half the maximum extent length, then use the current offset as the -* basis. This ensures that for large files the preallocation size -* always extends to MAXEXTLEN rather than falling short due to things -* like stripe unit/width alignment of real extents. +* Otherwise we take the size of the preceding data extents as the basis +* for the preallocation size. Note that we don't care if the previous +* extents are written or not. +* +* If the size of the extents is greater than half the maximum extent +* length, then use the current offset as the basis. This ensures that +* for large files the preallocation size always extends to MAXEXTLEN +* rather than falling short due to things like stripe unit/width +* alignment of real extents. */ -if (prev.br_blockcount <= (MAXEXTLEN >>1 )) - alloc_blocks = prev.br_blockcount <<1 ; -else + plen = prev.br_blockcount; +while (xfs_iext_prev_extent (ifp, &ncur, &got)) { +if (plen >MAXEXTLEN /2 || +isnullstartblock (got.br_startblock) || + got.br_startoff + got.br_blockcount != prev.br_startoff || + got.br_startblock + got.br_blockcount != prev.br_startblock) +break ; + plen += got.br_blockcount; + prev = got; + } + alloc_blocks = plen *2 ; +if (alloc_blocks >MAXEXTLEN ) alloc_blocks =XFS_B_TO_FSB (mp, offset);if (!alloc_blocks) goto check_writeio;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 153/175 xfs: force writes to delalloc regions to unwritten
In reply to Sasha LevinFrom: "Darrick J. Wong" <[email protected]>
[ Upstream commit a5949d3faedf492fa7863b914da408047ab46eb0 ]
When writing to a delalloc region in the data fork, commit the new allocations (of the da reservation) as unwritten so that the mappings are only marked written once writeback completes successfully. This fixes the problem of stale data exposure if the system goes down during targeted writeback of a specific region of a file, as tested by generic/042.
--- fs/xfs/libxfs/xfs_bmap.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +17 -12
@@ -4090,17 +4090,7 @@ xfs_bmapi_allocate( bma->got.br_blockcount = bma->length; bma->got.br_state =XFS_EXT_NORM ; -/* -* In the data fork, a wasdelay extent has been initialized, so -* shouldn't be flagged as unwritten. -* -* For the cow fork, however, we convert delalloc reservations -* (extents allocated for speculative preallocation) to -* allocated unwritten extents, and only convert the unwritten -* extents to real extents when we're about to write the data. -*/ -if ((!bma->wasdel || (bma->flags &XFS_BMAPI_COWFORK )) && - (bma->flags &XFS_BMAPI_PREALLOC )) +if (bma->flags &XFS_BMAPI_PREALLOC ) bma->got.br_state =XFS_EXT_UNWRITTEN ;if (bma->wasdel)
@@ -4507,8 +4497,23 @@ xfs_bmapi_convert_delalloc( bma.length =max_t (xfs_filblks_t, bma.got.br_blockcount,MAXEXTLEN ); bma.total =XFS_EXTENTADD_SPACE_RES (ip->i_mount,XFS_DATA_FORK ); bma.minleft =xfs_bmapi_minleft (tp, ip, whichfork); + +/* +* When we're converting the delalloc reservations backing dirty pages +* in the page cache, we must be careful about how we create the new +* extents: +* +* New CoW fork extents are created unwritten, turned into real extents +* when we're about to write the data to disk, and mapped into the data +* fork after the write finishes. End of story. +* +* New data fork extents must be mapped in as unwritten and converted +* to real extents after the write succeeds to avoid exposing stale +* disk contents if we crash. +*/ + bma.flags =XFS_BMAPI_PREALLOC ;if (whichfork ==XFS_COW_FORK ) - bma.flags =XFS_BMAPI_COWFORK |XFS_BMAPI_PREALLOC ; + bma.flags |=XFS_BMAPI_COWFORK ;if (!xfs_iext_peek_prev_extent (ifp, &bma.icur, &bma.prev)) bma.prev.br_startoff =NULLFILEOFF ;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 154/175 mmc: sdhci-msm: Set SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 quirk
In reply to Sasha LevinFrom: Veerabhadrarao Badiganti <[email protected]>
[ Upstream commit d863cb03fb2aac07f017b2a1d923cdbc35021280 ]
sdhci-msm can support auto cmd12.
So enable SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 quirk.
--- drivers/mmc/host/sdhci-msm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-msm.c +3 -1
@@ -1736,7 +1736,9 @@ static const struct sdhci_ops sdhci_msm_ops = {static const struct sdhci_pltfm_data sdhci_msm_pdata = { .quirks =SDHCI_QUIRK_BROKEN_CARD_DETECTION |SDHCI_QUIRK_SINGLE_POWER_WRITE | -SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN , +SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN | +SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 , + .quirks2 =SDHCI_QUIRK2_PRESET_VALUE_BROKEN , .ops = &sdhci_msm_ops, };
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 155/175 staging: greybus: sdio: Respect the cmd->busy_timeout from the mmc core
In reply to Sasha LevinFrom: Ulf Hansson <[email protected]>
[ Upstream commit a389087ee9f195fcf2f31cd771e9ec5f02c16650 ]
Using a fixed 1s timeout for all commands is a bit problematic.
For some commands it means waiting longer than needed for the timeout to expire, which may not a big issue, but still. For other commands, like for an erase (CMD38) that uses a R1B response, may require longer timeouts than 1s. In these cases, we may end up treating the command as it failed, while it just needed some more time to complete successfully.
Fix the problem by respecting the cmd->busy_timeout, which is provided by the mmc core.
--- drivers/staging/greybus/sdio.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/staging/greybus/sdio.c +7 -3
@@ -411,6 +411,7 @@ static int gb_sdio_command(struct gb_sdio_host *host, struct mmc_command *cmd)struct gb_sdio_command_request request = {0 };struct gb_sdio_command_response response;struct mmc_data *data = host->mrq->data; +unsigned int timeout_ms;u8 cmd_flags;u8 cmd_type;int i;
@@ -469,9 +470,12 @@ static int gb_sdio_command(struct gb_sdio_host *host, struct mmc_command *cmd) request.data_blksz =cpu_to_le16 (data->blksz); } - ret =gb_operation_sync (host->connection,GB_SDIO_TYPE_COMMAND , - &request,sizeof (request), &response, -sizeof (response)); + timeout_ms = cmd->busy_timeout ? cmd->busy_timeout : +GB_OPERATION_TIMEOUT_DEFAULT ; + + ret =gb_operation_sync_timeout (host->connection,GB_SDIO_TYPE_COMMAND , + &request,sizeof (request), &response, +sizeof (response), timeout_ms);if (ret <0 ) goto out;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 156/175 mmc: via-sdmmc: Respect the cmd->busy_timeout from the mmc core
In reply to Sasha LevinFrom: Ulf Hansson <[email protected]>
[ Upstream commit 966244ccd2919e28f25555a77f204cd1c109cad8 ]
Using a fixed 1s timeout for all commands (and data transfers) is a bit problematic.
For some commands it means waiting longer than needed for the timer to expire, which may not a big issue, but still. For other commands, like for an erase (CMD38) that uses a R1B response, may require longer timeouts than 1s. In these cases, we may end up treating the command as it failed, while it just needed some more time to complete successfully.
Fix the problem by respecting the cmd->busy_timeout, which is provided by the mmc core.
--- drivers/mmc/host/via-sdmmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mmc/host/via-sdmmc.c +6 -1
@@ -319,6 +319,8 @@ struct via_crdr_mmc_host {/* some devices need a very long delay for power to stabilize */ #define VIA_CRDR_QUIRK_300MS_PWRDELAY 0x0001 +#define VIA_CMD_TIMEOUT_MS 1000 +static const struct pci_device_id via_ids[] = { {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_9530 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,0 ,},
@@ -551,14 +553,17 @@ static void via_sdc_send_command(struct via_crdr_mmc_host *host, {void __iomem *addrbase;struct mmc_data *data; +unsigned int timeout_ms;u32 cmdctrl =0 ;WARN_ON (host->cmd); data = cmd->data; -mod_timer (&host->timer, jiffies +HZ ); host->cmd = cmd; + timeout_ms = cmd->busy_timeout ? cmd->busy_timeout :VIA_CMD_TIMEOUT_MS ; +mod_timer (&host->timer, jiffies +msecs_to_jiffies (timeout_ms)); +/*Command index*/ cmdctrl = cmd->opcode <<8 ;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 157/175 ice: fix potential double free in probe unrolling
In reply to Sasha LevinFrom: Jacob Keller <[email protected]>
[ Upstream commit bc3a024101ca497bea4c69be4054c32a5c349f1d ]
If ice_init_interrupt_scheme fails, ice_probe will jump to clearing up the interrupts. This can lead to some static analysis tools such as the compiler sanitizers complaining about double free problems.
Since ice_init_interrupt_scheme already unrolls internally on failure, there is no need to call ice_clear_interrupt_scheme when it fails. Add a new unroll label and use that instead.
--- drivers/net/ethernet/intel/ice/ice_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_main.c +2 -1
@@ -2900,7 +2900,7 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)if (err) {dev_err (dev,"ice_init_interrupt_scheme failed: %d\n" , err); err = -EIO ; - goto err_init_interrupt_unroll; + goto err_init_vsi_unroll; }/* Driver is mostly up */
@@ -2986,6 +2986,7 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)ice_free_irq_msix_misc (pf); err_init_interrupt_unroll:ice_clear_interrupt_scheme (pf); +err_init_vsi_unroll:devm_kfree (dev, pf->vsi); err_init_pf_unroll:ice_deinit_pf (pf);
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 158/175 ixgbe: fix signed-integer-overflow warning
In reply to Sasha LevinFrom: Xie XiuQi <[email protected]>
[ Upstream commit 3b70683fc4d68f5d915d9dc7e5ba72c732c7315c ]
ubsan report this warning, fix it by adding a unsigned suffix.
UBSAN: signed-integer-overflow in drivers/net/ethernet/intel/ixgbe/ixgbe_common.c:2246:26 65535 * 65537 cannot be represented in type 'int' CPU: 21 PID: 7 Comm: kworker/u256:0 Not tainted 5.7.0-rc3-debug+ #39 Hardware name: Huawei TaiShan 2280 V2/BC82AMDC, BIOS 2280-V2 03/27/2020 Workqueue: ixgbe ixgbe_service_task [ixgbe] Call trace: dump_backtrace+0x0/0x3f0 show_stack+0x28/0x38 dump_stack+0x154/0x1e4 ubsan_epilogue+0x18/0x60 handle_overflow+0xf8/0x148 __ubsan_handle_mul_overflow+0x34/0x48 ixgbe_fc_enable_generic+0x4d0/0x590 [ixgbe] ixgbe_service_task+0xc20/0x1f78 [ixgbe] process_one_work+0x8f0/0xf18 worker_thread+0x430/0x6d0 kthread+0x218/0x238 ret_from_fork+0x10/0x18
--- drivers/net/ethernet/intel/ixgbe/ixgbe_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_common.c +1 -1
@@ -2243,7 +2243,7 @@ s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw) }/* Configure pause time (2 TCs per register) */ - reg = hw->fc.pause_time *0x00010001 ; + reg = hw->fc.pause_time *0x00010001U ;for (i =0 ; i < (MAX_TRAFFIC_CLASS /2 ); i++)IXGBE_WRITE_REG (hw,IXGBE_FCTTV (i), reg);
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 159/175 iwlwifi: mvm: fix aux station leak
In reply to Sasha LevinFrom: Sharon <[email protected]>
[ Upstream commit f327236df2afc8c3c711e7e070f122c26974f4da ]
When mvm is initialized we alloc aux station with aux queue. We later free the station memory when driver is stopped, but we never free the queue's memory, which casues a leak.
Add a proper de-initialization of the station.
--- .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 5 ++--- drivers/net/wireless/intel/iwlwifi/mvm/sta.c | 18 +++++++++++++----- drivers/net/wireless/intel/iwlwifi/mvm/sta.h | 6 +++--- 3 files changed, 18 insertions(+), 11 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +2 -3
@@ -1193,14 +1193,13 @@ void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)*/ flush_work (&mvm->roc_done_wk); +iwl_mvm_rm_aux_sta (mvm); +iwl_mvm_stop_device (mvm);iwl_mvm_async_handlers_purge (mvm);/* async_handlers_list is empty and will stay empty: HW is stopped */ -/* the fw is stopped, the aux sta is dead: clean up driver state */ -iwl_mvm_del_aux_sta (mvm); -/* * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the * hw (as restart_complete() won't be called in this case) and mac80211
drivers/net/wireless/intel/iwlwifi/mvm/sta.c +13 -5
@@ -2080,16 +2080,24 @@ int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)return ret; } -void iwl_mvm_dealloc_snif_sta (struct iwl_mvm *mvm) +int iwl_mvm_rm_aux_sta (struct iwl_mvm *mvm) { -iwl_mvm_dealloc_int_sta (mvm, &mvm->snif_sta); -} +int ret; -void iwl_mvm_del_aux_sta (struct iwl_mvm *mvm) -{lockdep_assert_held (&mvm->mutex); +iwl_mvm_disable_txq (mvm,NULL , mvm->aux_queue,IWL_MAX_TID_COUNT ,0 ); + ret =iwl_mvm_rm_sta_common (mvm, mvm->aux_sta.sta_id); +if (ret) +IWL_WARN (mvm,"Failed sending remove station\n" );iwl_mvm_dealloc_int_sta (mvm, &mvm->aux_sta); + +return ret; +} + +void iwl_mvm_dealloc_snif_sta (struct iwl_mvm *mvm) +{ +iwl_mvm_dealloc_int_sta (mvm, &mvm->snif_sta); }/*
drivers/net/wireless/intel/iwlwifi/mvm/sta.h +3 -3
@@ -8,7 +8,7 @@* Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH * Copyright(c) 2015 - 2016 Intel Deutschland GmbH -* Copyright(c) 2018 - 2019 Intel Corporation +* Copyright(c) 2018 - 2020 Intel Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as
@@ -31,7 +31,7 @@* Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH * Copyright(c) 2015 - 2016 Intel Deutschland GmbH -* Copyright(c) 2018 - 2019 Intel Corporation +* Copyright(c) 2018 - 2020 Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -541,7 +541,7 @@ int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, int tid, u8 queue, bool start);int iwl_mvm_add_aux_sta (struct iwl_mvm *mvm); -void iwl_mvm_del_aux_sta (struct iwl_mvm *mvm); +int iwl_mvm_rm_aux_sta (struct iwl_mvm *mvm);int iwl_mvm_alloc_bcast_sta (struct iwl_mvm *mvm,struct ieee80211_vif *vif);int iwl_mvm_send_add_bcast_sta (struct iwl_mvm *mvm,struct ieee80211_vif *vif);
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 160/175 mmc: sdhci-esdhc-imx: fix the mask for tuning start point
In reply to Sasha LevinFrom: Haibo Chen <[email protected]>
[ Upstream commit 1194be8c949b8190b2882ad8335a5d98aa50c735 ]
According the RM, the bit[6~0] of register ESDHC_TUNING_CTRL is TUNING_START_TAP, bit[7] of this register is to disable the command CRC check for standard tuning. So fix it here.
--- drivers/mmc/host/sdhci-esdhc-imx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +1 -1
@@ -87,7 +87,7 @@#define ESDHC_STD_TUNING_EN (1 << 24)/* NOTE: the minimum valid tuning start tap for mx6sl is 1 */ #define ESDHC_TUNING_START_TAP_DEFAULT 0x1 -#define ESDHC_TUNING_START_TAP_MASK 0xff +#define ESDHC_TUNING_START_TAP_MASK 0x7f#define ESDHC_TUNING_STEP_MASK 0x00070000#define ESDHC_TUNING_STEP_SHIFT 16
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 161/175 spi: dw: Return any value retrieved from the dma_transfer callback
In reply to Sasha LevinFrom: Serge Semin <[email protected]>
[ Upstream commit f0410bbf7d0fb80149e3b17d11d31f5b5197873e ]
DW APB SSI DMA-part of the driver may need to perform the requested SPI-transfer synchronously. In that case the dma_transfer() callback will return 0 as a marker of the SPI transfer being finished so the SPI core doesn't need to wait and may proceed with the SPI message trasnfers pumping procedure. This will be needed to fix the problem when DMA transactions are finished, but there is still data left in the SPI Tx/Rx FIFOs being sent/received. But for now make dma_transfer to return 1 as the normal dw_spi_transfer_one() method.
--- drivers/spi/spi-dw-mid.c | 2 +- drivers/spi/spi-dw.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/spi/spi-dw-mid.c +1 -1
@@ -266,7 +266,7 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, struct spi_transfer *xfer)dma_async_issue_pending (dws->txchan); } -return 0 ; +return 1 ; }static void mid_spi_dma_stop (struct dw_spi *dws)
drivers/spi/spi-dw.c +2 -5
@@ -370,11 +370,8 @@ static int dw_spi_transfer_one(struct spi_controller *master,spi_enable_chip (dws,1 ); -if (dws->dma_mapped) { - ret = dws->dma_ops->dma_transfer (dws, transfer); -if (ret <0 ) -return ret; - } +if (dws->dma_mapped) +return dws->dma_ops->dma_transfer (dws, transfer);if (chip->poll_mode)return poll_transfer (dws);
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 162/175 cpuidle: Fix three reference count leaks
In reply to Sasha LevinFrom: Qiushi Wu <[email protected]>
[ Upstream commit c343bf1ba5efcbf2266a1fe3baefec9cc82f867f ]
kobject_init_and_add() takes reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object.
Previous commit "b8eb718348b8" fixed a similar problem.
--- drivers/cpuidle/sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpuidle/sysfs.c +3 -3
@@ -480,7 +480,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device) ret =kobject_init_and_add (&kobj->kobj, &ktype_state_cpuidle, &kdev->kobj,"state%d" , i);if (ret) { -kfree (kobj); +kobject_put (&kobj->kobj); goto error_state; }cpuidle_add_s2idle_attr_group (kobj);
@@ -611,7 +611,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev) ret =kobject_init_and_add (&kdrv->kobj, &ktype_driver_cpuidle, &kdev->kobj,"driver" );if (ret) { -kfree (kdrv); +kobject_put (&kdrv->kobj);return ret; }
@@ -705,7 +705,7 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev) error =kobject_init_and_add (&kdev->kobj, &ktype_cpuidle, &cpu_dev->kobj,"cpuidle" );if (error) { -kfree (kdev); +kobject_put (&kdev->kobj);return error; }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 163/175 platform/x86: hp-wmi: Convert simple_strtoul() to kstrtou32()
In reply to Sasha LevinFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 5cdc45ed3948042f0d73c6fec5ee9b59e637d0d2 ]
First of all, unsigned long can overflow u32 value on 64-bit machine. Second, simple_strtoul() doesn't check for overflow in the input.
Convert simple_strtoul() to kstrtou32() to eliminate above issues.
--- drivers/platform/x86/hp-wmi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/platform/x86/hp-wmi.c +8 -2
@@ -461,8 +461,14 @@ static ssize_t postcode_show(struct device *dev, struct device_attribute *attr,static ssize_t als_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) { -u32 tmp =simple_strtoul (buf,NULL ,10 ); -int ret =hp_wmi_perform_query (HPWMI_ALS_QUERY ,HPWMI_WRITE , &tmp, +u32 tmp; +int ret; + + ret =kstrtou32 (buf,10 , &tmp); +if (ret) +return ret; + + ret =hp_wmi_perform_query (HPWMI_ALS_QUERY ,HPWMI_WRITE , &tmp,sizeof (tmp),sizeof (tmp));if (ret)return ret <0 ? ret : -EINVAL ;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 164/175 platform/x86: intel-hid: Add a quirk to support HP Spectre X2 (2015)
In reply to Sasha LevinFrom: Nickolai Kozachenko <[email protected]>
[ Upstream commit 8fe63eb757ac6e661a384cc760792080bdc738dc ]
HEBC method reports capabilities of 5 button array but HP Spectre X2 (2015) does not have this control method (the same was for Wacom MobileStudio Pro). Expand previous DMI quirk by Alex Hung to also enable 5 button array for this system.
--- drivers/platform/x86/intel-hid.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/platform/x86/intel-hid.c +7 -0
@@ -77,6 +77,13 @@ static const struct dmi_system_id button_array_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Wacom MobileStudio Pro 16"), }, }, + { + .ident = "HP Spectre x2 (2015)", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x2 Detachable"), + }, + }, { } };
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 165/175 platform/x86: intel-vbtn: Only blacklist SW_TABLET_MODE on the 9 / "Laptop" chasis-type
In reply to Sasha LevinFrom: Hans de Goede <[email protected]>
[ Upstream commit cfae58ed681c5fe0185db843013ecc71cd265ebf ]
The HP Stream x360 11-p000nd no longer report SW_TABLET_MODE state / events with recent kernels. This model reports a chassis-type of 10 / "Notebook" which is not on the recently introduced chassis-type whitelist
Commit de9647efeaa9 ("platform/x86: intel-vbtn: Only activate tablet mode switch on 2-in-1's") added a chassis-type whitelist and only listed 31 / "Convertible" as being capable of generating valid SW_TABLET_MOD events.
Commit 1fac39fd0316 ("platform/x86: intel-vbtn: Also handle tablet-mode switch on "Detachable" and "Portable" chassis-types") extended the whitelist with chassis-types 8 / "Portable" and 32 / "Detachable".
And now we need to exten the whitelist again with 10 / "Notebook"...
The issue original fixed by the whitelist is really a ACPI DSDT bug on the Dell XPS 9360 where it has a VGBS which reports it is in tablet mode even though it is not a 2-in-1 at all, but a regular laptop.
So since this is a workaround for a DSDT issue on that specific model, instead of extending the whitelist over and over again, lets switch to a blacklist and only blacklist the chassis-type of the model for which the chassis-type check was added.
Note this also fixes the current version of the code no longer checking if dmi_get_system_info(DMI_CHASSIS_TYPE) returns NULL.
--- drivers/platform/x86/intel-vbtn.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/platform/x86/intel-vbtn.c +8 -11
@@ -157,21 +157,18 @@ static void detect_tablet_mode(struct platform_device *device)static bool intel_vbtn_has_switches (acpi_handle handle) {const char *chassis_type =dmi_get_system_info (DMI_CHASSIS_TYPE ); -unsigned long chassis_type_int;unsigned long long vgbs;acpi_status status; -if (kstrtoul (chassis_type,10 , &chassis_type_int)) -return false; - -switch (chassis_type_int) { -case 8 :/* Portable */ -case 31 :/* Convertible */ -case 32 :/* Detachable */ -break ; -default : +/* +* Some normal laptops have a VGBS method despite being non-convertible +* and their VGBS method always returns 0, causing detect_tablet_mode() +* to report SW_TABLET_MODE=1 to userspace, which causes issues. +* These laptops have a DMI chassis_type of 9 ("Laptop"), do not report +* switches on any devices with a DMI chassis_type of 9. +*/ +if (chassis_type &&strcmp (chassis_type,"9" ) ==0 )return false; - } status =acpi_evaluate_integer (handle,"VGBS" ,NULL , &vgbs);return ACPI_SUCCESS (status);
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 166/175 platform/x86: asus_wmi: Reserve more space for struct bias_args
In reply to Sasha LevinFrom: Chris Chiu <[email protected]>
[ Upstream commit 7b91f1565fbfbe5a162d91f8a1f6c5580c2fc1d0 ]
On the ASUS laptop UX325JA/UX425JA, most of the media keys are not
working due to the ASUS WMI driver fails to be loaded. The ACPI error
as follows leads to the failure of asus_wmi_evaluate_method.
ACPI BIOS Error (bug): AE_AML_BUFFER_LIMIT, Field [IIA3] at bit offset/length 96/32 exceeds size of target Buffer (96 bits) (20200326/dsopcode-203) No Local Variables are initialized for Method [WMNB]
ACPI Error: Aborting method \_SB.ATKD.WMNB due to previous error (AE_AML_BUFFER_LIMIT) (20200326/psparse-531)
The DSDT for the WMNB part shows that 5 DWORD required for local variables and the 3rd variable IIA3 hit the buffer limit.
Method (WMNB, 3, Serialized)
{ ..
CreateDWordField (Arg2, Zero, IIA0)
CreateDWordField (Arg2, 0x04, IIA1)
CreateDWordField (Arg2, 0x08, IIA2)
CreateDWordField (Arg2, 0x0C, IIA3)
CreateDWordField (Arg2, 0x10, IIA4)
Local0 = (Arg1 & 0xFFFFFFFF)
If ((Local0 == 0x54494E49)) ..
}
The limitation is determined by the input acpi_buffer size passed to the wmi_evaluate_method. Since the struct bios_args is the data structure used as input buffer by default for all ASUS WMI calls, the size needs to be expanded to fix the problem.
--- drivers/platform/x86/asus-wmi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/platform/x86/asus-wmi.c +2 -0
@@ -111,6 +111,8 @@ struct bios_args {u32 arg0;u32 arg1;u32 arg2;/* At least TUF Gaming series uses 3 dword input buffer. */ +u32 arg4; +u32 arg5; } __packed;/*
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 167/175 vxlan: Avoid infinite loop when suppressing NS messages with invalid options
In reply to Sasha LevinFrom: Ido Schimmel <[email protected]>
[ Upstream commit 8066e6b449e050675df48e7c4b16c29f00507ff0 ]
When proxy mode is enabled the vxlan device might reply to Neighbor Solicitation (NS) messages on behalf of remote hosts.
In case the NS message includes the "Source link-layer address" option [1], the vxlan device will use the specified address as the link-layer destination address in its reply.
To avoid an infinite loop, break out of the options parsing loop when encountering an option with length zero and disregard the NS message.
This is consistent with the IPv6 ndisc code and RFC 4886 which states that "Nodes MUST silently discard an ND packet that contains an option with length zero" [2].
[1] https://tools.ietf.org/html/rfc4861#section-4.3
[2] https://tools.ietf.org/html/rfc4861#section-4.6
--- drivers/net/vxlan.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/vxlan.c +4 -0
@@ -1924,6 +1924,10 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, ns_olen = request->len -skb_network_offset (request) -sizeof (struct ipv6hdr ) -sizeof (*ns);for (i =0 ; i < ns_olen-1 ; i += (ns->opt[i+1 ]<<3 )) { +if (!ns->opt[i +1 ]) { +kfree_skb (reply); +return NULL ; + }if (ns->opt[i] ==ND_OPT_SOURCE_LL_ADDR ) { daddr = ns->opt + i +sizeof (struct nd_opt_hdr );break ;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 168/175 libbpf: Fix perf_buffer__free() API for sparse allocs
In reply to Sasha LevinFrom: Eelco Chaudron <[email protected]>
[ Upstream commit 601b05ca6edb0422bf6ce313fbfd55ec7bbbc0fd ]
In case the cpu_bufs are sparsely allocated they are not all free'ed. These changes will fix this.
--- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +4 -1
@@ -5358,9 +5358,12 @@ void perf_buffer__free(struct perf_buffer *pb)if (!pb)return ;if (pb->cpu_bufs) { -for (i =0 ; i < pb->cpu_cnt && pb->cpu_bufs[i]; i++) { +for (i =0 ; i < pb->cpu_cnt; i++) {struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i]; +if (!cpu_buf) +continue ; +bpf_map_delete_elem (pb->map_fd, &cpu_buf->map_key);perf_buffer__free_cpu_buf (pb, cpu_buf); }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 169/175 bpf: Fix map permissions check
In reply to Sasha LevinFrom: Anton Protopopov <[email protected]>
[ Upstream commit 1ea0f9120c8ce105ca181b070561df5cbd6bc049 ]
The map_lookup_and_delete_elem() function should check for both FMODE_CAN_WRITE and FMODE_CAN_READ permissions because it returns a map element to user space.
--- kernel/bpf/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +2 -1
@@ -1118,7 +1118,8 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr) map =__bpf_map_get (f);if (IS_ERR (map))return PTR_ERR (map); -if (!(map_get_sys_perms (map, f) &FMODE_CAN_WRITE )) { +if (!(map_get_sys_perms (map, f) &FMODE_CAN_READ ) || + !(map_get_sys_perms (map, f) &FMODE_CAN_WRITE )) { err = -EPERM ; goto err_put; }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 170/175 bpf: Refactor sockmap redirect code so its easy to reuse
In reply to Sasha LevinFrom: John Fastabend <[email protected]>
[ Upstream commit ca2f5f21dbbd5e3a00cd3e97f728aa2ca0b2e011 ]
We will need this block of code called from tls context shortly lets refactor the redirect logic so its easy to use. This also cleans up the switch stmt so we have fewer fallthrough cases.
No logic changes are intended.
--- net/core/skmsg.c | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-)
net/core/skmsg.c +34 -21
@@ -686,13 +686,43 @@ static struct sk_psock *sk_psock_from_strp(struct strparser *strp) return container_of(parser, struct sk_psock, parser); } -static void sk_psock_verdict_apply (struct sk_psock *psock, -struct sk_buff *skb,int verdict) +static void sk_psock_skb_redirect (struct sk_psock *psock,struct sk_buff *skb) {struct sk_psock *psock_other;struct sock *sk_other;bool ingress; + sk_other =tcp_skb_bpf_redirect_fetch (skb); +if (unlikely (!sk_other)) { +kfree_skb (skb); +return ; + } + psock_other =sk_psock (sk_other); +if (!psock_other ||sock_flag (sk_other,SOCK_DEAD ) || + !sk_psock_test_state (psock_other,SK_PSOCK_TX_ENABLED )) { +kfree_skb (skb); +return ; + } + + ingress =tcp_skb_bpf_ingress (skb); +if ((!ingress &&sock_writeable (sk_other)) || + (ingress && +atomic_read (&sk_other->sk_rmem_alloc) <= + sk_other->sk_rcvbuf)) { +if (!ingress) +skb_set_owner_w (skb, sk_other); +skb_queue_tail (&psock_other->ingress_skb, skb); +schedule_work (&psock_other->work); + }else { +kfree_skb (skb); + } +} + +static void sk_psock_verdict_apply (struct sk_psock *psock, +struct sk_buff *skb,int verdict) +{ +struct sock *sk_other; +switch (verdict) {case __SK_PASS: sk_other = psock->sk;
@@ -711,25 +741,8 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, } goto out_free;case __SK_REDIRECT: - sk_other =tcp_skb_bpf_redirect_fetch (skb); -if (unlikely (!sk_other)) - goto out_free; - psock_other =sk_psock (sk_other); -if (!psock_other ||sock_flag (sk_other,SOCK_DEAD ) || - !sk_psock_test_state (psock_other,SK_PSOCK_TX_ENABLED )) - goto out_free; - ingress =tcp_skb_bpf_ingress (skb); -if ((!ingress &&sock_writeable (sk_other)) || - (ingress && -atomic_read (&sk_other->sk_rmem_alloc) <= - sk_other->sk_rcvbuf)) { -if (!ingress) -skb_set_owner_w (skb, sk_other); -skb_queue_tail (&psock_other->ingress_skb, skb); -schedule_work (&psock_other->work); -break ; - } -/* fall-through */ +sk_psock_skb_redirect (psock, skb); +break ;case __SK_DROP:/* fall-through */ default :
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 171/175 bpf: Fix running sk_skb program types with ktls
In reply to Sasha LevinFrom: John Fastabend <[email protected]>
[ Upstream commit e91de6afa81c10e9f855c5695eb9a53168d96b73 ]
KTLS uses a stream parser to collect TLS messages and send them to the upper layer tls receive handler. This ensures the tls receiver has a full TLS header to parse when it is run. However, when a socket has BPF_SK_SKB_STREAM_VERDICT program attached before KTLS is enabled we end up with two stream parsers running on the same socket.
The result is both try to run on the same socket. First the KTLS stream parser runs and calls read_sock() which will tcp_read_sock which in turn calls tcp_rcv_skb(). This dequeues the skb from the sk_receive_queue. When this is done KTLS code then data_ready() callback which because we stacked KTLS on top of the bpf stream verdict program has been replaced with sk_psock_start_strp(). This will in turn kick the stream parser again and eventually do the same thing KTLS did above calling into tcp_rcv_skb() and dequeuing a skb from the sk_receive_queue.
At this point the data stream is broke. Part of the stream was handled by the KTLS side some other bytes may have been handled by the BPF side. Generally this results in either missing data or more likely a "Bad Message" complaint from the kTLS receive handler as the BPF program steals some bytes meant to be in a TLS header and/or the TLS header length is no longer correct.
We've already broke the idealized model where we can stack ULPs in any order with generic callbacks on the TX side to handle this. So in this patch we do the same thing but for RX side. We add a sk_psock_strp_enabled() helper so TLS can learn a BPF verdict program is running and add a tls_sw_has_ctx_rx() helper so BPF side can learn there is a TLS ULP on the socket.
Then on BPF side we omit calling our stream parser to avoid breaking the data stream for the KTLS receiver. Then on the KTLS side we call BPF_SK_SKB_STREAM_VERDICT once the KTLS receiver is done with the packet but before it posts the msg to userspace. This gives us symmetry between the TX and RX halfs and IMO makes it usable again. On the TX side we process packets in this order BPF -> TLS -> TCP and on the receive side in the reverse order TCP -> TLS -> BPF.
Discovered while testing OpenSSL 3.0 Alpha2.0 release.
--- include/linux/skmsg.h | 8 ++++++++ include/net/tls.h | 9 +++++++++ net/core/skmsg.c | 43 ++++++++++++++++++++++++++++++++++++++++--- net/tls/tls_sw.c | 20 ++++++++++++++++++-- 4 files changed, 75 insertions(+), 5 deletions(-)
include/linux/skmsg.h +8 -0
@@ -457,4 +457,12 @@ static inline void psock_progs_drop(struct sk_psock_progs *progs) psock_set_prog(&progs->skb_verdict, NULL); } +int sk_psock_tls_strp_read (struct sk_psock *psock,struct sk_buff *skb); + +static inline bool sk_psock_strp_enabled (struct sk_psock *psock) +{ +if (!psock) +return false; +return psock->parser.enabled; +}#endif /* _LINUX_SKMSG_H */
include/net/tls.h +9 -0
@@ -590,6 +590,15 @@ static inline bool tls_sw_has_ctx_tx(const struct sock *sk)return !!tls_sw_ctx_tx (ctx); } +static inline bool tls_sw_has_ctx_rx (const struct sock *sk) +{ +struct tls_context *ctx =tls_get_ctx (sk); + +if (!ctx) +return false; +return !!tls_sw_ctx_rx (ctx); +} +void tls_sw_write_space (struct sock *sk,struct tls_context *ctx);void tls_device_write_space (struct sock *sk,struct tls_context *ctx);
net/core/skmsg.c +40 -3
61 lines not on this page · raw message
net/tls/tls_sw.c +18 -2
@@ -1737,6 +1737,7 @@ int tls_sw_recvmsg(struct sock *sk,long timeo;bool is_kvec =iov_iter_is_kvec (&msg->msg_iter);bool is_peek = flags &MSG_PEEK ; +bool bpf_strp_enabled;int num_async =0 ;int pending;
@@ -1747,6 +1748,7 @@ int tls_sw_recvmsg(struct sock *sk, psock =sk_psock_get (sk);lock_sock (sk); + bpf_strp_enabled =sk_psock_strp_enabled (psock);/* Process pending decrypted records. It must be non-zero-copy */ err = process_rx_list(ctx, msg, &control, &cmsg, 0, len, false,
@@ -1800,11 +1802,12 @@ int tls_sw_recvmsg(struct sock *sk,if (to_decrypt <= len && !is_kvec && !is_peek && ctx->control ==TLS_RECORD_TYPE_DATA && - prot->version !=TLS_1_3_VERSION ) + prot->version !=TLS_1_3_VERSION && + !bpf_strp_enabled) zc = true;/* Do not use async mode if record is non-data */ -if (ctx->control ==TLS_RECORD_TYPE_DATA ) +if (ctx->control ==TLS_RECORD_TYPE_DATA && !bpf_strp_enabled) async_capable = ctx->async_capable;else async_capable = false;
@@ -1854,6 +1857,19 @@ int tls_sw_recvmsg(struct sock *sk, goto pick_next_record;if (!zc) { +if (bpf_strp_enabled) { + err =sk_psock_tls_strp_read (psock, skb); +if (err != __SK_PASS) { + rxm->offset = rxm->offset + rxm->full_len; + rxm->full_len =0 ; +if (err == __SK_DROP) +consume_skb (skb); + ctx->recv_pkt =NULL ; +__strp_unpause (&ctx->strp); +continue ; + } + } +if (rxm->full_len > len) { retain_skb = true; chunk = len;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 172/175 selftests/bpf, flow_dissector: Close TAP device FD after the test
In reply to Sasha LevinFrom: Jakub Sitnicki <[email protected]>
[ Upstream commit b8215dce7dfd817ca38807f55165bf502146cd68 ]
test_flow_dissector leaves a TAP device after it's finished, potentially interfering with other tests that will run after it. Fix it by closing the TAP descriptor on cleanup.
--- tools/testing/selftests/bpf/prog_tests/flow_dissector.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/flow_dissector.c +1 -0
@@ -523,6 +523,7 @@ void test_flow_dissector(void)CHECK_ATTR (err, tests[i].name,"bpf_map_delete_elem %d\n" , err); } +close (tap_fd);bpf_prog_detach (prog_fd,BPF_FLOW_DISSECTOR );bpf_object__close (obj); }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 173/175 net_failover: fixed rollback in net_failover_open()
In reply to Sasha LevinFrom: Vasily Averin <[email protected]>
[ Upstream commit e8224bfe77293494626f6eec1884fee7b87d0ced ]
found by smatch:drivers/net/net_failover.c:65 net_failover_open() error:
we previously assumed 'primary_dev' could be null (see line 43)
--- drivers/net/net_failover.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/net_failover.c +2 -1
@@ -61,7 +61,8 @@ static int net_failover_open(struct net_device *dev)return 0 ; err_standby_open: -dev_close (primary_dev); +if (primary_dev) +dev_close (primary_dev); err_primary_open:netif_tx_disable (dev);return err;
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 174/175 kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE
In reply to Sasha LevinFrom: Daniel Axtens <[email protected]>
[ Upstream commit adb72ae1915db28f934e9e02c18bfcea2f3ed3b7 ]
Patch series "Fix some incompatibilites between KASAN and FORTIFY_SOURCE", v4.
3 KASAN self-tests fail on a kernel with both KASAN and FORTIFY_SOURCE:
memchr, memcmp and strlen.
When FORTIFY_SOURCE is on, a number of functions are replaced with fortified versions, which attempt to check the sizes of the operands. However, these functions often directly invoke __builtin_foo() once they have performed the fortify check. The compiler can detect that the results of these functions are not used, and knows that they have no other side effects, and so can eliminate them as dead code.
Why are only memchr, memcmp and strlen affected?
================================================
Of string and string-like functions, kasan_test tests:
* strchr -> not affected, no fortified version * strrchr -> likewise * strcmp -> likewise * strncmp -> likewise
* strnlen -> not affected, the fortify source implementation calls the underlying strnlen implementation which is instrumented, not a builtin
* strlen -> affected, the fortify souce implementation calls a __builtin version which the compiler can determine is dead.
* memchr -> likewise * memcmp -> likewise
* memset -> not affected, the compiler knows that memset writes to its
first argument and therefore is not dead.
Why does this not affect the functions normally?
================================================
In string.h, these functions are not marked as __pure, so the compiler cannot know that they do not have side effects. If relevant functions are marked as __pure in string.h, we see the following warnings and the functions are elided:
lib/test_kasan.c: In function `kasan_memchr':lib/test_kasan.c:606:2: warning: statement with no effect [-Wunused-value]
memchr(ptr, '1', size + 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~lib/test_kasan.c: In function `kasan_memcmp':lib/test_kasan.c:622:2: warning: statement with no effect [-Wunused-value]
memcmp(ptr, arr, size+1);
^~~~~~~~~~~~~~~~~~~~~~~~lib/test_kasan.c: In function `kasan_strings':lib/test_kasan.c:645:2: warning: statement with no effect [-Wunused-value]
strchr(ptr, '1');
^~~~~~~~~~~~~~~~
...
This annotation would make sense to add and could be added at any point, so the behaviour of test_kasan.c should change.
The fix
=======
Make all the functions that are pure write their results to a global, which makes them live. The strlen and memchr tests now pass.
The memcmp test still fails to trigger, which is addressed in the next patch.
--- lib/test_kasan.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
lib/test_kasan.c +19 -10
@@ -22,6 +22,14 @@#include <asm/page.h> +/* +* We assign some test results to these globals to make sure the tests +* are not eliminated as dead code. +*/ + +int kasan_int_result; +void *kasan_ptr_result; +/* * Note: test functions are marked noinline so that their names appear in * reports.
@@ -603,7 +611,7 @@ static noinline void __init kasan_memchr(void)if (!ptr)return ; -memchr (ptr,'1' , size +1 ); + kasan_ptr_result =memchr (ptr,'1' , size +1 );kfree (ptr); }
@@ -619,7 +627,7 @@ static noinline void __init kasan_memcmp(void)return ;memset (arr,0 ,sizeof (arr)); -memcmp (ptr, arr, size+1 ); + kasan_int_result =memcmp (ptr, arr, size +1 );kfree (ptr); }
@@ -642,22 +650,22 @@ static noinline void __init kasan_strings(void)* will likely point to zeroed byte. */ ptr +=16 ; -strchr (ptr,'1' ); + kasan_ptr_result =strchr (ptr,'1' );pr_info ("use-after-free in strrchr\n" ); -strrchr (ptr,'1' ); + kasan_ptr_result =strrchr (ptr,'1' );pr_info ("use-after-free in strcmp\n" ); -strcmp (ptr,"2" ); + kasan_int_result =strcmp (ptr,"2" );pr_info ("use-after-free in strncmp\n" ); -strncmp (ptr,"2" ,1 ); + kasan_int_result =strncmp (ptr,"2" ,1 );pr_info ("use-after-free in strlen\n" ); -strlen (ptr); + kasan_int_result =strlen (ptr);pr_info ("use-after-free in strnlen\n" ); -strnlen (ptr,1 ); + kasan_int_result =strnlen (ptr,1 ); } static noinline void __init kasan_bitops(void)
@@ -724,11 +732,12 @@ static noinline void __init kasan_bitops(void)__test_and_change_bit (BITS_PER_LONG +BITS_PER_BYTE , bits);pr_info ("out-of-bounds in test_bit\n" ); - (void )test_bit (BITS_PER_LONG +BITS_PER_BYTE , bits); + kasan_int_result =test_bit (BITS_PER_LONG +BITS_PER_BYTE , bits);#if defined(clear_bit_unlock_is_negative_byte)pr_info ("out-of-bounds in clear_bit_unlock_is_negative_byte\n" ); -clear_bit_unlock_is_negative_byte (BITS_PER_LONG +BITS_PER_BYTE , bits); + kasan_int_result =clear_bit_unlock_is_negative_byte (BITS_PER_LONG + +BITS_PER_BYTE , bits);#endif kfree (bits); }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 175/175 string.h: fix incompatibility between FORTIFY_SOURCE and KASAN
In reply to Sasha LevinFrom: Daniel Axtens <[email protected]>
[ Upstream commit 47227d27e2fcb01a9e8f5958d8997cf47a820afc ]
The memcmp KASAN self-test fails on a kernel with both KASAN and FORTIFY_SOURCE.
When FORTIFY_SOURCE is on, a number of functions are replaced with fortified versions, which attempt to check the sizes of the operands. However, these functions often directly invoke __builtin_foo() once they have performed the fortify check. Using __builtins may bypass KASAN checks if the compiler decides to inline it's own implementation as sequence of instructions, rather than emit a function call that goes out to a KASAN-instrumented implementation.
Why is only memcmp affected?
============================
Of the string and string-like functions that kasan_test tests, only memcmp is replaced by an inline sequence of instructions in my testing on x86 with gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2).
I believe this is due to compiler heuristics. For example, if I annotate kmalloc calls with the alloc_size annotation (and disable some fortify compile-time checking!), the compiler will replace every memset except the one in kmalloc_uaf_memset with inline instructions. (I have some WIP patches to add this annotation.)
Does this affect other functions in string.h?
=============================================
Yes. Anything that uses __builtin_* rather than __real_* could be affected. This looks like:
- strncpy
- strcat
- strlen
- strlcpy maybe, under some circumstances?
- strncat under some circumstances
- memset
- memcpy
- memmove
- memcmp (as noted)
- memchr
- strcpy
Whether a function call is emitted always depends on the compiler. Most bugs should get caught by FORTIFY_SOURCE, but the missed memcmp test shows that this is not always the case.
Isn't FORTIFY_SOURCE disabled with KASAN?
========================================-
The string headers on all arches supporting KASAN disable fortify with kasan, but only when address sanitisation is _also_ disabled. For example from x86:
#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) /*
* For files that are not instrumented (e.g. mm/slub.c) we
* should use not instrumented version of mem* functions. */
#define memcpy(dst, src, len) __memcpy(dst, src, len) #define memmove(dst, src, len) __memmove(dst, src, len) #define memset(s, c, n) __memset(s, c, n)
#ifndef __NO_FORTIFY
#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ #endif
#endif
This comes from commit 6974f0c4555e ("include/linux/string.h: add the option of fortified string.h functions"), and doesn't work when KASAN is enabled and the file is supposed to be sanitised - as with test_kasan.c
I'm pretty sure this is not wrong, but not as expansive it should be:
* we shouldn't use __builtin_memcpy etc in files where we don't have instrumentation - it could devolve into a function call to memcpy, which will be instrumented. Rather, we should use __memcpy which by convention is not instrumented.
* we also shouldn't be using __builtin_memcpy when we have a KASAN instrumented file, because it could be replaced with inline asm that will not be instrumented.
What is correct behaviour?
==========================
Firstly, there is some overlap between fortification and KASAN: both provide some level of _runtime_ checking. Only fortify provides compile-time checking.
KASAN and fortify can pick up different things at runtime:
- Some fortify functions, notably the string functions, could easily be modified to consider sub-object sizes (e.g. members within a struct), and I have some WIP patches to do this. KASAN cannot detect these because it cannot insert poision between members of a struct.
- KASAN can detect many over-reads/over-writes when the sizes of both operands are unknown, which fortify cannot.
So there are a couple of options:
1) Flip the test: disable fortify in santised files and enable it in unsanitised files. This at least stops us missing KASAN checking, but we lose the fortify checking.
2) Make the fortify code always call out to real versions. Do this only for KASAN, for fear of losing the inlining opportunities we get from __builtin_*.
(We can't use kasan_check_{read,write}: because the fortify functions are _extern inline_, you can't include _static_ inline functions without a compiler warning. kasan_check_{read,write} are static inline so we can't use them even when they would otherwise be suitable.)
Take approach 2 and call out to real versions when KASAN is enabled.
Use __underlying_foo to distinguish from __real_foo: __real_foo always refers to the kernel's implementation of foo, __underlying_foo could be either the kernel implementation or the __builtin_foo implementation.
This is sometimes enough to make the memcmp test succeed with FORTIFY_SOURCE enabled. It is at least enough to get the function call into the module. One more fix is needed to make it reliable: see the next patch.
--- include/linux/string.h | 60 +++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-)
include/linux/string.h +48 -12
@@ -269,6 +269,31 @@ void __read_overflow3(void) __compiletime_error("detected read beyond size of ob void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE ) + +#ifdef CONFIG_KASAN +extern void *__underlying_memchr (const void *p,int c,__kernel_size_t size)__RENAME (memchr); +extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp); +extern void *__underlying_memcpy (void *p,const void *q,__kernel_size_t size)__RENAME (memcpy); +extern void *__underlying_memmove (void *p,const void *q,__kernel_size_t size)__RENAME (memmove); +extern void *__underlying_memset (void *p,int c,__kernel_size_t size)__RENAME (memset); +extern char *__underlying_strcat (char *p,const char *q)__RENAME (strcat); +extern char *__underlying_strcpy (char *p,const char *q)__RENAME (strcpy); +extern __kernel_size_t __underlying_strlen(const char *p) __RENAME(strlen); +extern char *__underlying_strncat (char *p,const char *q,__kernel_size_t count)__RENAME (strncat); +extern char *__underlying_strncpy (char *p,const char *q,__kernel_size_t size)__RENAME (strncpy); +#else +#define __underlying_memchr __builtin_memchr +#define __underlying_memcmp __builtin_memcmp +#define __underlying_memcpy __builtin_memcpy +#define __underlying_memmove __builtin_memmove +#define __underlying_memset __builtin_memset +#define __underlying_strcat __builtin_strcat +#define __underlying_strcpy __builtin_strcpy +#define __underlying_strlen __builtin_strlen +#define __underlying_strncat __builtin_strncat +#define __underlying_strncpy __builtin_strncpy +#endif + __FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size) {size_t p_size =__builtin_object_size (p,0 );
@@ -276,14 +301,14 @@ __FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)__write_overflow ();if (p_size < size)fortify_panic (__func__); -return __builtin_strncpy (p, q, size); +return __underlying_strncpy (p, q, size); } __FORTIFY_INLINE char *strcat(char *p, const char *q) {size_t p_size =__builtin_object_size (p,0 );if (p_size == (size_t )-1 ) -return __builtin_strcat (p, q); +return __underlying_strcat (p, q);if (strlcat (p, q, p_size) >= p_size)fortify_panic (__func__);return p;
@@ -297,7 +322,7 @@ __FORTIFY_INLINE __kernel_size_t strlen(const char *p)/* Work around gcc excess stack consumption issue */ if (p_size == (size_t )-1 || (__builtin_constant_p (p[p_size -1 ]) && p[p_size -1 ] =='\0' )) -return __builtin_strlen (p); +return __underlying_strlen (p); ret =strnlen (p, p_size);if (p_size <= ret)fortify_panic (__func__);
@@ -330,7 +355,7 @@ __FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)__write_overflow ();if (len >= p_size)fortify_panic (__func__); -__builtin_memcpy (p, q, len); +__underlying_memcpy (p, q, len); p[len] ='\0' ; }return ret;
@@ -343,12 +368,12 @@ __FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)size_t p_size =__builtin_object_size (p,0 );size_t q_size =__builtin_object_size (q,0 );if (p_size == (size_t )-1 && q_size == (size_t )-1 ) -return __builtin_strncat (p, q, count); +return __underlying_strncat (p, q, count); p_len =strlen (p); copy_len =strnlen (q, count);if (p_size < p_len + copy_len +1 )fortify_panic (__func__); -__builtin_memcpy (p + p_len, q, copy_len); +__underlying_memcpy (p + p_len, q, copy_len); p[p_len + copy_len] ='\0' ;return p; }
@@ -360,7 +385,7 @@ __FORTIFY_INLINE void *memset(void *p, int c, __kernel_size_t size)__write_overflow ();if (p_size < size)fortify_panic (__func__); -return __builtin_memset (p, c, size); +return __underlying_memset (p, c, size); } __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size)
@@ -375,7 +400,7 @@ __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size) }if (p_size < size || q_size < size)fortify_panic (__func__); -return __builtin_memcpy (p, q, size); +return __underlying_memcpy (p, q, size); } __FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size)
@@ -390,7 +415,7 @@ __FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size) }if (p_size < size || q_size < size)fortify_panic (__func__); -return __builtin_memmove (p, q, size); +return __underlying_memmove (p, q, size); }extern void *__real_memscan (void *,int ,__kernel_size_t )__RENAME (memscan);
@@ -416,7 +441,7 @@ __FORTIFY_INLINE int memcmp(const void *p, const void *q, __kernel_size_t size) }if (p_size < size || q_size < size)fortify_panic (__func__); -return __builtin_memcmp (p, q, size); +return __underlying_memcmp (p, q, size); } __FORTIFY_INLINE void *memchr(const void *p, int c, __kernel_size_t size)
@@ -426,7 +451,7 @@ __FORTIFY_INLINE void *memchr(const void *p, int c, __kernel_size_t size)__read_overflow ();if (p_size < size)fortify_panic (__func__); -return __builtin_memchr (p, c, size); +return __underlying_memchr (p, c, size); }void *__real_memchr_inv (const void *s,int c,size_t n)__RENAME (memchr_inv);
@@ -457,11 +482,22 @@ __FORTIFY_INLINE char *strcpy(char *p, const char *q)size_t p_size =__builtin_object_size (p,0 );size_t q_size =__builtin_object_size (q,0 );if (p_size == (size_t )-1 && q_size == (size_t )-1 ) -return __builtin_strcpy (p, q); +return __underlying_strcpy (p, q);memcpy (p, q,strlen (q) +1 ); return p; } +/* Don't use these outside the FORITFY_SOURCE implementation */ +#undef __underlying_memchr +#undef __underlying_memcmp +#undef __underlying_memcpy +#undef __underlying_memmove +#undef __underlying_memset +#undef __underlying_strcat +#undef __underlying_strcpy +#undef __underlying_strlen +#undef __underlying_strncat +#undef __underlying_strncpy#endif /**
Signature · 1 line
2.25.1