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, Igor Pylypiv <ipylypiv@google.com>,
	Changyuan Lyu <changyuanl@google.com>,
	Luis Chamberlain <mcgrof@kernel.org>, Tejun Heo <tj@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.4 22/80] Revert "module, async: async_synchronize_full() on module init iff async is used"
Date: Mon, 21 Feb 2022 09:49:02 +0100	[thread overview]
Message-ID: <20220221084916.312284506@linuxfoundation.org> (raw)
In-Reply-To: <20220221084915.554151737@linuxfoundation.org>

From: Igor Pylypiv <ipylypiv@google.com>

[ Upstream commit 67d6212afda218d564890d1674bab28e8612170f ]

This reverts commit 774a1221e862b343388347bac9b318767336b20b.

We need to finish all async code before the module init sequence is
done.  In the reverted commit the PF_USED_ASYNC flag was added to mark a
thread that called async_schedule().  Then the PF_USED_ASYNC flag was
used to determine whether or not async_synchronize_full() needs to be
invoked.  This works when modprobe thread is calling async_schedule(),
but it does not work if module dispatches init code to a worker thread
which then calls async_schedule().

For example, PCI driver probing is invoked from a worker thread based on
a node where device is attached:

	if (cpu < nr_cpu_ids)
		error = work_on_cpu(cpu, local_pci_probe, &ddi);
	else
		error = local_pci_probe(&ddi);

We end up in a situation where a worker thread gets the PF_USED_ASYNC
flag set instead of the modprobe thread.  As a result,
async_synchronize_full() is not invoked and modprobe completes without
waiting for the async code to finish.

The issue was discovered while loading the pm80xx driver:
(scsi_mod.scan=async)

modprobe pm80xx                      worker
...
  do_init_module()
  ...
    pci_call_probe()
      work_on_cpu(local_pci_probe)
                                     local_pci_probe()
                                       pm8001_pci_probe()
                                         scsi_scan_host()
                                           async_schedule()
                                           worker->flags |= PF_USED_ASYNC;
                                     ...
      < return from worker >
  ...
  if (current->flags & PF_USED_ASYNC) <--- false
  	async_synchronize_full();

