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, stable@vger.kernel.org
Cc: Greg KH <gregkh@linuxfoundation.org>,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk,
	Dariusz Majchrzak <dariusz.majchrzak@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	James Bottomley <JBottomley@Parallels.com>
Subject: [ 08/49] SCSI: fix hot unplug vs async scan race
Date: Tue,  7 Aug 2012 15:44:26 -0700	[thread overview]
Message-ID: <20120807222027.608305327@linuxfoundation.org> (raw)
In-Reply-To: <20120807222026.848194739@linuxfoundation.org>

From: Greg KH <gregkh@linuxfoundation.org>

3.0-stable review patch.  If anyone has any objections, please let me know.

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

From: Dan Williams <dan.j.williams@intel.com>

commit 3b661a92e869ebe2358de8f4b3230ad84f7fce51 upstream.

The following crash results from cases where the end_device has been
removed before scsi_sysfs_add_sdev has had a chance to run.

 BUG: unable to handle kernel NULL pointer dereference at 0000000000000098
 IP: [<ffffffff8115e100>] sysfs_create_dir+0x32/0xb6
 ...
 Call Trace:
  [<ffffffff8125e4a8>] kobject_add_internal+0x120/0x1e3
  [<ffffffff81075149>] ? trace_hardirqs_on+0xd/0xf
  [<ffffffff8125e641>] kobject_add_varg+0x41/0x50
  [<ffffffff8125e70b>] kobject_add+0x64/0x66
  [<ffffffff8131122b>] device_add+0x12d/0x63a
  [<ffffffff814b65ea>] ? _raw_spin_unlock_irqrestore+0x47/0x56
  [<ffffffff8107de15>] ? module_refcount+0x89/0xa0
  [<ffffffff8132f348>] scsi_sysfs_add_sdev+0x4e/0x28a
  [<ffffffff8132dcbb>] do_scan_async+0x9c/0x145

...teach scsi_sysfs_add_devices() to check for deleted devices() before
trying to add them, and teach scsi_remove_target() how to remove targets
that have not been added via device_add().

Reported-by: Dariusz Majchrzak <dariusz.majchrzak@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/scsi/scsi_scan.c  |    3 +++
 drivers/scsi/scsi_sysfs.c |   41 ++++++++++++++++++++++++++---------------
 2 files changed, 29 insertions(+), 15 deletions(-)

