net: tundra: tsi108: use spin_lock_irqsave instead of spin_lock_irq in IRQ context
Subsystems (8)
Sasha Levin
maintainerPATCH 1/16 net: tundra: tsi108: use spin_lock_irqsave instead of spin_lock_irq in IRQ context
From: Fuqian Huang <[email protected]>
[ Upstream commit 8c25d0887a8bd0e1ca2074ac0c6dff173787a83b ]
As spin_unlock_irq will enable interrupts.
Function tsi108_stat_carry is called from interrupt handler tsi108_irq. Interrupts are enabled in interrupt handler.
Use spin_lock_irqsave/spin_unlock_irqrestore instead of spin_(un)lock_irq in IRQ context to avoid this.
--- drivers/net/ethernet/tundra/tsi108_eth.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/tundra/tsi108_eth.c +3 -2
@@ -381,9 +381,10 @@ tsi108_stat_carry_one(int carry, int carry_bit, int carry_shift,static void tsi108_stat_carry (struct net_device *dev) {struct tsi108_prv_data *data =netdev_priv (dev); +unsigned long flags;u32 carry1, carry2; -spin_lock_irq (&data->misclock); +spin_lock_irqsave (&data->misclock, flags); carry1 =TSI_READ (TSI108_STAT_CARRY1 ); carry2 =TSI_READ (TSI108_STAT_CARRY2 );
@@ -451,7 +452,7 @@ static void tsi108_stat_carry(struct net_device *dev)TSI108_STAT_TXPAUSEDROP_CARRY , &data->tx_pause_drop); -spin_unlock_irq (&data->misclock); +spin_unlock_irqrestore (&data->misclock, flags); }/* Read a stat counter atomically with respect to carries.
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 2/16 net: tc35815: Explicitly check NET_IP_ALIGN is not zero in tc35815_rx
From: Nathan Chancellor <[email protected]>
[ Upstream commit 125b7e0949d4e72b15c2b1a1590f8cece985a918 ]
clang warns:
drivers/net/ethernet/toshiba/tc35815.c:1507:30: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
if (!HAVE_DMA_RXALIGN(lp) && NET_IP_ALIGN)
^ ~~~~~~~~~~~~
drivers/net/ethernet/toshiba/tc35815.c:1507:30: note: use '&' for a
bitwise operation
if (!HAVE_DMA_RXALIGN(lp) && NET_IP_ALIGN)
^~
&
drivers/net/ethernet/toshiba/tc35815.c:1507:30: note: remove constant to
silence this warning
if (!HAVE_DMA_RXALIGN(lp) && NET_IP_ALIGN)
~^~~~~~~~~~~~~~~1 warning generated.
Explicitly check that NET_IP_ALIGN is not zero, which matches how this is checked in other parts of the tree. Because NET_IP_ALIGN is a build time constant, this check will be constant folded away during optimization.
--- drivers/net/ethernet/toshiba/tc35815.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/toshiba/tc35815.c +1 -1
@@ -1498,7 +1498,7 @@ tc35815_rx(struct net_device *dev, int limit)pci_unmap_single (lp->pci_dev, lp->rx_skbs[cur_bd].skb_dma,RX_BUF_SIZE ,PCI_DMA_FROMDEVICE ); -if (!HAVE_DMA_RXALIGN (lp) &&NET_IP_ALIGN ) +if (!HAVE_DMA_RXALIGN (lp) &&NET_IP_ALIGN !=0 )memmove (skb->data, skb->data -NET_IP_ALIGN , pkt_len); data =skb_put (skb, pkt_len);
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 3/16 Bluetooth: btqca: Add a short delay before downloading the NVM
In reply to Sasha LevinFrom: Matthias Kaehlcke <[email protected]>
[ Upstream commit 8059ba0bd0e4694e51c2ee6438a77b325f06c0d5 ]
On WCN3990 downloading the NVM sometimes fails with a "TLV response size mismatch" error:
[ 174.949955] Bluetooth: btqca.c:qca_download_firmware() hci0: QCA Downloading qca/crnv21.bin [ 174.958718] Bluetooth: btqca.c:qca_tlv_send_segment() hci0: QCA TLV response size mismatch
It seems the controller needs a short time after downloading the firmware before it is ready for the NVM. A delay as short as 1 ms seems sufficient, make it 10 ms just in case. No event is received during the delay, hence we don't just silently drop an extra event.
--- drivers/bluetooth/btqca.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/bluetooth/btqca.c +3 -0
@@ -363,6 +363,9 @@ int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate)return err; } +/* Give the controller some time to get ready to receive the NVM */ +msleep (10 ); +/* Download NVM configuration */ config.type =TLV_TYPE_NVM ; snprintf(config.fwname, sizeof(config.fwname), "qca/nvm_%08x.bin",
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 4/16 ibmveth: Convert multicast list size for little-endian system
In reply to Sasha LevinFrom: Thomas Falcon <[email protected]>
[ Upstream commit 66cf4710b23ab2adda11155684a2c8826f4fe732 ]
The ibm,mac-address-filters property defines the maximum number of addresses the hypervisor's multicast filter list can support. It is encoded as a big-endian integer in the OF device tree, but the virtual ethernet driver does not convert it for use by little-endian systems. As a result, the driver is not behaving as it should on affected systems when a large number of multicast addresses are assigned to the device.
--- drivers/net/ethernet/ibm/ibmveth.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +5 -4
@@ -1557,7 +1557,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)struct net_device *netdev;struct ibmveth_adapter *adapter;unsigned char *mac_addr_p; -unsigned int *mcastFilterSize_p; +__be32 *mcastFilterSize_p;long ret;unsigned long ret_attr;
@@ -1579,8 +1579,9 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)return -EINVAL ; } - mcastFilterSize_p = (unsigned int *)vio_get_attribute (dev, -VETH_MCAST_FILTER_SIZE ,NULL ); + mcastFilterSize_p = (__be32 *)vio_get_attribute (dev, +VETH_MCAST_FILTER_SIZE , +NULL );if (!mcastFilterSize_p) {dev_err (&dev->dev,"Can't find VETH_MCAST_FILTER_SIZE " "attribute\n" );
@@ -1597,7 +1598,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) adapter->vdev = dev; adapter->netdev = netdev; - adapter->mcastFilterSize = *mcastFilterSize_p; + adapter->mcastFilterSize =be32_to_cpu (*mcastFilterSize_p); adapter->pool_config =0 ;netif_napi_add (netdev, &adapter->napi, ibmveth_poll,16 );
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 5/16 gpio: Fix build error of function redefinition
In reply to Sasha LevinFrom: YueHaibing <[email protected]>
[ Upstream commit 68e03b85474a51ec1921b4d13204782594ef7223 ]
when do randbuilding, I got this error:
In file included from drivers/hwmon/pmbus/ucd9000.c:19:0:./include/linux/gpio/driver.h:576:1: error: redefinition of gpiochip_add_pin_range
gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, ^~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/hwmon/pmbus/ucd9000.c:18:0:./include/linux/gpio.h:245:1: note: previous definition of gpiochip_add_pin_range was here
gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, ^~~~~~~~~~~~~~~~~~~~~~
--- include/linux/gpio.h | 24 ------------------------ 1 file changed, 24 deletions(-)
include/linux/gpio.h +0 -24
@@ -229,30 +229,6 @@ static inline int irq_to_gpio(unsigned irq)return -EINVAL ; } -static inline int -gpiochip_add_pin_range (struct gpio_chip *chip,const char *pinctl_name, -unsigned int gpio_offset,unsigned int pin_offset, -unsigned int npins) -{ -WARN_ON (1 ); -return -EINVAL ; -} - -static inline int -gpiochip_add_pingroup_range (struct gpio_chip *chip, -struct pinctrl_dev *pctldev, -unsigned int gpio_offset,const char *pin_group) -{ -WARN_ON (1 ); -return -EINVAL ; -} - -static inline void -gpiochip_remove_pin_ranges (struct gpio_chip *chip) -{ -WARN_ON (1 ); -} -static inline int devm_gpio_request (struct device *dev,unsigned gpio,const char *label) {
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 6/16 cxgb4: fix a memory leak bug
In reply to Sasha LevinFrom: Wenwen Wang <[email protected]>
[ Upstream commit c554336efa9bbc28d6ec14efbee3c7d63c61a34f ]
In blocked_fl_write(), 't' is not deallocated if bitmap_parse_user() fails, leading to a memory leak bug. To fix this issue, free t before returning the error.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +3 -1
@@ -2781,8 +2781,10 @@ static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,return -ENOMEM ; err =bitmap_parse_user (ubuf, count, t, adap->sge.egr_sz); -if (err) +if (err) { +kvfree (t);return err; + }bitmap_copy (adap->sge.blocked_fl, t, adap->sge.egr_sz);t4_free_mem (t);
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 7/16 net: myri10ge: fix memory leaks
In reply to Sasha LevinFrom: Wenwen Wang <[email protected]>
[ Upstream commit 20fb7c7a39b5c719e2e619673b5f5729ee7d2306 ]
In myri10ge_probe(), myri10ge_alloc_slices() is invoked to allocate slices related structures. Later on, myri10ge_request_irq() is used to get an irq. However, if this process fails, the allocated slices related structures are not deallocated, leading to memory leaks. To fix this issue, revise the target label of the goto statement to 'abort_with_slices'.
--- drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/myricom/myri10ge/myri10ge.c +1 -1
@@ -4113,7 +4113,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)* setup (if available). */ status =myri10ge_request_irq (mgp);if (status !=0 ) - goto abort_with_firmware; + goto abort_with_slices;myri10ge_free_irq (mgp);/* Save configuration space to be restored if the
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 8/16 cx82310_eth: fix a memory leak bug
In reply to Sasha LevinFrom: Wenwen Wang <[email protected]>
[ Upstream commit 1eca92eef18719027d394bf1a2d276f43e7cf886 ]
In cx82310_bind(), 'dev->partial_data' is allocated through kmalloc(). Then, the execution waits for the firmware to become ready. If the firmware is not ready in time, the execution is terminated. However, the allocated 'dev->partial_data' is not deallocated on this path, leading to a memory leak bug. To fix this issue, free 'dev->partial_data' before returning the error.
--- drivers/net/usb/cx82310_eth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/usb/cx82310_eth.c +2 -1
@@ -175,7 +175,8 @@ static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf) }if (!timeout) {dev_err (&udev->dev,"firmware not ready in time\n" ); -return -ETIMEDOUT ; + ret = -ETIMEDOUT ; + goto err; }/* enable ethernet mode (?) */
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 9/16 net: kalmia: fix memory leaks
In reply to Sasha LevinFrom: Wenwen Wang <[email protected]>
[ Upstream commit f1472cb09f11ddb41d4be84f0650835cb65a9073 ]
In kalmia_init_and_get_ethernet_addr(), 'usb_buf' is allocated through kmalloc(). In the following execution, if the 'status' returned by kalmia_send_init_packet() is not 0, 'usb_buf' is not deallocated, leading to memory leaks. To fix this issue, add the 'out' label to free 'usb_buf'.
--- drivers/net/usb/kalmia.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/usb/kalmia.c +3 -3
@@ -117,16 +117,16 @@ kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr) status =kalmia_send_init_packet (dev, usb_buf,sizeof (init_msg_1) /sizeof (init_msg_1[0 ]), usb_buf,24 );if (status !=0 ) -return status; + goto out;memcpy (usb_buf, init_msg_2,12 ); status =kalmia_send_init_packet (dev, usb_buf,sizeof (init_msg_2) /sizeof (init_msg_2[0 ]), usb_buf,28 );if (status !=0 ) -return status; + goto out;memcpy (ethernet_addr, usb_buf +10 ,ETH_ALEN ); - +out:kfree (usb_buf);return status; }
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 10/16 wimax/i2400m: fix a memory leak bug
In reply to Sasha LevinFrom: Wenwen Wang <[email protected]>
[ Upstream commit 44ef3a03252844a8753479b0cea7f29e4a804bdc ]
In i2400m_barker_db_init(), 'options_orig' is allocated through kstrdup() to hold the original command line options. Then, the options are parsed. However, if an error occurs during the parsing process, 'options_orig' is not deallocated, leading to a memory leak bug. To fix this issue, free 'options_orig' before returning the error.
--- drivers/net/wimax/i2400m/fw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wimax/i2400m/fw.c +3 -1
@@ -351,13 +351,15 @@ int i2400m_barker_db_init(const char *_options) } result =i2400m_barker_db_add (barker);if (result <0 ) - goto error_add; + goto error_parse_add; }kfree (options_orig); }return 0 ; +error_parse_add: error_parse: +kfree (options_orig); error_add:kfree (i2400m_barker_db);return result;
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 11/16 ravb: Fix use-after-free ravb_tstamp_skb
In reply to Sasha LevinFrom: Tho Vu <[email protected]>
[ Upstream commit cfef46d692efd852a0da6803f920cc756eea2855 ]
When a Tx timestamp is requested, a pointer to the skb is stored in the ravb_tstamp_skb struct. This was done without an skb_get. There exists the possibility that the skb could be freed by ravb_tx_free (when ravb_tx_free is called from ravb_start_xmit) before the timestamp was processed, leading to a use-after-free bug.
Use skb_get when filling a ravb_tstamp_skb struct, and add appropriate frees/consumes when a ravb_tstamp_skb struct is freed.
--- drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/renesas/ravb_main.c +6 -2
@@ -1,6 +1,6 @@/* Renesas Ethernet AVB device driver * -* Copyright (C) 2014-2015 Renesas Electronics Corporation +* Copyright (C) 2014-2019 Renesas Electronics Corporation * Copyright (C) 2015 Renesas Solutions Corp. * Copyright (C) 2015-2016 Cogent Embedded, Inc. <[email protected]> *
@@ -512,7 +512,10 @@ static void ravb_get_tx_tstamp(struct net_device *ndev)kfree (ts_skb);if (tag == tfa_tag) {skb_tstamp_tx (skb, &shhwtstamps); +dev_consume_skb_any (skb);break ; + }else { +dev_kfree_skb_any (skb); } }ravb_modify (ndev,TCCR ,TCCR_TFR ,TCCR_TFR );
@@ -1537,7 +1540,7 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev) DMA_TO_DEVICE); goto unmap; } - ts_skb->skb = skb; + ts_skb->skb =skb_get (skb); ts_skb->tag = priv->ts_skb_tag++; priv->ts_skb_tag &=0x3ff ;list_add_tail (&ts_skb->list, &priv->ts_skb_list);
@@ -1665,6 +1668,7 @@ static int ravb_close(struct net_device *ndev)/* Clear the timestamp list */ list_for_each_entry_safe (ts_skb, ts_skb2, &priv->ts_skb_list, list) {list_del (&ts_skb->list); +kfree_skb (ts_skb->skb);kfree (ts_skb); }
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 12/16 Tools: hv: kvp: eliminate 'may be used uninitialized' warning
In reply to Sasha LevinFrom: Vitaly Kuznetsov <[email protected]>
[ Upstream commit 89eb4d8d25722a0a0194cf7fa47ba602e32a6da7 ]
When building hv_kvp_daemon GCC-8.3 complains:
hv_kvp_daemon.c: In function ‘kvp_get_ip_info.constprop’:
hv_kvp_daemon.c:812:30: warning: ‘ip_buffer’ may be used uninitialized in this function [-Wmaybe-uninitialized]
struct hv_kvp_ipaddr_value *ip_buffer;
this seems to be a false positive: we only use ip_buffer when op == KVP_OP_GET_IP_INFO and it is only unset when op == KVP_OP_ENUMERATE.
Silence the warning by initializing ip_buffer to NULL.
--- tools/hv/hv_kvp_daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/hv/hv_kvp_daemon.c +1 -1
@@ -878,7 +878,7 @@ kvp_get_ip_info(int family, char *if_name, int op,int sn_offset =0 ;int error =0 ;char *buffer; -struct hv_kvp_ipaddr_value *ip_buffer; +struct hv_kvp_ipaddr_value *ip_buffer =NULL ;char cidr_mask[5 ];/* /xyz */ int weight;int i;
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 13/16 IB/mlx4: Fix memory leaks
In reply to Sasha LevinFrom: Wenwen Wang <[email protected]>
[ Upstream commit 5c1baaa82cea2c815a5180ded402a7cd455d1810 ]
In mlx4_ib_alloc_pv_bufs(), 'tun_qp->tx_ring' is allocated through kcalloc(). However, it is not always deallocated in the following execution if an error occurs, leading to memory leaks. To fix this issue, free 'tun_qp->tx_ring' whenever an error occurs.
--- drivers/infiniband/hw/mlx4/mad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx4/mad.c +2 -2
@@ -1643,8 +1643,6 @@ static int mlx4_ib_alloc_pv_bufs(struct mlx4_ib_demux_pv_ctx *ctx, tx_buf_size, DMA_TO_DEVICE);kfree (tun_qp->tx_ring[i].buf.addr); } -kfree (tun_qp->tx_ring); - tun_qp->tx_ring =NULL ; i =MLX4_NUM_TUNNEL_BUFS ; err:while (i >0 ) {
@@ -1653,6 +1651,8 @@ static int mlx4_ib_alloc_pv_bufs(struct mlx4_ib_demux_pv_ctx *ctx, rx_buf_size, DMA_FROM_DEVICE);kfree (tun_qp->ring[i].addr); } +kfree (tun_qp->tx_ring); + tun_qp->tx_ring =NULL ;kfree (tun_qp->ring); tun_qp->ring =NULL ;return -ENOMEM ;
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 14/16 ceph: fix buffer free while holding i_ceph_lock in __ceph_setxattr()
In reply to Sasha LevinFrom: Luis Henriques <[email protected]>
[ Upstream commit 86968ef21596515958d5f0a40233d02be78ecec0 ]
Calling ceph_buffer_put() in __ceph_setxattr() may end up freeing the i_xattrs.prealloc_blob buffer while holding the i_ceph_lock. This can be fixed by postponing the call until later, when the lock is released.
The following backtrace was triggered by fstests generic/117.
BUG: sleeping function called from invalid context at mm/vmalloc.c:2283
in_atomic(): 1, irqs_disabled(): 0, pid: 650, name: fsstress
3 locks held by fsstress/650:
#0: 00000000870a0fe8 (sb_writers#8){.+.+}, at: mnt_want_write+0x20/0x50
#1: 00000000ba0c4c74 (&type->i_mutex_dir_key#6){++++}, at: vfs_setxattr+0x55/0xa0
#2: 000000008dfbb3f2 (&(&ci->i_ceph_lock)->rlock){+.+.}, at: __ceph_setxattr+0x297/0x810
CPU: 1 PID: 650 Comm: fsstress Not tainted 5.2.0+ #437
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58-prebuilt.qemu.org 04/01/2014
Call Trace:
dump_stack+0x67/0x90
___might_sleep.cold+0x9f/0xb1
vfree+0x4b/0x60
ceph_buffer_release+0x1b/0x60
__ceph_setxattr+0x2b4/0x810
__vfs_setxattr+0x66/0x80
__vfs_setxattr_noperm+0x59/0xf0
vfs_setxattr+0x81/0xa0
setxattr+0x115/0x230
? filename_lookup+0xc9/0x140
? rcu_read_lock_sched_held+0x74/0x80
? rcu_sync_lockdep_assert+0x2e/0x60
? __sb_start_write+0x142/0x1a0
? mnt_want_write+0x20/0x50
path_setxattr+0xba/0xd0
__x64_sys_lsetxattr+0x24/0x30
do_syscall_64+0x50/0x1c0
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7ff23514359a--- fs/ceph/xattr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/ceph/xattr.c +6 -2
@@ -951,6 +951,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_mds_client *mdsc =ceph_sb_to_client (inode->i_sb)->mdsc;struct ceph_cap_flush *prealloc_cf =NULL ; +struct ceph_buffer *old_blob =NULL ;int issued;int err;int dirty =0 ;
@@ -1019,13 +1020,15 @@ int __ceph_setxattr(struct inode *inode, const char *name,struct ceph_buffer *blob;spin_unlock (&ci->i_ceph_lock); -dout (" preaallocating new blob size=%d\n" , required_blob_size); +ceph_buffer_put (old_blob);/* Shouldn't be required */ +dout (" pre-allocating new blob size=%d\n" , required_blob_size); blob =ceph_buffer_new (required_blob_size,GFP_NOFS );if (!blob) goto do_sync_unlocked;spin_lock (&ci->i_ceph_lock); +/* prealloc_blob can't be released while holding i_ceph_lock */ if (ci->i_xattrs.prealloc_blob) -ceph_buffer_put (ci->i_xattrs.prealloc_blob); + old_blob = ci->i_xattrs.prealloc_blob; ci->i_xattrs.prealloc_blob = blob; goto retry; }
@@ -1041,6 +1044,7 @@ int __ceph_setxattr(struct inode *inode, const char *name, }spin_unlock (&ci->i_ceph_lock); +ceph_buffer_put (old_blob);if (lock_snap_rwsem)up_read (&mdsc->snap_rwsem);if (dirty)
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 15/16 ceph: fix buffer free while holding i_ceph_lock in fill_inode()
In reply to Sasha LevinFrom: Luis Henriques <[email protected]>
[ Upstream commit af8a85a41734f37b67ba8ce69d56b685bee4ac48 ]
Calling ceph_buffer_put() in fill_inode() may result in freeing the i_xattrs.blob buffer while holding the i_ceph_lock. This can be fixed by postponing the call until later, when the lock is released.
The following backtrace was triggered by fstests generic/070.
BUG: sleeping function called from invalid context at mm/vmalloc.c:2283
in_atomic(): 1, irqs_disabled(): 0, pid: 3852, name: kworker/0:4
6 locks held by kworker/0:4/3852:
#0: 000000004270f6bb ((wq_completion)ceph-msgr){+.+.}, at: process_one_work+0x1b8/0x5f0
#1: 00000000eb420803 ((work_completion)(&(&con->work)->work)){+.+.}, at: process_one_work+0x1b8/0x5f0
#2: 00000000be1c53a4 (&s->s_mutex){+.+.}, at: dispatch+0x288/0x1476
#3: 00000000559cb958 (&mdsc->snap_rwsem){++++}, at: dispatch+0x2eb/0x1476
#4: 000000000d5ebbae (&req->r_fill_mutex){+.+.}, at: dispatch+0x2fc/0x1476
#5: 00000000a83d0514 (&(&ci->i_ceph_lock)->rlock){+.+.}, at: fill_inode.isra.0+0xf8/0xf70
CPU: 0 PID: 3852 Comm: kworker/0:4 Not tainted 5.2.0+ #441
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58-prebuilt.qemu.org 04/01/2014
Workqueue: ceph-msgr ceph_con_workfn
Call Trace:
dump_stack+0x67/0x90
___might_sleep.cold+0x9f/0xb1
vfree+0x4b/0x60
ceph_buffer_release+0x1b/0x60
fill_inode.isra.0+0xa9b/0xf70
ceph_fill_trace+0x13b/0xc70
? dispatch+0x2eb/0x1476
dispatch+0x320/0x1476
? __mutex_unlock_slowpath+0x4d/0x2a0
ceph_con_workfn+0xc97/0x2ec0
? process_one_work+0x1b8/0x5f0
process_one_work+0x244/0x5f0
worker_thread+0x4d/0x3e0
kthread+0x105/0x140
? process_one_work+0x5f0/0x5f0
? kthread_park+0x90/0x90
ret_from_fork+0x3a/0x50--- fs/ceph/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/ceph/inode.c +4 -3
@@ -741,6 +741,7 @@ static int fill_inode(struct inode *inode, struct page *locked_page,int issued =0 , implemented, new_issued;struct timespec mtime, atime, ctime;struct ceph_buffer *xattr_blob =NULL ; +struct ceph_buffer *old_blob =NULL ;struct ceph_string *pool_ns =NULL ;struct ceph_cap *new_cap =NULL ;int err =0 ;
@@ -858,7 +859,7 @@ static int fill_inode(struct inode *inode, struct page *locked_page,if ((ci->i_xattrs.version ==0 || !(issued &CEPH_CAP_XATTR_EXCL )) &&le64_to_cpu (info->xattr_version) > ci->i_xattrs.version) {if (ci->i_xattrs.blob) -ceph_buffer_put (ci->i_xattrs.blob); + old_blob = ci->i_xattrs.blob; ci->i_xattrs.blob = xattr_blob;if (xattr_blob) memcpy(ci->i_xattrs.blob->vec.iov_base,
@@ -1004,8 +1005,8 @@ static int fill_inode(struct inode *inode, struct page *locked_page, out:if (new_cap)ceph_put_cap (mdsc, new_cap); -if (xattr_blob) -ceph_buffer_put (xattr_blob); +ceph_buffer_put (old_blob); +ceph_buffer_put (xattr_blob);ceph_put_string (pool_ns);return err; }
Signature · 1 line
2.20.1
Sasha Levin
maintainerPATCH 16/16 KVM: arm/arm64: Only skip MMIO insn once
In reply to Sasha LevinFrom: Andrew Jones <[email protected]>
[ Upstream commit 2113c5f62b7423e4a72b890bd479704aa85c81ba ]
If after an MMIO exit to userspace a VCPU is immediately run with an immediate_exit request, such as when a signal is delivered or an MMIO emulation completion is needed, then the VCPU completes the MMIO emulation and immediately returns to userspace. As the exit_reason does not get changed from KVM_EXIT_MMIO in these cases we have to be careful not to complete the MMIO emulation again, when the VCPU is eventually run again, because the emulation does an instruction skip (and doing too many skips would be a waste of guest code :-) We need to use additional VCPU state to track if the emulation is complete. As luck would have it, we already have 'mmio_needed', which even appears to be used in this way by other architectures already.
--- arch/arm/kvm/mmio.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/kvm/mmio.c +7 -0
@@ -98,6 +98,12 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)unsigned int len;int mask; +/* Detect an already handled MMIO return */ +if (unlikely (!vcpu->mmio_needed)) +return 0 ; + + vcpu->mmio_needed =0 ; +if (!run->mmio.is_write) { len = run->mmio.len;if (len >sizeof (unsigned long ))
@@ -200,6 +206,7 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, run->mmio.is_write = is_write; run->mmio.phys_addr = fault_ipa; run->mmio.len = len; + vcpu->mmio_needed =1 ;if (!ret) {/* We handled the access successfully in the kernel. */
Signature · 1 line
2.20.1