mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Carl Love <carll@us.ibm.com>,
	Robert Richter <robert.richter@amd.com>
Subject: [73/89] oprofile: Fix locking dependency in sync_start()
Date: Wed, 15 Jun 2011 17:00:36 -0700	[thread overview]
Message-ID: <20110616000236.153229699@clark.kroah.org> (raw)
In-Reply-To: <20110616000258.GA14529@kroah.com>

2.6.39-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Robert Richter <robert.richter@amd.com>

commit 130c5ce716c9bfd1c2a2ec840a746eb7ff9ce1e6 upstream.

This fixes the A->B/B->A locking dependency, see the warning below.

The function task_exit_notify() is called with (task_exit_notifier)
.rwsem set and then calls sync_buffer() which locks buffer_mutex. In
sync_start() the buffer_mutex was set to prevent notifier functions to
be started before sync_start() is finished. But when registering the
notifier, (task_exit_notifier).rwsem is locked too, but now in
different order than in sync_buffer(). In theory this causes a locking
dependency, what does not occur in practice since task_exit_notify()
is always called after the notifier is registered which means the lock
is already released.

However, after checking the notifier functions it turned out the
buffer_mutex in sync_start() is unnecessary. This is because
sync_buffer() may be called from the notifiers even if sync_start()
did not finish yet, the buffers are already allocated but empty. No
need to protect this with the mutex.

So we fix this theoretical locking dependency by removing buffer_mutex
in sync_start(). This is similar to the implementation before commit:

 750d857 oprofile: fix crash when accessing freed task structs

which introduced the locking dependency.

Lockdep warning:

oprofiled/4447 is trying to acquire lock:
 (buffer_mutex){+.+...}, at: [<ffffffffa0000e55>] sync_buffer+0x31/0x3ec [oprofile]

but task is already holding lock:
 ((task_exit_notifier).rwsem){++++..}, at: [<ffffffff81058026>] __blocking_notifier_call_chain+0x39/0x67

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 ((task_exit_notifier).rwsem){++++..}:
       [<ffffffff8106557f>] lock_acquire+0xf8/0x11e
       [<ffffffff81463a2b>] down_write+0x44/0x67
       [<ffffffff810581c0>] blocking_notifier_chain_register+0x52/0x8b
       [<ffffffff8105a6ac>] profile_event_register+0x2d/0x2f
       [<ffffffffa00013c1>] sync_start+0x47/0xc6 [oprofile]
       [<ffffffffa00001bb>] oprofile_setup+0x60/0xa5 [oprofile]
       [<ffffffffa00014e3>] event_buffer_open+0x59/0x8c [oprofile]
       [<ffffffff810cd3b9>] __dentry_open+0x1eb/0x308
       [<ffffffff810cd59d>] nameidata_to_filp+0x60/0x67
       [<ffffffff810daad6>] do_last+0x5be/0x6b2
       [<ffffffff810dbc33>] path_openat+0xc7/0x360
       [<ffffffff810dbfc5>] do_filp_open+0x3d/0x8c
       [<ffffffff810ccfd2>] do_sys_open+0x110/0x1a9
       [<ffffffff810cd09e>] sys_open+0x20/0x22
       [<ffffffff8146ad4b>] system_call_fastpath+0x16/0x1b

-> #0 (buffer_mutex){+.+...}:
       [<ffffffff81064dfb>] __lock_acquire+0x1085/0x1711
       [<ffffffff8106557f>] lock_acquire+0xf8/0x11e
       [<ffffffff814634f0>] mutex_lock_nested+0x63/0x309
       [<ffffffffa0000e55>] sync_buffer+0x31/0x3ec [oprofile]
       [<ffffffffa0001226>] task_exit_notify+0x16/0x1a [oprofile]
       [<ffffffff81467b96>] notifier_call_chain+0x37/0x63
       [<ffffffff8105803d>] __blocking_notifier_call_chain+0x50/0x67
       [<ffffffff81058068>] blocking_notifier_call_chain+0x14/0x16
       [<ffffffff8105a718>] profile_task_exit+0x1a/0x1c
       [<ffffffff81039e8f>] do_exit+0x2a/0x6fc
       [<ffffffff8103a5e4>] do_group_exit+0x83/0xae
       [<ffffffff8103a626>] sys_exit_group+0x17/0x1b
       [<ffffffff8146ad4b>] system_call_fastpath+0x16/0x1b

