diff mbox series

aoe: Avoid flush_scheduled_work() usage

Message ID 9d1759e0-2f93-d49f-48b3-12b8d47e95cd@I-love.SAKURA.ne.jp (mailing list archive)
State New, archived
Headers show
Series aoe: Avoid flush_scheduled_work() usage | expand

Commit Message

Tetsuo Handa April 18, 2022, 2:03 p.m. UTC
Flushing system-wide workqueues is dangerous and will be forbidden.
Replace system_wq with local aoe_wq.

Link: https://lkml.kernel.org/r/49925af7-78a8-a3dd-bce6-cfc02e1a9236@I-love.SAKURA.ne.jp
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
Note: This patch is only compile tested.

 drivers/block/aoe/aoe.h     | 2 ++
 drivers/block/aoe/aoeblk.c  | 2 +-
 drivers/block/aoe/aoecmd.c  | 2 +-
 drivers/block/aoe/aoedev.c  | 4 ++--
 drivers/block/aoe/aoemain.c | 9 ++++++++-
 5 files changed, 14 insertions(+), 5 deletions(-)

Comments

kernel test robot April 18, 2022, 10:58 p.m. UTC | #1
Hi Tetsuo,

I love your patch! Yet something to improve:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on v5.18-rc3 next-20220414]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Tetsuo-Handa/aoe-Avoid-flush_scheduled_work-usage/20220418-231118
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: arc-randconfig-r023-20220419 (https://download.01.org/0day-ci/archive/20220419/202204190659.PmftNpOE-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/b1ae05b7bd5a2a2abad4aba03f55e7f4b4599789
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Tetsuo-Handa/aoe-Avoid-flush_scheduled_work-usage/20220418-231118
        git checkout b1ae05b7bd5a2a2abad4aba03f55e7f4b4599789
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arceb-elf-ld: drivers/block/aoe/aoeblk.o: in function `queue_work':
>> include/linux/workqueue.h:502: undefined reference to `aoe_wq'
>> arceb-elf-ld: include/linux/workqueue.h:502: undefined reference to `aoe_wq'
   arceb-elf-ld: drivers/block/aoe/aoecmd.o: in function `queue_work':
>> include/linux/workqueue.h:502: undefined reference to `aoe_wq'
>> arceb-elf-ld: include/linux/workqueue.h:502: undefined reference to `aoe_wq'
   arceb-elf-ld: drivers/block/aoe/aoedev.o: in function `flush':
>> drivers/block/aoe/aoedev.c:324: undefined reference to `aoe_wq'
   arceb-elf-ld: drivers/block/aoe/aoedev.o:drivers/block/aoe/aoedev.c:324: more undefined references to `aoe_wq' follow


vim +502 include/linux/workqueue.h

dcd989cb73ab0f Tejun Heo    2010-06-29  475  
8425e3d5bdbe8e Tejun Heo    2013-03-13  476  /**
8425e3d5bdbe8e Tejun Heo    2013-03-13  477   * queue_work - queue work on a workqueue
8425e3d5bdbe8e Tejun Heo    2013-03-13  478   * @wq: workqueue to use
8425e3d5bdbe8e Tejun Heo    2013-03-13  479   * @work: work to queue
8425e3d5bdbe8e Tejun Heo    2013-03-13  480   *
8425e3d5bdbe8e Tejun Heo    2013-03-13  481   * Returns %false if @work was already on a queue, %true otherwise.
8425e3d5bdbe8e Tejun Heo    2013-03-13  482   *
8425e3d5bdbe8e Tejun Heo    2013-03-13  483   * We queue the work to the CPU on which it was submitted, but if the CPU dies
8425e3d5bdbe8e Tejun Heo    2013-03-13  484   * it can be processed by another CPU.
dbb92f88648d62 Andrea Parri 2020-01-22  485   *
dbb92f88648d62 Andrea Parri 2020-01-22  486   * Memory-ordering properties:  If it returns %true, guarantees that all stores
dbb92f88648d62 Andrea Parri 2020-01-22  487   * preceding the call to queue_work() in the program order will be visible from
dbb92f88648d62 Andrea Parri 2020-01-22  488   * the CPU which will execute @work by the time such work executes, e.g.,
dbb92f88648d62 Andrea Parri 2020-01-22  489   *
dbb92f88648d62 Andrea Parri 2020-01-22  490   * { x is initially 0 }
dbb92f88648d62 Andrea Parri 2020-01-22  491   *
dbb92f88648d62 Andrea Parri 2020-01-22  492   *   CPU0				CPU1
dbb92f88648d62 Andrea Parri 2020-01-22  493   *
dbb92f88648d62 Andrea Parri 2020-01-22  494   *   WRITE_ONCE(x, 1);			[ @work is being executed ]
dbb92f88648d62 Andrea Parri 2020-01-22  495   *   r0 = queue_work(wq, work);		  r1 = READ_ONCE(x);
dbb92f88648d62 Andrea Parri 2020-01-22  496   *
dbb92f88648d62 Andrea Parri 2020-01-22  497   * Forbids: r0 == true && r1 == 0
8425e3d5bdbe8e Tejun Heo    2013-03-13  498   */
8425e3d5bdbe8e Tejun Heo    2013-03-13  499  static inline bool queue_work(struct workqueue_struct *wq,
8425e3d5bdbe8e Tejun Heo    2013-03-13  500  			      struct work_struct *work)
8425e3d5bdbe8e Tejun Heo    2013-03-13  501  {
8425e3d5bdbe8e Tejun Heo    2013-03-13 @502  	return queue_work_on(WORK_CPU_UNBOUND, wq, work);
8425e3d5bdbe8e Tejun Heo    2013-03-13  503  }
8425e3d5bdbe8e Tejun Heo    2013-03-13  504
diff mbox series

Patch

diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 84d0fcebd6af..749ae1246f4c 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -244,3 +244,5 @@  void aoenet_exit(void);
 void aoenet_xmit(struct sk_buff_head *);
 int is_aoe_netif(struct net_device *ifp);
 int set_aoe_iflist(const char __user *str, size_t size);
+
+extern struct workqueue_struct *aoe_wq;
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index 8a91fcac6f82..348adf335217 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -435,7 +435,7 @@  aoeblk_gdalloc(void *vp)
 err:
 	spin_lock_irqsave(&d->lock, flags);
 	d->flags &= ~DEVFL_GD_NOW;
-	schedule_work(&d->work);
+	queue_work(aoe_wq, &d->work);
 	spin_unlock_irqrestore(&d->lock, flags);
 }
 
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 384073ef2323..d7317425be51 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -968,7 +968,7 @@  ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id)
 		d->flags |= DEVFL_NEWSIZE;
 	else
 		d->flags |= DEVFL_GDALLOC;
-	schedule_work(&d->work);
+	queue_work(aoe_wq, &d->work);
 }
 
 static void
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index c5753c6bfe80..b381d1c3ef32 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -321,7 +321,7 @@  flush(const char __user *str, size_t cnt, int exiting)
 			specified = 1;
 	}
 
-	flush_scheduled_work();
+	flush_workqueue(aoe_wq);
 	/* pass one: do aoedev_downdev, which might sleep */
 restart1:
 	spin_lock_irqsave(&devlist_lock, flags);
@@ -520,7 +520,7 @@  freetgt(struct aoedev *d, struct aoetgt *t)
 void
 aoedev_exit(void)
 {
-	flush_scheduled_work();
+	flush_workqueue(aoe_wq);
 	flush(NULL, 0, EXITING);
 }
 
diff --git a/drivers/block/aoe/aoemain.c b/drivers/block/aoe/aoemain.c
index 1e4e2971171c..892d627a2379 100644
--- a/drivers/block/aoe/aoemain.c
+++ b/drivers/block/aoe/aoemain.c
@@ -35,6 +35,7 @@  aoe_exit(void)
 	aoechr_exit();
 	aoedev_exit();
 	aoeblk_exit();		/* free cache after de-allocating bufs */
+	destroy_workqueue(aoe_wq);
 }
 
 static int __init
@@ -42,9 +43,13 @@  aoe_init(void)
 {
 	int ret;
 
+	aoe_wq = alloc_workqueue("aoe_wq", 0, 0);
+	if (!aoe_wq)
+		return -ENOMEM;
+
 	ret = aoedev_init();
 	if (ret)
-		return ret;
+		goto dev_fail;
 	ret = aoechr_init();
 	if (ret)
 		goto chr_fail;
@@ -77,6 +82,8 @@  aoe_init(void)
 	aoechr_exit();
  chr_fail:
 	aoedev_exit();
+ dev_fail:
+	destroy_workqueue(aoe_wq);
 
 	printk(KERN_INFO "aoe: initialisation failure.\n");
 	return ret;