Commit 21c3c5d28007 ("block: don't request module during elevator init")
fixed the deadlock issue which the reverted commit 774a1221e862
("module, async: async_synchronize_full() on module init iff async is
used") tried to fix.

Since commit 0fdff3ec6d87 ("async, kmod: warn on synchronous
request_module() from async workers") synchronous module loading from
async is not allowed.

Given that the original deadlock issue is fixed and it is no longer
allowed to call synchronous request_module() from async we can remove
PF_USED_ASYNC flag to make module init consistently invoke
async_synchronize_full() unless async module probe is requested.

Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
Reviewed-by: Changyuan Lyu <changyuanl@google.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 include/linux/sched.h |    1 -
 kernel/async.c        |    3 ---
 kernel/module.c       |   25 +++++--------------------
 3 files changed, 5 insertions(+), 24 deletions(-)

--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1454,7 +1454,6 @@ extern struct pid *cad_pid;
 #define PF_MEMALLOC		0x00000800	/* Allocating memory */
 #define PF_NPROC_EXCEEDED	0x00001000	/* set_user() noticed that RLIMIT_NPROC was exceeded */
 #define PF_USED_MATH		0x00002000	/* If unset the fpu must be initialized before use */
-#define PF_USED_ASYNC		0x00004000	/* Used async_schedule*(), used by module init */
 #define PF_NOFREEZE		0x00008000	/* This thread should not be frozen */
 #define PF_FROZEN		0x00010000	/* Frozen for system suspend */
 #define PF_KSWAPD		0x00020000	/* I am kswapd */
--- a/kernel/async.c
+++ b/kernel/async.c
@@ -205,9 +205,6 @@ async_cookie_t async_schedule_node_domai
 	atomic_inc(&entry_count);
 	spin_unlock_irqrestore(&async_lock, flags);
 
-	/* mark that this task has queued an async job, used by module init */
-	current->flags |= PF_USED_ASYNC;
-
 	/* schedule for execution */
 	queue_work_node(node, system_unbound_wq, &entry->work);
 
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3711,12 +3711,6 @@ static noinline int do_init_module(struc
 	}
 	freeinit->module_init = mod->init_layout.base;
 
-	/*
-	 * We want to find out whether @mod uses async during init.  Clear
-	 * PF_USED_ASYNC.  async_schedule*() will set it.
-	 */
-	current->flags &= ~PF_USED_ASYNC;
-
 	do_mod_ctors(mod);
 	/* Start the module */
 	if (mod->init != NULL)
@@ -3742,22 +3736,13 @@ static noinline int do_init_module(struc
 
 	/*
 	 * We need to finish all async code before the module init sequence
-	 * is done.  This has potential to deadlock.  For example, a newly
-	 * detected block device can trigger request_module() of the
-	 * default iosched from async probing task.  Once userland helper
-	 * reaches here, async_synchronize_full() will wait on the async
-	 * task waiting on request_module() and deadlock.
-	 *
-	 * This deadlock is avoided by perfomring async_synchronize_full()
-	 * iff module init queued any async jobs.  This isn't a full
-	 * solution as it will deadlock the same if module loading from
-	 * async jobs nests more than once; however, due to the various
-	 * constraints, this hack seems to be the best option for now.
-	 * Please refer to the following thread for details.
+	 * is done. This has potential to deadlock if synchronous module
+	 * loading is requested from async (which is not allowed!).
 	 *
-	 * http://thread.gmane.org/gmane.linux.kernel/1420814
+	 * See commit 0fdff3ec6d87 ("async, kmod: warn on synchronous
+	 * request_module() from async workers") for more details.
 	 */
-	if (!mod->async_probe_requested && (current->flags & PF_USED_ASYNC))
+	if (!mod->async_probe_requested)
 		async_synchronize_full();
 
 	ftrace_free_mem(mod, mod->init_layout.base, mod->init_layout.base +



  parent reply	other threads:[~2022-02-21  9:03 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21  8:48 [PATCH 5.4 00/80] 5.4.181-rc1 review Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 01/80] Makefile.extrawarn: Move -Wunaligned-access to W=1 Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 02/80] HID:Add support for UGTABLET WP5540 Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 03/80] Revert "svm: Add warning message for AVIC IPI invalid target" Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 04/80] serial: parisc: GSC: fix build when IOSAPIC is not set Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 05/80] parisc: Drop __init from map_pages declaration Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 06/80] parisc: Fix data TLB miss in sba_unmap_sg Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 07/80] parisc: Fix sglist access in ccio-dma.c Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 08/80] btrfs: send: in case of IO error log it Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 09/80] platform/x86: ISST: Fix possible circular locking dependency detected Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 10/80] selftests: rtc: Increase test timeout so that all tests run Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 11/80] net: ieee802154: at86rf230: Stop leaking skbs Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 12/80] selftests/zram: Skip max_comp_streams interface on newer kernel Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 13/80] selftests/zram01.sh: Fix compression ratio calculation Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 14/80] selftests/zram: Adapt the situation that /dev/zram0 is being used Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 15/80] ax25: improve the incomplete fix to avoid UAF and NPD bugs Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 16/80] vfs: make freeze_super abort when sync_filesystem returns error Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 17/80] quota: make dquot_quota_sync return errors from ->sync_fs Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 18/80] nvme: fix a possible use-after-free in controller reset during load Greg Kroah-Hartman
