stable.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, Josef Bacik <josef@toxicpanda.com>,
	Mike Christie <mchristi@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.14 48/61] nbd: fix max number of supported devs
Date: Thu, 10 Oct 2019 10:37:13 +0200	[thread overview]
Message-ID: <20191010083519.876334933@linuxfoundation.org> (raw)
In-Reply-To: <20191010083449.500442342@linuxfoundation.org>

From: Mike Christie <mchristi@redhat.com>

[ Upstream commit e9e006f5fcf2bab59149cb38a48a4817c1b538b4 ]

This fixes a bug added in 4.10 with commit:

commit 9561a7ade0c205bc2ee035a2ac880478dcc1a024
Author: Josef Bacik <jbacik@fb.com>
Date:   Tue Nov 22 14:04:40 2016 -0500

    nbd: add multi-connection support

that limited the number of devices to 256. Before the patch we could
create 1000s of devices, but the patch switched us from using our
own thread to using a work queue which has a default limit of 256
active works.

The problem is that our recv_work function sits in a loop until
disconnection but only handles IO for one connection. The work is
started when the connection is started/restarted, but if we end up
creating 257 or more connections, the queue_work call just queues
connection257+'s recv_work and that waits for connection 1 - 256's
recv_work to be disconnected and that work instance completing.

Instead of reverting back to kthreads, this has us allocate a
workqueue_struct per device, so we can block in the work.

Cc: stable@vger.kernel.org
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/block/nbd.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 14b491c5cf7b6..a234600849558 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -106,6 +106,7 @@ struct nbd_device {
 	struct nbd_config *config;
 	struct mutex config_lock;
 	struct gendisk *disk;
+	struct workqueue_struct *recv_workq;
 
 	struct list_head list;
 	struct task_struct *task_recv;
@@ -136,7 +137,6 @@ static struct dentry *nbd_dbg_dir;
 
 static unsigned int nbds_max = 16;
 static int max_part = 16;
-static struct workqueue_struct *recv_workqueue;
 static int part_shift;
 
 static int nbd_dev_dbg_init(struct nbd_device *nbd);
@@ -1015,7 +1015,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
 		/* We take the tx_mutex in an error path in the recv_work, so we
 		 * need to queue_work outside of the tx_mutex.
 		 */
-		queue_work(recv_workqueue, &args->work);
+		queue_work(nbd->recv_workq, &args->work);
 
 		atomic_inc(&config->live_connections);
 		wake_up(&config->conn_wait);
@@ -1120,6 +1120,10 @@ static void nbd_config_put(struct nbd_device *nbd)
 		kfree(nbd->config);
 		nbd->config = NULL;
 
+		if (nbd->recv_workq)
+			destroy_workqueue(nbd->recv_workq);
+		nbd->recv_workq = NULL;
+
 		nbd->tag_set.timeout = 0;
 		queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);
 
@@ -1145,6 +1149,14 @@ static int nbd_start_device(struct nbd_device *nbd)
 		return -EINVAL;
 	}
 
+	nbd->recv_workq = alloc_workqueue("knbd%d-recv",
+					  WQ_MEM_RECLAIM | WQ_HIGHPRI |
+					  WQ_UNBOUND, 0, nbd->index);
+	if (!nbd->recv_workq) {
+		dev_err(disk_to_dev(nbd->disk), "Could not allocate knbd recv work queue.\n");
+		return -ENOMEM;
+	}
+
 	blk_mq_update_nr_hw_queues(&nbd->tag_set, config->num_connections);
 	nbd->task_recv = current;
 
@@ -1175,7 +1187,7 @@ static int nbd_start_device(struct nbd_device *nbd)
 		INIT_WORK(&args->work, recv_work);
 		args->nbd = nbd;
 		args->index = i;
-		queue_work(recv_workqueue, &args->work);
+		queue_work(nbd->recv_workq, &args->work);
 	}
 	nbd_size_update(nbd);
 	return error;
