mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, Kay Sievers <kay.sievers@vrfy.org>,
	Bernie Thompson <bernie@plugable.com>
Subject: [ 51/94] udlfb: fix hcd_buffer_free panic on unplug/replug
Date: Sun, 27 May 2012 10:05:14 +0900	[thread overview]
Message-ID: <20120527010430.965598949@linuxfoundation.org> (raw)
In-Reply-To: <20120527010332.GA11170@kroah.com>

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

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

From: Bernie Thompson <bernie@plugable.com>

commit 8d21547d3c9c3bc653261f26d554cfabc4a083de upstream.

Fix race conditions with unplug/replug behavior, in particular
take care not to hold up USB probe/disconnect for long-running
framebuffer operations and rely on usb to handle teardown.

Fix for kernel panic reported with new F17 multiseat support.

Reported-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Bernie Thompson <bernie@plugable.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/video/udlfb.c |  146 +++++++++++++++++++++++++++-----------------------
 include/video/udlfb.h |    1 
 2 files changed, 81 insertions(+), 66 deletions(-)

--- a/drivers/video/udlfb.c
+++ b/drivers/video/udlfb.c
@@ -918,10 +918,6 @@ static void dlfb_free(struct kref *kref)
 {
 	struct dlfb_data *dev = container_of(kref, struct dlfb_data, kref);
 
-	/* this function will wait for all in-flight urbs to complete */
-	if (dev->urbs.count > 0)
-		dlfb_free_urb_list(dev);
-
 	if (dev->backing_buffer)
 		vfree(dev->backing_buffer);
 
@@ -940,35 +936,42 @@ static void dlfb_release_urb_work(struct
 	up(&unode->dev->urbs.limit_sem);
 }
 
-static void dlfb_free_framebuffer_work(struct work_struct *work)
+static void dlfb_free_framebuffer(struct dlfb_data *dev)
 {
-	struct dlfb_data *dev = container_of(work, struct dlfb_data,
-					     free_framebuffer_work.work);
 	struct fb_info *info = dev->info;
-	int node = info->node;
 
-	unregister_framebuffer(info);
+	if (info) {
+		int node = info->node;
 
-	if (info->cmap.len != 0)
-		fb_dealloc_cmap(&info->cmap);
-	if (info->monspecs.modedb)
-		fb_destroy_modedb(info->monspecs.modedb);
-	if (info->screen_base)
-		vfree(info->screen_base);
+		unregister_framebuffer(info);
 
-	fb_destroy_modelist(&info->modelist);
+		if (info->cmap.len != 0)
+			fb_dealloc_cmap(&info->cmap);
+		if (info->monspecs.modedb)
+			fb_destroy_modedb(info->monspecs.modedb);
+		if (info->screen_base)
+			vfree(info->screen_base);
+
+		fb_destroy_modelist(&info->modelist);
 
-	dev->info = 0;
+		dev->info = NULL;
 
-	/* Assume info structure is freed after this point */
-	framebuffer_release(info);
+		/* Assume info structure is freed after this point */
+		framebuffer_release(info);
 
-	pr_warn("fb_info for /dev/fb%d has been freed\n", node);
+		pr_warn("fb_info for /dev/fb%d has been freed\n", node);
+	}
 
 	/* ref taken in probe() as part of registering framebfufer */
 	kref_put(&dev->kref, dlfb_free);
 }
 
+static void dlfb_free_framebuffer_work(struct work_struct *work)
+{
+	struct dlfb_data *dev = container_of(work, struct dlfb_data,
+					     free_framebuffer_work.work);
+	dlfb_free_framebuffer(dev);
+}
 /*
  * Assumes caller is holding info->lock mutex (for open and release at least)
  */
@@ -1570,14 +1573,15 @@ success:
 	kfree(buf);
 	return true;
 }