2022-02-21  8:48 ` [PATCH 5.4 19/80] nvme-tcp: fix possible use-after-free in transport error_recovery work Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 20/80] nvme-rdma: " Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 21/80] drm/amdgpu: fix logic inversion in check Greg Kroah-Hartman
2022-02-21  8:49 ` Greg Kroah-Hartman [this message]
2022-02-21  8:49 ` [PATCH 5.4 23/80] ftrace: add ftrace_init_nop() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 24/80] module/ftrace: handle patchable-function-entry Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 25/80] arm64: module: rework special section handling Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 26/80] arm64: module/ftrace: intialize PLT at load time Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 27/80] iwlwifi: fix use-after-free Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 28/80] drm/radeon: Fix backlight control on iMac 12,1 Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 29/80] ext4: check for out-of-order index extents in ext4_valid_extent_entries() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 30/80] ext4: check for inconsistent extents between index and leaf block Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 31/80] ext4: prevent partial update of the extent blocks Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 32/80] taskstats: Cleanup the use of task->exit_code Greg Kroah-Hartman
2022-02-21 22:46   ` Dr. Thomas Orgis
2022-02-22 23:53     ` Eric W. Biederman
2022-02-23 22:40       ` Dr. Thomas Orgis
2022-02-25  0:23         ` Eric W. Biederman
2022-02-21  8:49 ` [PATCH 5.4 33/80] dmaengine: at_xdmac: Start transfer for cyclic channels in issue_pending Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 34/80] vsock: remove vsock from connected table when connect is interrupted by a signal Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 35/80] mmc: block: fix read single on recovery logic Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 36/80] iwlwifi: pcie: fix locking when "HW not ready" Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 37/80] iwlwifi: pcie: gen2: " Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 38/80] netfilter: nft_synproxy: unregister hooks on init error path Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 39/80] net: dsa: lan9303: fix reset on probe Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 40/80] net: ieee802154: ca8210: Fix lifs/sifs periods Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 41/80] ping: fix the dif and sdif check in ping_lookup Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 42/80] bonding: force carrier update when releasing slave Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 43/80] drop_monitor: fix data-race in dropmon_net_event / trace_napi_poll_hit Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 44/80] bonding: fix data-races around agg_select_timer Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 45/80] libsubcmd: Fix use-after-free for realloc(..., 0) Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 46/80] ALSA: hda: Fix regression on forced probe mask option Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 47/80] ALSA: hda: Fix missing codec probe on Shenker Dock 15 Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 48/80] ASoC: ops: Fix stereo change notifications in snd_soc_put_volsw() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 49/80] ASoC: ops: Fix stereo change notifications in snd_soc_put_volsw_range() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 50/80] powerpc/lib/sstep: fix ptesync build error Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 51/80] mtd: rawnand: gpmi: dont leak PM reference in error path Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 52/80] tee: export teedev_open() and teedev_close_context() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 53/80] optee: use driver internal tee_context for some rpc Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 54/80] block/wbt: fix negative inflight counter when remove scsi device Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 55/80] NFS: LOOKUP_DIRECTORY is also ok with symlinks Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 56/80] NFS: Do not report writeback errors in nfs_getattr() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 57/80] mtd: rawnand: qcom: Fix clock sequencing in qcom_nandc_probe() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 58/80] mtd: rawnand: brcmnand: Fixed incorrect sub-page ECC status Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 59/80] scsi: lpfc: Fix pt2pt NVMe PRLI reject LOGO loop Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 60/80] EDAC: Fix calculation of returned address and next offset in edac_align_ptr() Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 61/80] net: sched: limit TC_ACT_REPEAT loops Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 62/80] dmaengine: sh: rcar-dmac: Check for error num after setting mask Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 63/80] copy_process(): Move fd_install() out of sighand->siglock critical section Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 64/80] i2c: brcmstb: fix support for DSL and CM variants Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 65/80] Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 66/80] KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 67/80] ARM: OMAP2+: hwmod: Add of_node_put() before break Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 68/80] ARM: OMAP2+: adjust the location of put_device() call in omapdss_init_of Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 69/80] irqchip/sifive-plic: Add missing thead,c900-plic match string Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 70/80] netfilter: conntrack: dont refresh sctp entries in closed state Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 71/80] arm64: dts: meson-gx: add ATF BL32 reserved-memory region Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 72/80] arm64: dts: meson-g12: " Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 73/80] arm64: dts: meson-g12: drop BL32 region from SEI510/SEI610 Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 74/80] kconfig: let shell return enough output for deep path names Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 75/80] ata: libata-core: Disable TRIM on M88V29 Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 76/80] drm/rockchip: dw_hdmi: Do not leave clock enabled in error case Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 77/80] tracing: Fix tp_printk option related with tp_printk_stop_on_boot Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 78/80] net: usb: qmi_wwan: Add support for Dell DW5829e Greg Kroah-Hartman
2022-02-21  8:49 ` [PATCH 5.4 79/80] net: macb: Align the dma and coherent dma masks Greg Kroah-Hartman
2022-02-21  8:50 ` [PATCH 5.4 80/80] kconfig: fix failing to generate auto.conf Greg Kroah-Hartman
2022-02-21 21:18 ` [PATCH 5.4 00/80] 5.4.181-rc1 review Guenter Roeck
2022-02-21 21:38 ` Shuah Khan
2022-02-22  3:19 ` Slade Watkins
2022-02-22  3:25 ` Florian Fainelli
2022-02-22  6:54 ` Naresh Kamboju
2022-02-22 12:04 ` Sudip Mukherjee
2022-02-22 12:07 ` Jon Hunter
2022-02-23  0:54 ` Samuel Zou

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=20220221084916.312284506@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=changyuanl@google.com \
    --cc=ipylypiv@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.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).