--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1710,6 +1710,9 @@ static void scsi_sysfs_add_devices(struc
 {
 	struct scsi_device *sdev;
 	shost_for_each_device(sdev, shost) {
+		/* target removed before the device could be added */
+		if (sdev->sdev_state == SDEV_DEL)
+			continue;
 		if (!scsi_host_scan_allowed(shost) ||
 		    scsi_sysfs_add_sdev(sdev) != 0)
 			__scsi_remove_device(sdev);
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -962,7 +962,6 @@ static void __scsi_remove_target(struct
 	struct scsi_device *sdev;
 
 	spin_lock_irqsave(shost->host_lock, flags);
-	starget->reap_ref++;
  restart:
 	list_for_each_entry(sdev, &shost->__devices, siblings) {
 		if (sdev->channel != starget->channel ||
@@ -976,14 +975,6 @@ static void __scsi_remove_target(struct
 		goto restart;
 	}
 	spin_unlock_irqrestore(shost->host_lock, flags);
-	scsi_target_reap(starget);
-}
-
-static int __remove_child (struct device * dev, void * data)
-{
-	if (scsi_is_target_device(dev))
-		__scsi_remove_target(to_scsi_target(dev));
-	return 0;
 }
 
 /**
@@ -996,14 +987,34 @@ static int __remove_child (struct device
  */
 void scsi_remove_target(struct device *dev)
 {
-	if (scsi_is_target_device(dev)) {
-		__scsi_remove_target(to_scsi_target(dev));
-		return;
+	struct Scsi_Host *shost = dev_to_shost(dev->parent);
+	struct scsi_target *starget, *found;
+	unsigned long flags;
+
+ restart:
+	found = NULL;
+	spin_lock_irqsave(shost->host_lock, flags);
+	list_for_each_entry(starget, &shost->__targets, siblings) {
+		if (starget->state == STARGET_DEL)
+			continue;
+		if (starget->dev.parent == dev || &starget->dev == dev) {
+			found = starget;
+			found->reap_ref++;
+			break;
+		}
 	}
+	spin_unlock_irqrestore(shost->host_lock, flags);
 
-	get_device(dev);
-	device_for_each_child(dev, NULL, __remove_child);
-	put_device(dev);
+	if (found) {
+		__scsi_remove_target(found);
+		scsi_target_reap(found);
+		/* in the case where @dev has multiple starget children,
+		 * continue removing.
+		 *
+		 * FIXME: does such a case exist?
+		 */
+		goto restart;
+	}
 }
 EXPORT_SYMBOL(scsi_remove_target);
 



  parent reply	other threads:[~2012-08-07 22:45 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 22:44 [ 00/49] 3.0.40-stable review Greg Kroah-Hartman
2012-08-07 22:44 ` [ 01/49] mmc: sdhci-pci: CaFe has broken card detection Greg Kroah-Hartman
2012-08-07 22:44 ` [ 02/49] powerpc/ftrace: Fix assembly trampoline register usage Greg Kroah-Hartman
2012-08-07 22:44 ` [ 03/49] powerpc: Add "memory" attribute for mfmsr() Greg Kroah-Hartman
2012-08-07 22:44 ` [ 04/49] powerpc: Fix wrong divisor in usecs_to_cputime Greg Kroah-Hartman
2012-08-07 22:44 ` [ 05/49] SCSI: libsas: continue revalidation Greg Kroah-Hartman
2012-08-07 22:44 ` [ 06/49] SCSI: libsas: fix sas_discover_devices return code handling Greg Kroah-Hartman
2012-08-07 22:44 ` [ 07/49] SCSI: fix eh wakeup (scsi_schedule_eh vs scsi_restart_operations) Greg Kroah-Hartman
2012-08-07 22:44 ` Greg Kroah-Hartman [this message]
2012-08-07 22:44 ` [ 09/49] SCSI: Avoid dangling pointer in scsi_requeue_command() Greg Kroah-Hartman
2012-08-07 22:44 ` [ 10/49] ARM: OMAP2+: OPP: Fix to ensure check of right oppdef after bad one Greg Kroah-Hartman
2012-08-07 22:44 ` [ 11/49] ALSA: hda - Add support for Realtek ALC282 Greg Kroah-Hartman
2012-08-07 22:44 ` [ 12/49] usbdevfs: Correct amount of data copied to user in processcompl_compat Greg Kroah-Hartman
2012-08-07 22:44 ` [ 13/49] usb: gadget: Fix g_ether interface link status Greg Kroah-Hartman
2012-08-07 22:44 ` [ 14/49] locks: fix checking of fcntl_setlease argument Greg Kroah-Hartman
2012-08-07 22:44 ` [ 15/49] ftrace: Disable function tracing during suspend/resume and hibernation, again Greg Kroah-Hartman
2012-08-07 22:44 ` [ 16/49] stable: update references to older 2.6 versions for 3.x Greg Kroah-Hartman
2012-08-07 22:44 ` [ 17/49] workqueue: perform cpu down operations from low priority cpu_notifier() Greg Kroah-Hartman
2012-08-07 22:44 ` [ 18/49] ACPI/AC: prevent OOPS on some boxes due to missing check power_supply_register() return value check Greg Kroah-Hartman
2012-08-07 22:44 ` [ 19/49] Btrfs: call the ordered free operation without any locks held Greg Kroah-Hartman
2012-08-07 22:44 ` [ 20/49] drm/radeon: Try harder to avoid HW cursor ending on a multiple of 128 columns Greg Kroah-Hartman
2012-08-07 22:44 ` [ 21/49] drm/radeon: fix non revealent error message Greg Kroah-Hartman
2012-08-07 22:44 ` [ 22/49] drm/radeon: fix hotplug of DP to DVI|HDMI passive adapters (v2) Greg Kroah-Hartman
2012-08-07 22:44 ` [ 23/49] drm/radeon: on hotplug force link training to happen (v2) Greg Kroah-Hartman
2012-08-07 22:44 ` [ 24/49] nfsd4: our filesystems are normally case sensitive Greg Kroah-Hartman
2012-08-07 22:44 ` [ 25/49] nfs: skip commit in releasepage if were freeing memory for fs-related reasons Greg Kroah-Hartman
2012-08-07 22:44 ` [ 26/49] ext4: pass a char * to ext4_count_free() instead of a buffer_head ptr Greg Kroah-Hartman
2012-08-07 22:44 ` [ 27/49] ext4: dont let i_reserved_meta_blocks go negative Greg Kroah-Hartman
2012-08-07 22:44 ` [ 28/49] bnx2: Fix bug in bnx2_free_tx_skbs() Greg Kroah-Hartman
2012-08-07 22:44 ` [ 29/49] sch_sfb: Fix missing NULL check Greg Kroah-Hartman
2012-08-07 22:44 ` [ 30/49] sctp: Fix list corruption resulting from freeing an association on a list Greg Kroah-Hartman
2012-08-07 22:44 ` [ 31/49] caif: Fix access to freed pernet memory Greg Kroah-Hartman
2012-08-07 22:44 ` [ 32/49] cipso: dont follow a NULL pointer when setsockopt() is called Greg Kroah-Hartman
2012-08-07 22:44 ` [ 33/49] caif: fix NULL pointer check Greg Kroah-Hartman
2012-08-07 22:44 ` [ 34/49] wanmain: comparing array with NULL Greg Kroah-Hartman
2012-08-07 22:44 ` [ 35/49] tcp: Add TCP_USER_TIMEOUT negative value check Greg Kroah-Hartman
2012-08-07 22:44 ` [ 36/49] USB: kaweth.c: use GFP_ATOMIC under spin_lock Greg Kroah-Hartman
2012-08-07 22:44 ` [ 37/49] net: fix rtnetlink IFF_PROMISC and IFF_ALLMULTI handling Greg Kroah-Hartman
2012-08-07 22:44 ` [ 38/49] tcp: perform DMA to userspace only if there is a task waiting for it Greg Kroah-Hartman
2012-08-07 22:44 ` [ 39/49] net/tun: fix ioctl() based info leaks Greg Kroah-Hartman
2012-08-07 22:44 ` [ 40/49] USB: echi-dbgp: increase the controller wait time to come out of halt Greg Kroah-Hartman
2012-08-07 22:44 ` [ 41/49] ALSA: snd-usb: fix clock source validity index Greg Kroah-Hartman
2012-08-07 22:45 ` [ 42/49] ALSA: mpu401: Fix missing initialization of irq field Greg Kroah-Hartman
2012-08-07 22:45 ` [ 43/49] ASoC: wm8962: Allow VMID time to fully ramp Greg Kroah-Hartman
2012-08-07 22:45 ` [ 44/49] ASoC: wm8994: Ensure there are enough BCLKs for four channels Greg Kroah-Hartman
2012-08-07 22:45 ` [ 45/49] m68k: Make sys_atomic_cmpxchg_32 work on classic m68k Greg Kroah-Hartman
2012-08-07 22:45 ` [ 46/49] m68k: Correct the Atari ALLOWINT definition Greg Kroah-Hartman
2012-08-07 22:45 ` [ 47/49] futex: Test for pi_mutex on fault in futex_wait_requeue_pi() Greg Kroah-Hartman
2012-08-07 22:45 ` [ 48/49] futex: Fix bug in WARN_ON for NULL q.pi_state Greg Kroah-Hartman
2012-08-07 22:45 ` [ 49/49] futex: Forbid uaddr == uaddr2 in futex_wait_requeue_pi() Greg Kroah-Hartman

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=20120807222027.608305327@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=JBottomley@Parallels.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dan.j.williams@intel.com \
    --cc=dariusz.majchrzak@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.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).