scsi: core: Put LLD module refcnt after SCSI device is released
Subsystems (7)
Sasha Levin
maintainerPATCH 1/9 scsi: core: Put LLD module refcnt after SCSI device is released
From: Ming Lei <[email protected]>
[ Upstream commit f2b85040acec9a928b4eb1b57a989324e8e38d3f ]
SCSI host release is triggered when SCSI device is freed. We have to make sure that the low-level device driver module won't be unloaded before SCSI host instance is released because shost->hostt is required in the release handler.
Make sure to put LLD module refcnt after SCSI device is released.
Fixes a kernel panic of 'BUG: unable to handle page fault for address' reported by Changhui and Yi.
--- drivers/scsi/scsi.c | 4 +++- drivers/scsi/scsi_sysfs.c | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/scsi/scsi.c +3 -1
@@ -555,8 +555,10 @@ EXPORT_SYMBOL(scsi_device_get);*/ void scsi_device_put (struct scsi_device *sdev) { -module_put (sdev->host->hostt->module); +struct module *mod = sdev->host->hostt->module; +put_device (&sdev->sdev_gendev); +module_put (mod); }EXPORT_SYMBOL (scsi_device_put);
drivers/scsi/scsi_sysfs.c +9 -0
@@ -438,9 +438,12 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)struct list_head *this, *tmp;struct scsi_vpd *vpd_pg80 =NULL , *vpd_pg83 =NULL ;unsigned long flags; +struct module *mod; sdev = container_of(work, struct scsi_device, ew.work); + mod = sdev->host->hostt->module; +scsi_dh_release_device (sdev); parent = sdev->sdev_gendev.parent;
@@ -481,11 +484,17 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)if (parent)put_device (parent); +module_put (mod); }static void scsi_device_dev_release (struct device *dev) {struct scsi_device *sdp =to_scsi_device (dev); + +/* Set module pointer as NULL in case of module unloading */ +if (!try_module_get (sdp->host->hostt->module)) + sdp->host->hostt->module =NULL ; +execute_in_process_context (scsi_device_dev_release_usercontext, &sdp->ew); }
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 2/9 cavium: Return negative value when pci_alloc_irq_vectors() fails
From: Zheyu Ma <[email protected]>
[ Upstream commit b2cddb44bddc1a9c5949a978bb454bba863264db ]
During the process of driver probing, the probe function should return < 0 for failure, otherwise, the kernel will treat value > 0 as success.
--- drivers/net/ethernet/cavium/thunder/nic_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cavium/thunder/nic_main.c +1 -1
@@ -1193,7 +1193,7 @@ static int nic_register_interrupts(struct nicpf *nic)dev_err (&nic->pdev->dev,"Request for #%d msix vectors failed, returned %d\n" , nic->num_vec, ret); -return 1 ; +return ret; }/* Register mailbox interrupt handler */
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 3/9 scsi: qla2xxx: Return -ENOMEM if kzalloc() fails
In reply to Sasha LevinFrom: Zheyu Ma <[email protected]>
[ Upstream commit 06634d5b6e923ed0d4772aba8def5a618f44c7fe ]
The driver probing function should return < 0 for failure, otherwise kernel will treat value > 0 as success.
--- drivers/scsi/qla2xxx/qla_os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_os.c +1 -1
@@ -4064,7 +4064,7 @@ qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,ql_dbg_pci (ql_dbg_init, ha->pdev,0xe0ee ,"%s: failed alloc dsd\n" , __func__); -return 1 ; +return -ENOMEM ; } ha->dif_bundle_kallocs++;
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 4/9 scsi: qla2xxx: Fix unmap of already freed sgl
In reply to Sasha LevinFrom: Dmitry Bogdanov <[email protected]>
[ Upstream commit 4a8f71014b4d56c4fb287607e844c0a9f68f46d9 ]
The sgl is freed in the target stack in target_release_cmd_kref() before calling qlt_free_cmd() but there is an unmap of sgl in qlt_free_cmd() that causes a panic if sgl is not yet DMA unmapped:
NIP dma_direct_unmap_sg+0xdc/0x180
LR dma_direct_unmap_sg+0xc8/0x180
Call Trace: ql_dbg_prefix+0x68/0xc0 [qla2xxx] (unreliable) dma_unmap_sg_attrs+0x54/0xf0 qlt_unmap_sg.part.19+0x54/0x1c0 [qla2xxx] qlt_free_cmd+0x124/0x1d0 [qla2xxx] tcm_qla2xxx_release_cmd+0x4c/0xa0 [tcm_qla2xxx] target_put_sess_cmd+0x198/0x370 [target_core_mod] transport_generic_free_cmd+0x6c/0x1b0 [target_core_mod] tcm_qla2xxx_complete_free+0x6c/0x90 [tcm_qla2xxx]
The sgl may be left unmapped in error cases of response sending. For instance, qlt_rdy_to_xfer() maps sgl and exits when session is being deleted keeping the sgl mapped.
This patch removes use-after-free of the sgl and ensures that the sgl is unmapped for any command that was not sent to firmware.
--- drivers/scsi/qla2xxx/qla_target.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/scsi/qla2xxx/qla_target.c +5 -9
@@ -3251,8 +3251,7 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type,"RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n" , vha->flags.online,qla2x00_reset_active (vha), cmd->reset_count, qpair->chip_reset); -spin_unlock_irqrestore (qpair->qp_lock_ptr, flags); -return 0 ; + goto out_unmap_unlock; }/* Does F/W have an IOCBs for this request */
@@ -3375,10 +3374,6 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) prm.sg =NULL ; prm.req_cnt =1 ; -/* Calculate number of entries and segments required */ -if (qlt_pci_map_calc_cnt (&prm) !=0 ) -return -EAGAIN ; -if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || (cmd->sess && cmd->sess->deleted)) {/*
@@ -3396,6 +3391,10 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)return 0 ; } +/* Calculate number of entries and segments required */ +if (qlt_pci_map_calc_cnt (&prm) !=0 ) +return -EAGAIN ; +spin_lock_irqsave (qpair->qp_lock_ptr, flags);/* Does F/W have an IOCBs for this request */ res =qlt_check_reserve_free_req (qpair, prm.req_cnt);
@@ -3800,9 +3799,6 @@ void qlt_free_cmd(struct qla_tgt_cmd *cmd)BUG_ON (cmd->cmd_in_wq); -if (cmd->sg_mapped) -qlt_unmap_sg (cmd->vha, cmd); -if (!cmd->q_full)qlt_decr_num_pend_cmds (cmd->vha);
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 5/9 cavium: Fix return values of the probe function
In reply to Sasha LevinFrom: Zheyu Ma <[email protected]>
[ Upstream commit c69b2f46876825c726bd8a97c7fa852d8932bc32 ]
During the process of driver probing, the probe function should return < 0 for failure, otherwise, the kernel will treat value > 0 as success.
--- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +2 -2
@@ -1226,7 +1226,7 @@ static int nicvf_register_misc_interrupt(struct nicvf *nic)if (ret <0 ) {netdev_err (nic->netdev,"Req for #%d msix vectors failed\n" , nic->num_vec); -return 1 ; +return ret; }sprintf (nic->irq_name[irq],"%s Mbox" ,"NICVF" );
@@ -1245,7 +1245,7 @@ static int nicvf_register_misc_interrupt(struct nicvf *nic)if (!nicvf_check_pf_ready (nic)) {nicvf_disable_intr (nic,NICVF_INTR_MBOX ,0 );nicvf_unregister_interrupts (nic); -return 1 ; +return -EIO ; }return 0 ;
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 6/9 vrf: Revert "Reset skb conntrack connection..."
In reply to Sasha LevinFrom: Eugene Crosser <[email protected]>
[ Upstream commit 55161e67d44fdd23900be166a81e996abd6e3be9 ]
This reverts commit 09e856d54bda5f288ef8437a90ab2b9b3eab83d1.
When an interface is enslaved in a VRF, prerouting conntrack hook is called twice: once in the context of the original input interface, and once in the context of the VRF interface. If no special precausions are taken, this leads to creation of two conntrack entries instead of one, and breaks SNAT.
Commit above was intended to avoid creation of extra conntrack entries when input interface is enslaved in a VRF. It did so by resetting conntrack related data associated with the skb when it enters VRF context.
However it breaks netfilter operation. Imagine a use case when conntrack zone must be assigned based on the original input interface, rather than VRF interface (that would make original interfaces indistinguishable). One could create netfilter rules similar to these:
chain rawprerouting {
type filter hook prerouting priority raw;
iif realiface1 ct zone set 1 return
iif realiface2 ct zone set 2 return
}This works before the mentioned commit, but not after: zone assignment is "forgotten", and any subsequent NAT or filtering that is dependent on the conntrack zone does not work.
Here is a reproducer script that demonstrates the difference in behaviour.
==========
#!/bin/sh
# This script demonstrates unexpected change of nftables behaviour
# caused by commit 09e856d54bda5f28 ""vrf: Reset skb conntrack # connection on VRF rcv" # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=09e856d54bda5f288ef8437a90ab2b9b3eab83d1 # # Before the commit, it was possible to assign conntrack zone to a # packet (or mark it for `notracking`) in the prerouting chanin, raw # priority, based on the `iif` (interface from which the packet # arrived). # After the change, # if the interface is enslaved in a VRF, such # assignment is lost. Instead, assignment based on the `iif` matching # the VRF master interface is honored. Thus it is impossible to # distinguish packets based on the original interface. # # This script demonstrates this change of behaviour: conntrack zone 1 # or 2 is assigned depending on the match with the original interface # or the vrf master interface. It can be observed that conntrack entry # appears in different zone in the kernel versions before and after # the commit.
IPIN=172.30.30.1
IPOUT=172.30.30.2
PFXL=30
ip li sh vein >/dev/null 2>&1 && ip li del vein
ip li sh tvrf >/dev/null 2>&1 && ip li del tvrf
nft list table testct >/dev/null 2>&1 && nft delete table testct
ip li add vein type veth peer veout
ip li add tvrf type vrf table 9876
ip li set veout master tvrf
ip li set vein up
ip li set veout up
ip li set tvrf up/sbin/sysctl -w net.ipv4.conf.veout.accept_local=1 /sbin/sysctl -w net.ipv4.conf.veout.rp_filter=0 ip addr add $IPIN/$PFXL dev vein
ip addr add $IPOUT/$PFXL dev veout
nft -f - <<__END__
table testct {
chain rawpre {
type filter hook prerouting priority raw;
iif { veout, tvrf } meta nftrace set 1
iif veout ct zone set 1 return
iif tvrf ct zone set 2 return
notrack
}
chain rawout {
type filter hook output priority raw;
notrack
}
}__END__
uname -rv
conntrack -F
ping -W 1 -c 1 -I vein $IPOUT
conntrack -L
--- drivers/net/vrf.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/vrf.c +0 -4
@@ -1036,8 +1036,6 @@ static struct sk_buff *vrf_ip6_rcv(struct net_device *vrf_dev,bool need_strict =rt6_need_strict (&ipv6_hdr (skb)->daddr);bool is_ndisc =ipv6_ndisc_frame (skb); -nf_reset_ct (skb); -/* loopback, multicast & non-ND link-local traffic; do not push through * packet taps again. Reset pkt_type for upper layers to process skb. * For strict packets with a source LLA, determine the dst using the
@@ -1094,8 +1092,6 @@ static struct sk_buff *vrf_ip_rcv(struct net_device *vrf_dev, skb->skb_iif = vrf_dev->ifindex;IPCB (skb)->flags |=IPSKB_L3SLAVE ; -nf_reset_ct (skb); -if (ipv4_is_multicast (ip_hdr (skb)->daddr)) goto out;
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 7/9 sfc: Don't use netif_info before net_device setup
In reply to Sasha LevinFrom: Erik Ekman <[email protected]>
[ Upstream commit bf6abf345dfa77786aca554bc58c64bd428ecb1d ]
Use pci_info instead to avoid unnamed/uninitialized noise:
[197088.688729] sfc 0000:01:00.0: Solarflare NIC detected [197088.690333] sfc 0000:01:00.0: Part Number : SFN5122F [197088.729061] sfc 0000:01:00.0 (unnamed net_device) (uninitialized): no SR-IOV VFs probed [197088.729071] sfc 0000:01:00.0 (unnamed net_device) (uninitialized): no PTP support
Inspired by fa44821a4ddd ("sfc: don't use netif_info et al before net_device is registered") from Heiner Kallweit.
--- drivers/net/ethernet/sfc/ptp.c | 4 ++-- drivers/net/ethernet/sfc/siena_sriov.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/sfc/ptp.c +2 -2
@@ -648,7 +648,7 @@ static int efx_ptp_get_attributes(struct efx_nic *efx) }else if (rc == -EINVAL ) { fmt =MC_CMD_PTP_OUT_GET_ATTRIBUTES_SECONDS_NANOSECONDS ; }else if (rc == -EPERM ) { -netif_info (efx, probe, efx->net_dev,"no PTP support\n" ); +pci_info (efx->pci_dev,"no PTP support\n" );return rc; }else { efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf),
@@ -824,7 +824,7 @@ static int efx_ptp_disable(struct efx_nic *efx)* should only have been called during probe. */ if (rc == -ENOSYS || rc == -EPERM ) -netif_info (efx, probe, efx->net_dev,"no PTP support\n" ); +pci_info (efx->pci_dev,"no PTP support\n" );else if (rc) efx_mcdi_display_error(efx, MC_CMD_PTP, MC_CMD_PTP_IN_DISABLE_LEN,
drivers/net/ethernet/sfc/siena_sriov.c +1 -1
@@ -1056,7 +1056,7 @@ void efx_siena_sriov_probe(struct efx_nic *efx)return ;if (efx_siena_sriov_cmd (efx, false, &efx->vi_scale, &count)) { -netif_info (efx, probe, efx->net_dev,"no SR-IOV VFs probed\n" ); +pci_info (efx->pci_dev,"no SR-IOV VFs probed\n" );return ; }if (count >0 && count > max_vfs)
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 8/9 usbnet: sanity check for maxpacket
In reply to Sasha LevinFrom: Oliver Neukum <[email protected]>
[ Upstream commit 397430b50a363d8b7bdda00522123f82df6adc5e ]
maxpacket of 0 makes no sense and oopses as we need to divide by it. Give up.
V2: fixed typo in log and stylistic issues
--- drivers/net/usb/usbnet.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/usb/usbnet.c +4 -0
@@ -1773,6 +1773,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)if (!dev->rx_urb_size) dev->rx_urb_size = dev->hard_mtu; dev->maxpacket =usb_maxpacket (dev->udev, dev->out,1 ); +if (dev->maxpacket ==0 ) { +/* that is a broken device */ + goto out4; + }/* let userspace know we have a random address */ if (ether_addr_equal (net->dev_addr, node_id))
Signature · 1 line
2.33.0
Sasha Levin
maintainerPATCH 9/9 hyperv/vmbus: include linux/bitops.h
In reply to Sasha LevinFrom: Arnd Bergmann <[email protected]>
[ Upstream commit 8017c99680fa65e1e8d999df1583de476a187830 ]
On arm64 randconfig builds, hyperv sometimes fails with this error:
In file included from drivers/hv/hv_trace.c:3:
In file included from drivers/hv/hyperv_vmbus.h:16:
In file included from arch/arm64/include/asm/sync_bitops.h:5:arch/arm64/include/asm/bitops.h:11:2: error: only <linux/bitops.h> can be included directly
In file included from include/asm-generic/bitops/hweight.h:5:include/asm-generic/bitops/arch_hweight.h:9:9: error: implicit declaration of function '__sw_hweight32' [-Werror,-Wimplicit-function-declaration] include/asm-generic/bitops/atomic.h:17:7: error: implicit declaration of function 'BIT_WORD' [-Werror,-Wimplicit-function-declaration]
Include the correct header first.
--- drivers/hv/hyperv_vmbus.h | 1 + 1 file changed, 1 insertion(+)
drivers/hv/hyperv_vmbus.h +1 -0
@@ -13,6 +13,7 @@#define _HYPERV_VMBUS_H#include <linux/list.h> +#include <linux/bitops.h> #include <asm/sync_bitops.h> #include <asm/hyperv-tlfs.h> #include <linux/atomic.h>
Signature · 1 line
2.33.0