linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Ilya Dryomov <idryomov@gmail.com>,
	Robin Geuze <robin.geuze@nl.team.blue>
Subject: [PATCH 5.4 097/108] rbd: dont hold lock_rwsem while running_list is being drained
Date: Mon, 26 Jul 2021 17:39:38 +0200	[thread overview]
Message-ID: <20210726153834.792089562@linuxfoundation.org> (raw)
In-Reply-To: <20210726153831.696295003@linuxfoundation.org>

From: Ilya Dryomov <idryomov@gmail.com>

commit ed9eb71085ecb7ded9a5118cec2ab70667cc7350 upstream.

Currently rbd_quiesce_lock() holds lock_rwsem for read while blocking
on releasing_wait completion.  On the I/O completion side, each image
request also needs to take lock_rwsem for read.  Because rw_semaphore
implementation doesn't allow new readers after a writer has indicated
interest in the lock, this can result in a deadlock if something that
needs to take lock_rwsem for write gets involved.  For example:

1. watch error occurs
2. rbd_watch_errcb() takes lock_rwsem for write, clears owner_cid and
   releases lock_rwsem
3. after reestablishing the watch, rbd_reregister_watch() takes
   lock_rwsem for write and calls rbd_reacquire_lock()
4. rbd_quiesce_lock() downgrades lock_rwsem to for read and blocks on
   releasing_wait until running_list becomes empty
5. another watch error occurs
6. rbd_watch_errcb() blocks trying to take lock_rwsem for write
7. no in-flight image request can complete and delete itself from
   running_list because lock_rwsem won't be granted anymore

A similar scenario can occur with "lock has been acquired" and "lock
has been released" notification handers which also take lock_rwsem for
write to update owner_cid.

We don't actually get anything useful from sitting on lock_rwsem in
rbd_quiesce_lock() -- owner_cid updates certainly don't need to be
synchronized with.  In fact the whole owner_cid tracking logic could
probably be removed from the kernel client because we don't support
proxied maintenance operations.