other info that might help us debug this:

1 lock held by oprofiled/4447:
 #0:  ((task_exit_notifier).rwsem){++++..}, at: [<ffffffff81058026>] __blocking_notifier_call_chain+0x39/0x67

stack backtrace:
Pid: 4447, comm: oprofiled Not tainted 2.6.39-00007-gcf4d8d4 #10
Call Trace:
 [<ffffffff81063193>] print_circular_bug+0xae/0xbc
 [<ffffffff81064dfb>] __lock_acquire+0x1085/0x1711
 [<ffffffffa0000e55>] ? sync_buffer+0x31/0x3ec [oprofile]
 [<ffffffff8106557f>] lock_acquire+0xf8/0x11e
 [<ffffffffa0000e55>] ? sync_buffer+0x31/0x3ec [oprofile]
 [<ffffffff81062627>] ? mark_lock+0x42f/0x552
 [<ffffffffa0000e55>] ? sync_buffer+0x31/0x3ec [oprofile]
 [<ffffffff814634f0>] mutex_lock_nested+0x63/0x309
 [<ffffffffa0000e55>] ? sync_buffer+0x31/0x3ec [oprofile]
 [<ffffffffa0000e55>] sync_buffer+0x31/0x3ec [oprofile]
 [<ffffffff81058026>] ? __blocking_notifier_call_chain+0x39/0x67
 [<ffffffff81058026>] ? __blocking_notifier_call_chain+0x39/0x67
 [<ffffffffa0001226>] task_exit_notify+0x16/0x1a [oprofile]
 [<ffffffff81467b96>] notifier_call_chain+0x37/0x63
 [<ffffffff8105803d>] __blocking_notifier_call_chain+0x50/0x67
 [<ffffffff81058068>] blocking_notifier_call_chain+0x14/0x16
 [<ffffffff8105a718>] profile_task_exit+0x1a/0x1c
 [<ffffffff81039e8f>] do_exit+0x2a/0x6fc
 [<ffffffff81465031>] ? retint_swapgs+0xe/0x13
 [<ffffffff8103a5e4>] do_group_exit+0x83/0xae
 [<ffffffff8103a626>] sys_exit_group+0x17/0x1b
 [<ffffffff8146ad4b>] system_call_fastpath+0x16/0x1b

Reported-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Carl Love <carll@us.ibm.com>
Signed-off-by: Robert Richter <robert.richter@amd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/oprofile/buffer_sync.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -155,8 +155,6 @@ int sync_start(void)
 	if (!zalloc_cpumask_var(&marked_cpus, GFP_KERNEL))
 		return -ENOMEM;
 
-	mutex_lock(&buffer_mutex);
-
 	err = task_handoff_register(&task_free_nb);
 	if (err)
 		goto out1;
@@ -173,7 +171,6 @@ int sync_start(void)
 	start_cpu_work();
 
 out:
-	mutex_unlock(&buffer_mutex);
 	return err;
 out4:
 	profile_event_unregister(PROFILE_MUNMAP, &munmap_nb);