+
+static void dlfb_init_framebuffer_work(struct work_struct *work);
+
 static int dlfb_usb_probe(struct usb_interface *interface,
 			const struct usb_device_id *id)
 {
 	struct usb_device *usbdev;
 	struct dlfb_data *dev = 0;
-	struct fb_info *info = 0;
 	int retval = -ENOMEM;
-	int i;
 
 	/* usb initialization */
 
@@ -1589,9 +1593,7 @@ static int dlfb_usb_probe(struct usb_int
 		goto error;
 	}
 
-	/* we need to wait for both usb and fbdev to spin down on disconnect */
 	kref_init(&dev->kref); /* matching kref_put in usb .disconnect fn */
-	kref_get(&dev->kref); /* matching kref_put in free_framebuffer_work */
 
 	dev->udev = usbdev;
 	dev->gdev = &usbdev->dev; /* our generic struct device * */
@@ -1619,10 +1621,39 @@ static int dlfb_usb_probe(struct usb_int
 		goto error;
 	}
 
+	kref_get(&dev->kref); /* matching kref_put in free_framebuffer_work */
+
 	/* We don't register a new USB class. Our client interface is fbdev */
 
+	/* Workitem keep things fast & simple during USB enumeration */
+	INIT_DELAYED_WORK(&dev->init_framebuffer_work,
+			  dlfb_init_framebuffer_work);
+	schedule_delayed_work(&dev->init_framebuffer_work, 0);
+
+	return 0;
+
+error:
+	if (dev) {
+
+		kref_put(&dev->kref, dlfb_free); /* ref for framebuffer */
+		kref_put(&dev->kref, dlfb_free); /* last ref from kref_init */
+
+		/* dev has been deallocated. Do not dereference */
+	}
+
+	return retval;
+}
+
+static void dlfb_init_framebuffer_work(struct work_struct *work)
+{
+	struct dlfb_data *dev = container_of(work, struct dlfb_data,
+					     init_framebuffer_work.work);
+	struct fb_info *info;
+	int retval;
+	int i;
+
 	/* allocates framebuffer driver structure, not framebuffer memory */
-	info = framebuffer_alloc(0, &interface->dev);
+	info = framebuffer_alloc(0, dev->gdev);
 	if (!info) {
 		retval = -ENOMEM;
 		pr_err("framebuffer_alloc failed\n");
@@ -1668,15 +1699,13 @@ static int dlfb_usb_probe(struct usb_int
 	for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++) {
 		retval = device_create_file(info->dev, &fb_device_attrs[i]);
 		if (retval) {
-			pr_err("device_create_file failed %d\n", retval);
-			goto err_del_attrs;
+			pr_warn("device_create_file failed %d\n", retval);
 		}
 	}
 
 	retval = device_create_bin_file(info->dev, &edid_attr);
 	if (retval) {
-		pr_err("device_create_bin_file failed %d\n", retval);
-		goto err_del_attrs;
+		pr_warn("device_create_bin_file failed %d\n", retval);
 	}
 
 	pr_info("DisplayLink USB device /dev/fb%d attached. %dx%d resolution."
@@ -1684,38 +1713,10 @@ static int dlfb_usb_probe(struct usb_int
 			info->var.xres, info->var.yres,
 			((dev->backing_buffer) ?
 			info->fix.smem_len * 2 : info->fix.smem_len) >> 10);
-	return 0;
-
-err_del_attrs:
-	for (i -= 1; i >= 0; i--)
-		device_remove_file(info->dev, &fb_device_attrs[i]);
+	return;
 
 error:
-	if (dev) {
-
-		if (info) {
-			if (info->cmap.len != 0)
-				fb_dealloc_cmap(&info->cmap);
-			if (info->monspecs.modedb)
-				fb_destroy_modedb(info->monspecs.modedb);
-			if (info->screen_base)
-				vfree(info->screen_base);
-
-			fb_destroy_modelist(&info->modelist);
-
-			framebuffer_release(info);
-		}
-
-		if (dev->backing_buffer)
-			vfree(dev->backing_buffer);
-
-		kref_put(&dev->kref, dlfb_free); /* ref for framebuffer */
-		kref_put(&dev->kref, dlfb_free); /* last ref from kref_init */
-
-		/* dev has been deallocated. Do not dereference */
-	}
-
-	return retval;
+	dlfb_free_framebuffer(dev);
 }
 
 static void dlfb_usb_disconnect(struct usb_interface *interface)
@@ -1735,12 +1736,24 @@ static void dlfb_usb_disconnect(struct u
 	/* When non-active we'll update virtual framebuffer, but no new urbs */
 	atomic_set(&dev->usb_active, 0);
 
-	/* remove udlfb's sysfs interfaces */
-	for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++)
-		device_remove_file(info->dev, &fb_device_attrs[i]);
-	device_remove_bin_file(info->dev, &edid_attr);
-	unlink_framebuffer(info);
+	/* this function will wait for all in-flight urbs to complete */
+	dlfb_free_urb_list(dev);
+
+	if (info) {
+
+		/* remove udlfb's sysfs interfaces */
+		for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++)
+			device_remove_file(info->dev, &fb_device_attrs[i]);
+		device_remove_bin_file(info->dev, &edid_attr);
+
+		/* it's safe to uncomment next line if your kernel
+		   doesn't yet have this function exported */
+		unlink_framebuffer(info);
+	}
+
 	usb_set_intfdata(interface, NULL);
+	dev->udev = NULL;
+	dev->gdev = NULL;
 
 	/* if clients still have us open, will be freed on last close */
 	if (dev->fb_count == 0)
@@ -1806,12 +1819,12 @@ static void dlfb_free_urb_list(struct dl
 	int ret;
 	unsigned long flags;
 
-	pr_notice("Waiting for completes and freeing all render urbs\n");
+	pr_notice("Freeing all render urbs\n");
 
 	/* keep waiting and freeing, until we've got 'em all */
 	while (count--) {
 
-		/* Getting interrupted means a leak, but ok at shutdown*/
+		/* Getting interrupted means a leak, but ok at disconnect */
 		ret = down_interruptible(&dev->urbs.limit_sem);
 		if (ret)
 			break;
@@ -1833,6 +1846,7 @@ static void dlfb_free_urb_list(struct dl
 		kfree(node);
 	}
 
+	dev->urbs.count = 0;
 }
 
 static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size)
--- a/include/video/udlfb.h
+++ b/include/video/udlfb.h
@@ -41,6 +41,7 @@ struct dlfb_data {
 	char *backing_buffer;
 	int fb_count;
 	bool virtualized; /* true when physical usb device not present */
+	struct delayed_work init_framebuffer_work;
 	struct delayed_work free_framebuffer_work;
 	atomic_t usb_active; /* 0 = update virtual buffer, but no usb traffic */
 	atomic_t lost_pixels; /* 1 = a render op failed. Need screen refresh */



  parent reply	other threads:[~2012-05-27  1:10 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-27  1:03 [ 00/94] 3.3.8-stable review Greg KH
2012-05-27  1:04 ` [ 01/94] tilegx: enable SYSCALL_WRAPPERS support Greg KH
2012-05-27  1:04 ` [ 02/94] bio allocation failure due to bio_get_nr_vecs() Greg KH
2012-05-27  1:04 ` [ 03/94] block: fix buffer overflow when printing partition UUIDs Greg KH
2012-05-27  1:04 ` [ 04/94] block: dont mark buffers beyond end of disk as mapped Greg KH
2012-05-27  1:04 ` [ 05/94] PARISC: fix PA1.1 oops on boot Greg KH
2012-05-27  1:04 ` [ 06/94] PARISC: fix crash in flush_icache_page_asm on PA1.1 Greg KH
2012-05-27  1:04 ` [ 07/94] PARISC: fix panic on prefetch(NULL) on PA7300LC Greg KH
2012-05-27  1:04 ` [ 08/94] isdn/gigaset: ratelimit CAPI message dumps Greg KH
2012-05-27  1:04 ` [ 09/94] vfs: make AIO use the proper rw_verify_area() area helpers Greg KH
2012-05-27  1:04 ` [ 10/94] iwlwifi: use 6000G2B for 6030 device series Greg KH
2012-05-27 13:38   ` Ben Hutchings
2012-06-01  7:01     ` Greg KH
2012-05-27  1:04 ` [ 11/94] iwlwifi: use correct released ucode version Greg KH
2012-05-27  1:04 ` [ 12/94] net/wireless: ipw2200: Fix WARN_ON occurring in wiphy_register called by ipw_pci_probe Greg KH
2012-05-27 19:47   ` Herton Ronaldo Krzesinski
2012-06-01  6:58     ` Greg KH
2012-05-27  1:04 ` [ 13/94] cfg80211: warn if db.txt is empty with CONFIG_CFG80211_INTERNAL_REGDB Greg KH
2012-05-27  1:04 ` [ 14/94] regulator: core: Release regulator-regulator supplies on error Greg KH
2012-05-27  1:04 ` [ 15/94] Fix blocking allocations called very early during bootup Greg KH
2012-05-27  1:04 ` [ 16/94] s390/pfault: fix task state race Greg KH
2012-05-27  1:04 ` [ 17/94] SCSI: mpt2sas: Fix for panic happening because of improper memory allocation Greg KH
2012-05-27  1:04 ` [ 18/94] isci: fix oem parameter validation on single controller skus Greg KH
2012-05-27  1:04 ` [ 19/94] RDMA/cxgb4: Always wake up waiters in c4iw_peer_abort_intr() Greg KH
2012-05-27  1:04 ` [ 20/94] RDMA/cxgb4: Use dst parameter in import_ep() Greg KH
2012-05-27  1:04 ` [ 21/94] RDMA/cxgb4: Drop peer_abort when no endpoint found Greg KH
2012-05-27  1:04 ` [ 22/94] powerpc: Fix broken cpu_idle_wait() implementation Greg KH
2012-05-27  1:04 ` [ 23/94] KEYS: Use the compat keyctl() syscall wrapper on Sparc64 for Sparc32 compat Greg KH
2012-05-27  1:04 ` [ 24/94] SELinux: if sel_make_bools errors dont leave inconsistent state Greg KH
2012-05-27  1:04 ` [ 25/94] IB/core: Fix mismatch between locked and pinned pages Greg KH
2012-05-27  1:04 ` [ 26/94] drivers/staging/comedi/comedi_fops.c: add missing vfree Greg KH
2012-05-27  1:04 ` [ 27/94] perf/x86: Update event scheduling constraints for AMD family 15h models Greg KH
2012-05-27  1:04 ` [ 28/94] mtd: sm_ftl: fix typo in major number Greg KH
2012-05-27  1:04 ` [ 29/94] libata: forbid port runtime pm by default, fixing regression Greg KH
2012-05-27  1:04 ` [ 30/94] ahci: Detect Marvell 88SE9172 SATA controller Greg KH
2012-05-27  1:04 ` [ 31/94] HID: wiimote: Fix IR data parser Greg KH
2012-05-27  1:04 ` [ 32/94] usbhid: prevent deadlock during timeout Greg KH
2012-05-27  1:04 ` [ 33/94] HID: logitech: read all 32 bits of report type bitfield Greg KH
2012-05-27  1:04 ` [ 34/94] um: Fix __swp_type() Greg KH
2012-05-27  1:04 ` [ 35/94] um: Implement a custom pte_same() function Greg KH
2012-05-27  1:04 ` [ 36/94] docs: update HOWTO for 2.6.x -> 3.x versioning Greg KH
2012-05-27  1:05 ` [ 37/94] swap: dont do discard if no discard option added Greg KH
2012-05-27  1:05 ` [ 38/94] USB: cdc-wdm: sanitize error returns Greg KH
2012-05-27  1:05 ` [ 39/94] USB: cdc-wdm: poll must return POLLHUP if device is gone Greg KH
2012-05-27  1:05 ` [ 40/94] workqueue: skip nr_running sanity check in worker_enter_idle() if trustee is active Greg KH
2012-05-27  1:05 ` [ 41/94] mm: mempolicy: Let vma_merge and vma_split handle vma->vm_policy linkages Greg KH
2012-05-27  1:05 ` [ 42/94] md: using GFP_NOIO to allocate bio for flush request Greg KH
2012-05-27  1:05 ` [ 43/94] Add missing call to uart_update_timeout() Greg KH
2012-05-27  1:05 ` [ 44/94] 8250_pci: fix pch uart matching Greg KH
2012-05-27  1:05 ` [ 45/94] tty: Allow uart_register/unregister/register Greg KH
2012-05-27  1:05 ` [ 46/94] USB: ftdi-sio: add support for Physik Instrumente E-861 Greg KH
2012-05-27  1:05 ` [ 47/94] usb-storage: unusual_devs entry for Yarvik PMP400 MP4 player Greg KH
2012-05-27  1:05 ` [ 48/94] USB: ffs-test: fix length argument of out function call Greg KH
2012-05-27  1:05 ` [ 49/94] drivers/rtc/rtc-pl031.c: configure correct wday for 2000-01-01 Greg KH
2012-05-27  1:05 ` [ 50/94] SCSI: hpsa: Fix problem with MSA2xxx devices Greg KH
2012-05-27  1:05 ` Greg KH [this message]
2012-05-27  1:05 ` [ 52/94] usb: usbtest: two super speed fixes for usbtest Greg KH
2012-05-27  1:05 ` [ 53/94] USB: ohci-at91: add a reset function to fix race condition Greg KH
2012-05-27  1:05 ` [ 54/94] USB: Remove races in devio.c Greg KH
2012-05-27  1:05 ` [ 55/94] USB: serial: ti_usb_3410_5052: Add support for the FRI2 serial console Greg KH
2012-05-27  1:05 ` [ 56/94] usb: gadget: fsl_udc_core: dTDs next dtd pointer need to be updated once written Greg KH
2012-05-27  1:05 ` [ 57/94] usb: add USB_QUIRK_RESET_RESUME for M-Audio 88es Greg KH
2012-05-27  1:05 ` [ 58/94] xhci: Add Lynx Point to list of Intel switchable hosts Greg KH
2012-05-27  1:05 ` [ 59/94] xhci: Avoid dead ports when CONFIG_USB_XHCI_HCD=n Greg KH
2012-05-27  1:05 ` [ 60/94] usb-xhci: Handle COMP_TX_ERR for isoc tds Greg KH
2012-05-27  1:05 ` [ 61/94] xhci: Reset reserved command ring TRBs on cleanup Greg KH
2012-05-27  1:05 ` [ 62/94] xhci: Add new short TX quirk for Fresco Logic host Greg KH
2012-05-27  1:05 ` [ 63/94] USB: fix resource leak in xhci power loss path Greg KH
2012-05-27  1:05 ` [ 64/94] usbcore: enable USB2 LPM if port suspend fails Greg KH
2012-05-27  1:05 ` [ 65/94] gma500: Fix Poulsbo suspend/resume crash on devices with SDVO ports Greg KH
2012-05-27  1:05 ` [ 66/94] b43legacy: Fix error due to MMIO access with SSB unpowered Greg KH
2012-05-27  1:05 ` [ 67/94] drm/i915: Avoid a double-read of PCH_IIR during interrupt handling Greg KH
2012-05-27  1:05 ` [ 68/94] drm/i915: [GEN7] Use HW scheduler for fixed function shaders Greg KH
2012-05-27  1:05 ` [ 69/94] drm/i915: dont clobber the pipe param in sanitize_modesetting Greg KH
2012-05-27  1:05 ` [ 70/94] gpio: mpc8xxx: Prevent NULL pointer deref in demux handler Greg KH
2012-05-27  1:05 ` [ 71/94] spi/spi-fsl-spi: reference correct pdata in fsl_spi_cs_control Greg KH
2012-05-28 19:44   ` Herton Ronaldo Krzesinski
2012-06-01  7:05     ` Greg KH
2012-05-27  1:05 ` [ 72/94] xen: do not map the same GSI twice in PVHVM guests Greg KH
2012-05-27  1:05 ` [ 73/94] nouveau: nouveau_set_bo_placement takes TTM flags Greg KH
2012-05-27  1:05 ` [ 74/94] [media] smsusb: add autodetection support for USB ID 2040:c0a0 Greg KH
2012-05-27  1:05 ` [ 75/94] media: uvcvideo: Fix ENUMINPUT handling Greg KH
2012-05-27  1:05 ` [ 76/94] x86, realmode: 16-bit real-mode code support for relocs tool Greg KH
2012-05-27 16:37   ` Ben Hutchings
2012-05-27 20:02     ` Greg KH
2012-05-27  1:05 ` [ 77/94] x86, relocs: Workaround for binutils 2.22.52.0.1 section bug Greg KH
2012-05-27  1:05 ` [ 78/94] x86, relocs: When printing an error, say relative or absolute Greg KH
2012-05-27  1:05 ` [ 79/94] x86, relocs: Build clean fix Greg KH
2012-05-27  1:05 ` [ 80/94] x86-32, relocs: Whitelist more symbols for ld bug workaround Greg KH
2012-05-27  1:05 ` [ 81/94] x86, relocs: Add jiffies and jiffies_64 to the relative whitelist Greg KH
2012-05-27  1:05 ` [ 82/94] x86/mce: Fix check for processor context when machine check was taken Greg KH
2012-05-27  1:05 ` [ 83/94] mmc: sdio: avoid spurious calls to interrupt handlers Greg KH
2012-05-27  1:05 ` [ 84/94] mmc: cd-gpio: protect against NULL context in mmc_cd_gpio_free() Greg KH
2012-05-27  1:05 ` [ 85/94] mmc: omap_hsmmc: pass IRQF_ONESHOT to request_threaded_irq Greg KH
2012-05-27  1:05 ` [ 86/94] tile: fix bug where fls(0) was not returning 0 Greg KH
2012-05-27  1:05 ` [ 87/94] intel-iommu: Add device info into list before doing context mapping Greg KH
2012-05-27  1:05 ` [ 88/94] iommu: Fix off by one in dmar_get_fault_reason() Greg KH
2012-05-27  1:05 ` [ 89/94] rtlwifi: fix for race condition when firmware is cached Greg KH
2012-05-28 20:21   ` Herton Ronaldo Krzesinski
2012-05-28 21:59     ` Larry Finger
2012-06-01  7:06       ` Greg KH
2012-05-27  1:05 ` [ 90/94] ARM: 7365/1: drop unused parameter from flush_cache_user_range Greg KH
2012-05-27  1:05 ` [ 91/94] ARM: 7409/1: Do not call flush_cache_user_range with mmap_sem held Greg KH
2012-05-27  1:05 ` [ 92/94] MCE: Fix vm86 handling for 32bit mce handler Greg KH
2012-05-27  1:05 ` [ 93/94] i2c: davinci: Free requested IRQ in remove Greg KH
2012-05-27  1:05 ` [ 94/94] i2c: tegra: notify transfer-complete after clearing status Greg KH
2012-05-27  1:11 ` [ 00/94] 3.3.8-stable review 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=20120527010430.965598949@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=bernie@plugable.com \
    --cc=kay.sievers@vrfy.org \
    --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

Powered by JetHome