Cc: stable@vger.kernel.org # 5.3+
URL: https://tracker.ceph.com/issues/42757
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Tested-by: Robin Geuze <robin.geuze@nl.team.blue>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/block/rbd.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -4239,8 +4239,6 @@ again:
 
 static bool rbd_quiesce_lock(struct rbd_device *rbd_dev)
 {
-	bool need_wait;
-
 	dout("%s rbd_dev %p\n", __func__, rbd_dev);
 	lockdep_assert_held_write(&rbd_dev->lock_rwsem);
 
@@ -4252,11 +4250,11 @@ static bool rbd_quiesce_lock(struct rbd_
 	 */
 	rbd_dev->lock_state = RBD_LOCK_STATE_RELEASING;
 	rbd_assert(!completion_done(&rbd_dev->releasing_wait));
-	need_wait = !list_empty(&rbd_dev->running_list);
-	downgrade_write(&rbd_dev->lock_rwsem);
-	if (need_wait)
-		wait_for_completion(&rbd_dev->releasing_wait);
-	up_read(&rbd_dev->lock_rwsem);
+	if (list_empty(&rbd_dev->running_list))
+		return true;
+
+	up_write(&rbd_dev->lock_rwsem);
+	wait_for_completion(&rbd_dev->releasing_wait);
 
 	down_write(&rbd_dev->lock_rwsem);
 	if (rbd_dev->lock_state != RBD_LOCK_STATE_RELEASING)



  parent reply	other threads:[~2021-07-26 16:15 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 15:38 [PATCH 5.4 000/108] 5.4.136-rc1 review Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 001/108] igc: Fix use-after-free error during reset Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 002/108] igb: " Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 003/108] igc: change default return of igc_read_phy_reg() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 004/108] ixgbe: Fix an error handling path in ixgbe_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 005/108] igc: Prefer to use the pci_release_mem_regions method Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 006/108] igc: Fix an error handling path in igc_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 007/108] igb: Fix an error handling path in igb_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 008/108] fm10k: Fix an error handling path in fm10k_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 009/108] e1000e: Fix an error handling path in e1000_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 010/108] iavf: Fix an error handling path in iavf_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 011/108] igb: Check if num of q_vectors is smaller than max before array access Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 012/108] igb: Fix position of assignment to *ring Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 013/108] gve: Fix an error handling path in gve_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 014/108] ipv6: fix disable_policy for fwd packets Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 015/108] selftests: icmp_redirect: remove from checking for IPv6 route get Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 016/108] selftests: icmp_redirect: IPv6 PMTU info should be cleared after redirect Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 017/108] pwm: sprd: Ensure configuring period and duty_cycle isnt wrongly skipped Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 018/108] cxgb4: fix IRQ free race during driver unload Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 019/108] nvme-pci: do not call nvme_dev_remove_admin from nvme_remove Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 020/108] perf map: Fix dso->nsinfo refcounting Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 021/108] perf probe: " Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 022/108] perf env: Fix sibling_dies memory leak Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 023/108] perf test session_topology: Delete session->evlist Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 024/108] perf test event_update: Fix memory leak of evlist Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 025/108] perf dso: Fix memory leak in dso__new_map() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 026/108] perf script: Fix memory threads and cpus leaks on exit Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 027/108] perf lzma: Close lzma stream " Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 028/108] perf probe-file: Delete namelist in del_events() on the error path Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 029/108] perf data: Close all files in close_dir() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 030/108] spi: imx: add a check for speed_hz before calculating the clock Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 031/108] spi: stm32: Use dma_request_chan() instead dma_request_slave_channel() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 032/108] spi: stm32: fixes pm_runtime calls in probe/remove Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 033/108] regulator: hi6421: Use correct variable type for regmap api val argument Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 034/108] regulator: hi6421: Fix getting wrong drvdata Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 035/108] spi: mediatek: fix fifo rx mode Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 036/108] ASoC: rt5631: Fix regcache sync errors on resume Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 037/108] liquidio: Fix unintentional sign extension issue on left shift of u16 Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 038/108] s390/bpf: Perform r1 range checking before accessing jit->seen_reg[r1] Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 039/108] bpf, sockmap, tcp: sk_prot needs inuse_idx set for proc stats Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 040/108] bpftool: Check malloc return value in mount_bpffs_for_pin Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 041/108] net: fix uninit-value in caif_seqpkt_sendmsg Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 042/108] efi/tpm: Differentiate missing and invalid final event log table Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 043/108] net: decnet: Fix sleeping inside in af_decnet Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 044/108] KVM: PPC: Book3S: Fix CONFIG_TRANSACTIONAL_MEM=n crash Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 045/108] KVM: PPC: Fix kvm_arch_vcpu_ioctl vcpu_load leak Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 046/108] net: sched: fix memory leak in tcindex_partial_destroy_work Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 047/108] netrom: Decrease sock refcount when sock timers expire Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 048/108] scsi: iscsi: Fix iface sysfs attr detection Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 049/108] scsi: target: Fix protect handling in WRITE SAME(32) Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 050/108] spi: cadence: Correct initialisation of runtime PM again Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 051/108] bnxt_en: Improve bnxt_ulp_stop()/bnxt_ulp_start() call sequence Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 052/108] bnxt_en: Refresh RoCE capabilities in bnxt_ulp_probe() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 053/108] bnxt_en: Add missing check for BNXT_STATE_ABORT_ERR in bnxt_fw_rset_task() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 054/108] bnxt_en: Check abort error state in bnxt_half_open_nic() Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 055/108] net: hisilicon: rename CACHE_LINE_MASK to avoid redefinition Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 056/108] net/tcp_fastopen: fix data races around tfo_active_disable_stamp Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 057/108] net: hns3: fix rx VLAN offload state inconsistent issue Greg Kroah-Hartman