@@ -190,14 +187,13 @@ out1:
 
 void sync_stop(void)
 {
-	/* flush buffers */
-	mutex_lock(&buffer_mutex);
 	end_cpu_work();
 	unregister_module_notifier(&module_load_nb);
 	profile_event_unregister(PROFILE_MUNMAP, &munmap_nb);
 	profile_event_unregister(PROFILE_TASK_EXIT, &task_exit_nb);
 	task_handoff_unregister(&task_free_nb);
-	mutex_unlock(&buffer_mutex);
+	barrier();			/* do all of the above first */
+
 	flush_cpu_work();
 
 	free_all_tasks();



  parent reply	other threads:[~2011-06-16  7:31 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16  0:02 [00/89] 2.6.39.2-stable review Greg KH
2011-06-15 23:59 ` [01/89] lguest: fix timer interrupt setup Greg KH
2011-06-15 23:59 ` [02/89] intel-iommu: Flush unmaps at domain_exit Greg KH
2011-06-15 23:59 ` [03/89] intel-iommu: Only unlink device domains from iommu Greg KH
2011-06-15 23:59 ` [04/89] intel-iommu: Check for identity mapping candidate using Greg KH
2011-06-15 23:59 ` [05/89] intel-iommu: Speed up processing of the identity_mapping Greg KH
2011-06-15 23:59 ` [06/89] intel-iommu: Dont cache iova above 32bit Greg KH
2011-06-15 23:59 ` [07/89] intel-iommu: Use coherent DMA mask when requested Greg KH
2011-06-15 23:59 ` [08/89] intel-iommu: Remove Host Bridge devices from identity Greg KH
2011-06-15 23:59 ` [09/89] intel-iommu: Add domain check in domain_remove_one_dev_info Greg KH
2011-06-15 23:59 ` [10/89] powerpc/4xx: Fix regression in SMP on 476 Greg KH
2011-06-15 23:59 ` [11/89] arch/tile: allocate PCI IRQs later in boot Greg KH
2011-06-15 23:59 ` [12/89] UBIFS: fix shrinker object count reports Greg KH
2011-06-15 23:59 ` [13/89] UBIFS: fix memory leak on error path Greg KH
2011-06-15 23:59 ` [14/89] block: blkdev_get() should access ->bd_disk only after Greg KH
2011-06-15 23:59 ` [15/89] nbd: limit module parameters to a sane value Greg KH
2011-06-15 23:59 ` [16/89] [SCSI] Fix oops caused by queue refcounting failure Greg KH
2011-06-15 23:59 ` [17/89] ath9k: Reset chip on baseband hang Greg KH
2011-06-15 23:59 ` [18/89] ath9k: set 40 Mhz rate only if hw is configured in ht40 Greg KH
2011-06-15 23:59 ` [19/89] ath9k: fix two more bugs in tx power Greg KH
2011-06-15 23:59 ` [20/89] hwmon: (coretemp) Fix TjMax detection for older CPUs Greg KH
2011-06-15 23:59 ` [21/89] hwmon: (coretemp) Relax target temperature range check Greg KH
2011-06-15 23:59 ` [22/89] iwl4965: fix 5GHz operation Greg KH
2011-06-15 23:59 ` [23/89] iwl4965: correctly validate temperature value Greg KH
2011-06-15 23:59 ` [24/89] zd1211rw: fix to work on OHCI Greg KH
2011-06-15 23:59 ` [25/89] mm: fix ENOSPC returned by handle_mm_fault() Greg KH
2011-06-15 23:59 ` [26/89] serial: core, move termios handling to uart_startup Greg KH
2011-06-15 23:59 ` [27/89] serial: core, do not set DTR/RTS twice on startup Greg KH
2011-06-15 23:59 ` [28/89] serial: core, remove uart_update_termios Greg KH
2011-06-15 23:59 ` [29/89] PCI: Set PCIE maxpayload for card during hotplug insertion Greg KH
2011-06-15 23:59 ` [30/89] powerpc: Fix 32-bit SMP build Greg KH
2011-06-15 23:59 ` [31/89] asus-wmi: Remove __init from asus_wmi_platform_init Greg KH
2011-06-15 23:59 ` [32/89] nl80211: fix check for valid SSID size in scan operations Greg KH
2011-06-15 23:59 ` [33/89] block: export blk_{get,put}_queue() Greg KH
2011-06-15 23:59 ` [34/89] usbnet/cdc_ncm: add missing .reset_resume hook Greg KH
2011-06-15 23:59 ` [35/89] lockdep: Fix lock_is_held() on recursion Greg KH
2011-06-15 23:59 ` [36/89] drm/i915: Add a no lvds quirk for the Asus EeeBox PC EB1007 Greg KH
2011-06-16  0:00 ` [37/89] drm/radeon/kms: viewport height has to be even Greg KH
2011-06-16  0:00 ` [38/89] drm/radeon/kms: fix for radeon on systems >4GB without Greg KH
2011-06-16  0:00 ` [39/89] fat: Fix corrupt inode flags when remove ATTR_SYS flag Greg KH
2011-06-16  0:00 ` [40/89] xen: off by one errors in multicalls.c Greg KH
2011-06-16  0:00 ` [51/89] option: add Zoom 4597 modem USB IDs Greg KH
2011-06-16  0:00 ` [52/89] option: add Alcatel X200 to sendsetup blacklist Greg KH
2011-06-16  0:00 ` [53/89] option: add Prolink PH300 modem IDs Greg KH
2011-06-16  0:00 ` [54/89] USB: option Add blacklist for ZTE K3765-Z (19d2:2002) Greg KH
2011-06-16  0:00 ` [55/89] Revert "USB: option: add ID for ZTE MF 330" Greg KH
2011-06-16  0:00 ` [56/89] USB: core: Tolerate protocol stall during hub and port Greg KH
2011-06-16  0:00 ` [57/89] USB: serial: add another 4N-GALAXY.DE PID to ftdi_sio driver Greg KH
2011-06-16  0:00 ` [58/89] usb-storage: redo incorrect reads Greg KH
2011-06-16  0:00 ` [59/89] Revert "x86, efi: Retain boot service code until after switching to virtual mode" Greg KH
2011-06-16  0:00 ` [60/89] xhci: Add defines for hardcoded slot states Greg KH
2011-06-16  0:00 ` [61/89] xhci: Do not issue device reset when device is not setup Greg KH
2011-06-16  0:00 ` [62/89] xhci: Disable MSI for some Fresco Logic hosts Greg KH
2011-06-16  0:00 ` [63/89] USB: xhci - fix interval calculation for FS isoc endpoints Greg KH
2011-06-16  0:00 ` [64/89] AppArmor: Fix sleep in invalid context from task_setrlimit Greg KH
2011-06-16  0:00 ` [65/89] cifs: dont allow cifs_reconnect to exit with NULL socket Greg KH
2011-06-16  0:00 ` [66/89] ASoC: AD1836: Fix setting the PCM format Greg KH
2011-06-16  0:00 ` [67/89] ASoC: Fix WM8962 headphone volume update for use of advanced Greg KH
2011-06-16  0:00 ` [68/89] ASoC: WM8804 does not support sample rates below 32kHz Greg KH
2011-06-16  0:00 ` [69/89] ASoC: snd_soc_new_{mixer,mux,pga} make sure to use right Greg KH
2011-06-16  0:00 ` [70/89] ASoC: SAMSUNG: Fix the incorrect referencing of I2SCON Greg KH
2011-06-16  0:00 ` [71/89] ALSA: hda: Fix quirk for Dell Inspiron 910 Greg KH
2011-06-16  0:00 ` [72/89] oprofile: Free potentially owned tasks in case of errors Greg KH
2011-06-16  0:00 ` Greg KH [this message]
2011-06-16  0:00 ` [74/89] oprofile, dcookies: Fix possible circular locking dependency Greg KH
2011-06-16  0:00 ` [75/89] drm/radeon/kms: do bounds checking for 3D_LOAD_VBPNTR and Greg KH
2011-06-16  0:00 ` [76/89] iwlagn: use cts-to-self protection on 5000 adapters series Greg KH
2011-06-16  0:00 ` [77/89] iwl4965: set tx power after rxon_assoc Greg KH
2011-06-16  0:00 ` [78/89] igb: fix i350 SR-IOV failture Greg KH
2011-06-16  0:00 ` [79/89] mac80211: fix IBSS teardown race Greg KH
2011-06-16  0:00 ` [80/89] x86: devicetree: Add missing early_init_dt_setup_initrd_arch Greg KH
2011-06-16  0:00 ` [81/89] x86: cpu-hotplug: Prevent softirq wakeup on wrong CPU Greg KH
2011-06-16  0:00 ` [82/89] CPUFREQ: Remove cpufreq_stats sysfs entries on module unload Greg KH
2011-06-16  0:00 ` [83/89] TOMOYO: Fix oops in tomoyo_mount_acl() Greg KH
2011-06-16  0:00 ` [84/89] md: check ->hot_remove_disk when removing disk Greg KH
2011-06-16  0:00 ` [85/89] md/raid5: fix raid5_set_bi_hw_segments Greg KH
2011-06-16  0:00 ` [86/89] md/raid5: fix FUA request handling in ops_run_io() Greg KH
2011-06-16  0:00 ` [87/89] iwlagn: send tx power command if defer cause by RXON not Greg KH
2011-06-16  0:00 ` [88/89] iwlagn: fix channel switch locking Greg KH
2011-06-16  0:00 ` [89/89] iwlegacy: " Greg KH

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=20110616000236.153229699@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=carll@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robert.richter@amd.com \
    --cc=stable-review@kernel.org \
    --cc=stable@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

all inboxes | Powered by JetHome®