@@ -1195,8 +1207,10 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b
 	mutex_unlock(&nbd->config_lock);
 	ret = wait_event_interruptible(config->recv_wq,
 					 atomic_read(&config->recv_threads) == 0);
-	if (ret)
+	if (ret) {
 		sock_shutdown(nbd);
+		flush_workqueue(nbd->recv_workq);
+	}
 	mutex_lock(&nbd->config_lock);
 	bd_set_size(bdev, 0);
 	/* user requested, ignore socket errors */
@@ -1836,6 +1850,12 @@ static void nbd_disconnect_and_put(struct nbd_device *nbd)
 	mutex_lock(&nbd->config_lock);
 	nbd_disconnect(nbd);
 	mutex_unlock(&nbd->config_lock);
+	/*
+	 * Make sure recv thread has finished, so it does not drop the last
+	 * config ref and try to destroy the workqueue from inside the work
+	 * queue.
+	 */
+	flush_workqueue(nbd->recv_workq);
 	if (test_and_clear_bit(NBD_HAS_CONFIG_REF,
 			       &nbd->config->runtime_flags))
 		nbd_config_put(nbd);
@@ -2216,20 +2236,12 @@ static int __init nbd_init(void)
 
 	if (nbds_max > 1UL << (MINORBITS - part_shift))
 		return -EINVAL;
-	recv_workqueue = alloc_workqueue("knbd-recv",
-					 WQ_MEM_RECLAIM | WQ_HIGHPRI |
-					 WQ_UNBOUND, 0);
-	if (!recv_workqueue)
-		return -ENOMEM;
 
-	if (register_blkdev(NBD_MAJOR, "nbd")) {
-		destroy_workqueue(recv_workqueue);
+	if (register_blkdev(NBD_MAJOR, "nbd"))
 		return -EIO;
-	}
 
 	if (genl_register_family(&nbd_genl_family)) {
 		unregister_blkdev(NBD_MAJOR, "nbd");
-		destroy_workqueue(recv_workqueue);
 		return -EINVAL;
 	}
 	nbd_dbg_init();
@@ -2271,7 +2283,6 @@ static void __exit nbd_cleanup(void)
 
 	idr_destroy(&nbd_index_idr);
 	genl_unregister_family(&nbd_genl_family);
-	destroy_workqueue(recv_workqueue);
 	unregister_blkdev(NBD_MAJOR, "nbd");
 }
 
-- 
2.20.1




  parent reply	other threads:[~2019-10-10  8:51 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  8:36 [PATCH 4.14 00/61] 4.14.149-stable review Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 01/61] s390/process: avoid potential reading of freed stack Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 02/61] KVM: s390: Test for bad access register and size at the start of S390_MEM_OP Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 03/61] s390/topology: avoid firing events before kobjs are created Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 04/61] s390/cio: avoid calling strlen on null pointer Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 05/61] s390/cio: exclude subchannels with no parent from pseudo check Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 06/61] KVM: PPC: Book3S HV: Dont lose pending doorbell request on migration on P9 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 07/61] KVM: nVMX: handle page fault in vmread fix Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 08/61] PM / devfreq: tegra: Fix kHz to Hz conversion Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 09/61] ASoC: Define a set of DAPM pre/post-up events Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 10/61] powerpc/powernv: Restrict OPAL symbol map to only be readable by root Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 11/61] can: mcp251x: mcp251x_hw_reset(): allow more time after a reset Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 12/61] tools lib traceevent: Fix "robust" test of do_generate_dynamic_list_file Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 13/61] crypto: qat - Silence smp_processor_id() warning Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 14/61] crypto: skcipher - Unmap pages after an external error Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 15/61] crypto: cavium/zip - Add missing single_release() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 16/61] crypto: caam - fix concurrency issue in givencrypt descriptor Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 17/61] MIPS: Treat Loongson Extensions as ASEs Greg Kroah-Hartman