2021-07-26 15:38 ` [PATCH 5.4 058/108] net/sched: act_skbmod: Skip non-Ethernet packets Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 059/108] ipv6: fix another slab-out-of-bounds in fib6_nh_flush_exceptions Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 060/108] nvme-pci: dont WARN_ON in nvme_reset_work if ctrl.state is not RESETTING Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 061/108] Revert "USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem" Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 062/108] afs: Fix tracepoint string placement with built-in AFS Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 063/108] r8169: Avoid duplicate sysfs entry creation error Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 064/108] nvme: set the PRACT bit when using Write Zeroes with T10 PI Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 065/108] sctp: update active_key for asoc when old key is being replaced Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 066/108] net: sched: cls_api: Fix the the wrong parameter Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 067/108] drm/panel: raspberrypi-touchscreen: Prevent double-free Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 068/108] proc: Avoid mixing integer types in mem_rw() Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 069/108] [PATCH] Revert "MIPS: add PMD table accounting into MIPSpmd_alloc_one" Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 070/108] s390/ftrace: fix ftrace_update_ftrace_func implementation Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 071/108] s390/boot: fix use of expolines in the DMA code Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 072/108] ALSA: usb-audio: Add missing proc text entry for BESPOKEN type Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 073/108] ALSA: usb-audio: Add registration quirk for JBL Quantum headsets Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 074/108] ALSA: sb: Fix potential ABBA deadlock in CSP driver Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 075/108] ALSA: hdmi: Expose all pins on MSI MS-7C94 board Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 076/108] xhci: Fix lost USB 2 remote wake Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 077/108] KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 078/108] KVM: PPC: Book3S HV Nested: Sanitise H_ENTER_NESTED TM state Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 079/108] usb: hub: Disable USB 3 device initiated lpm if exit latency is too high Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 080/108] usb: hub: Fix link power management max exit latency (MEL) calculations Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 081/108] USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 082/108] usb: max-3421: Prevent corruption of freed memory Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 083/108] usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 084/108] USB: serial: option: add support for u-blox LARA-R6 family Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 085/108] USB: serial: cp210x: fix comments for GE CS1000 Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 086/108] USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 087/108] usb: dwc2: gadget: Fix sending zero length packet in DDMA mode Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 088/108] firmware/efi: Tell memblock about EFI iomem reservations Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 089/108] tracing/histogram: Rename "cpu" to "common_cpu" Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 090/108] tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 091/108] btrfs: check for missing device in btrfs_trim_fs Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 092/108] media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 093/108] ixgbe: Fix packet corruption due to missing DMA sync Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 094/108] selftest: use mmap instead of posix_memalign to allocate memory Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 095/108] userfaultfd: do not untag user pointers Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 096/108] hugetlbfs: fix mount mode command line processing Greg Kroah-Hartman
2021-07-26 15:39 ` Greg Kroah-Hartman [this message]
2021-07-26 15:39 ` [PATCH 5.4 098/108] rbd: always kick acquire on "acquired" and "released" notifications Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 099/108] nds32: fix up stack guard gap Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 100/108] drm: Return -ENOTTY for non-drm ioctls Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 101/108] net: dsa: mv88e6xxx: use correct .stats_set_histogram() on Topaz Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 102/108] net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 103/108] iio: accel: bma180: Use explicit member assignment Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 104/108] iio: accel: bma180: Fix BMA25x bandwidth register values Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 105/108] btrfs: compression: dont try to compress if we dont have enough pages Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 106/108] PCI: Mark AMD Navi14 GPU ATS as broken Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 107/108] perf inject: Close inject.output on exit Greg Kroah-Hartman
2021-07-26 15:39 ` [PATCH 5.4 108/108] xhci: add xhci_get_virt_ep() helper Greg Kroah-Hartman
2021-07-26 21:15 ` [PATCH 5.4 000/108] 5.4.136-rc1 review Florian Fainelli
2021-07-27  0:35 ` Shuah Khan
2021-07-27  8:49 ` Naresh Kamboju
2021-07-27 16:06 ` Sudip Mukherjee
2021-07-27 18:02 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210726153834.792089562@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.geuze@nl.team.blue \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).