2019-10-11  4:30   ` Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 18/61] usercopy: Avoid HIGHMEM pfn warning Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 19/61] timer: Read jiffies once when forwarding base clk Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 20/61] watchdog: imx2_wdt: fix min() calculation in imx2_wdt_set_timeout Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 21/61] drm/omap: fix max fclk divider for omap36xx Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 22/61] mmc: sdhci: improve ADMA error reporting Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 23/61] mmc: sdhci-of-esdhc: set DMA snooping based on DMA coherence Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 24/61] Revert "locking/pvqspinlock: Dont wait if vCPU is preempted" Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 25/61] xen/xenbus: fix self-deadlock after killing user process Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 26/61] ieee802154: atusb: fix use-after-free at disconnect Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 27/61] cfg80211: initialize on-stack chandefs Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 28/61] ima: always return negative code for error Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 29/61] fs: nfs: Fix possible null-pointer dereferences in encode_attrs() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 30/61] 9p: avoid attaching writeback_fid on mmap with type PRIVATE Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 31/61] xen/pci: reserve MCFG areas earlier Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 32/61] ceph: fix directories inode i_blkbits initialization Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 33/61] ceph: reconnect connection if session hang in opening state Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.14 34/61] watchdog: aspeed: Add support for AST2600 Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 35/61] netfilter: nf_tables: allow lookups in dynamic sets Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 36/61] drm/amdgpu: Check for valid number of registers to read Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 37/61] pNFS: Ensure we do clear the return-on-close layout stateid on fatal errors Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 38/61] pwm: stm32-lp: Add check in case requested period cannot be achieved Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 39/61] thermal: Fix use-after-free when unregistering thermal zone device Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 40/61] fuse: fix memleak in cuse_channel_open Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 41/61] sched/core: Fix migration to invalid CPU in __set_cpus_allowed_ptr() Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 42/61] perf build: Add detection of java-11-openjdk-devel package Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 43/61] kernel/elfcore.c: include proper prototypes Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 44/61] perf unwind: Fix libunwind build failure on i386 systems Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 45/61] KVM: PPC: Book3S HV: XIVE: Free escalation interrupts before disabling the VP Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 46/61] nbd: fix crash when the blksize is zero Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 47/61] block/ndb: add WQ_UNBOUND to the knbd-recv workqueue Greg Kroah-Hartman
2019-10-10  8:37 ` Greg Kroah-Hartman [this message]
2019-10-10  8:37 ` [PATCH 4.14 49/61] powerpc/pseries: Fix cpu_hotplug_lock acquisition in resize_hpt() Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 50/61] tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on failure Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 51/61] tick: broadcast-hrtimer: Fix a race in bc_set_next Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 53/61] perf stat: Fix a segmentation fault when using repeat forever Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 54/61] perf stat: Reset previous counts on repeat with interval Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 55/61] drm/i915/userptr: Acquire the page lock around set_page_dirty() Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 56/61] vfs: Fix EOVERFLOW testing in put_compat_statfs64 Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 57/61] coresight: etm4x: Use explicit barriers on enable/disable Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 58/61] cfg80211: add and use strongly typed element iteration macros Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 59/61] cfg80211: Use const more consistently in for_each_element macros Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 60/61] nl80211: validate beacon head Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.14 61/61] ASoC: sgtl5000: Improve VAG power and mute control Greg Kroah-Hartman
2019-10-10 13:27 ` [PATCH 4.14 00/61] 4.14.149-stable review Naresh Kamboju
2019-10-10 14:21 ` kernelci.org bot
2019-10-10 17:12 ` Guenter Roeck
2019-10-11  4:29   ` Greg Kroah-Hartman
2019-10-11 13:14     ` Guenter Roeck
2019-10-11 14:01       ` Greg Kroah-Hartman
2019-10-10 22:18 ` Guenter Roeck
2019-10-10 23:50 ` Didik Setiawan
2019-10-11  3:09 ` shuah
2019-10-11  8:33 ` Jon Hunter

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=20191010083519.876334933@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=axboe@kernel.dk \
    --cc=josef@toxicpanda.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchristi@redhat.com \
    --cc=sashal@kernel.org \
    --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).