All of lore.kernel.org
 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, Paul Gevers <elbrus@debian.org>,
	Ben Hutchings <ben@decadent.org.uk>
Subject: [PATCH 3.14 47/78] Staging: speakup: Move pasting into a work item
Date: Mon,  9 Jun 2014 15:48:27 -0700	[thread overview]
Message-ID: <20140609224814.868544840@linuxfoundation.org> (raw)
In-Reply-To: <20140609224813.282275135@linuxfoundation.org>

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

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

From: Ben Hutchings <ben@decadent.org.uk>

commit d7500135802ca55b3f4e01a16544e8b34082f8c3 upstream.

Input is handled in softirq context, but when pasting we may
need to sleep.  speakup_paste_selection() currently tries to
bodge this by busy-waiting if in_atomic(), but that doesn't
help because the ldisc may also sleep.

For bonus breakage, speakup_paste_selection() changes the
state of current, even though it's not running in process
context.

Move it into a work item and make sure to cancel it on exit.

References: https://bugs.debian.org/735202
References: https://bugs.debian.org/744015
Reported-by: Paul Gevers <elbrus@debian.org>
Reported-and-tested-by: Jarek Czekalski <jarekczek@poczta.onet.pl>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/staging/speakup/main.c      |    1 
 drivers/staging/speakup/selection.c |   40 +++++++++++++++++++++++++++++-------
 drivers/staging/speakup/speakup.h   |    1 
 3 files changed, 35 insertions(+), 7 deletions(-)

--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -2218,6 +2218,7 @@ static void __exit speakup_exit(void)
 	unregister_keyboard_notifier(&keyboard_notifier_block);
 	unregister_vt_notifier(&vt_notifier_block);
 	speakup_unregister_devsynth();
+	speakup_cancel_paste();
 	del_timer(&cursor_timer);
 	kthread_stop(speakup_task);
 	speakup_task = NULL;
--- a/drivers/staging/speakup/selection.c
+++ b/drivers/staging/speakup/selection.c
@@ -4,6 +4,8 @@
 #include <linux/sched.h>
 #include <linux/device.h> /* for dev_warn */
 #include <linux/selection.h>
+#include <linux/workqueue.h>
+#include <asm/cmpxchg.h>
 
 #include "speakup.h"
 
@@ -121,20 +123,24 @@ int speakup_set_selection(struct tty_str
 	return 0;
 }
 
-/* TODO: move to some helper thread, probably.  That'd fix having to check for
- * in_atomic().  */
-int speakup_paste_selection(struct tty_struct *tty)
-{
+struct speakup_paste_work {
+	struct work_struct work;
+	struct tty_struct *tty;
+};
+
+static void __speakup_paste_selection(struct work_struct *work)
+{
+	struct speakup_paste_work *spw =
+		container_of(work, struct speakup_paste_work, work);
+	struct tty_struct *tty = xchg(&spw->tty, NULL);
 	struct vc_data *vc = (struct vc_data *) tty->driver_data;
 	int pasted = 0, count;
 	DECLARE_WAITQUEUE(wait, current);
+
 	add_wait_queue(&vc->paste_wait, &wait);
 	while (sel_buffer && sel_buffer_lth > pasted) {
 		set_current_state(TASK_INTERRUPTIBLE);
 		if (test_bit(TTY_THROTTLED, &tty->flags)) {
-			if (in_atomic())
-				/* if we are in an interrupt handler, abort */
-				break;
 			schedule();
 			continue;
 		}
@@ -146,6 +152,26 @@ int speakup_paste_selection(struct tty_s
 	}
 	remove_wait_queue(&vc->paste_wait, &wait);
 	current->state = TASK_RUNNING;
+	tty_kref_put(tty);
+}
+
+static struct speakup_paste_work speakup_paste_work = {
+	.work = __WORK_INITIALIZER(speakup_paste_work.work,
+				   __speakup_paste_selection)
+};
+
+int speakup_paste_selection(struct tty_struct *tty)
+{
+	if (cmpxchg(&speakup_paste_work.tty, NULL, tty) != NULL)
+		return -EBUSY;
+
+	tty_kref_get(tty);
+	schedule_work_on(WORK_CPU_UNBOUND, &speakup_paste_work.work);
 	return 0;
 }
 
+void speakup_cancel_paste(void)
+{
+	cancel_work_sync(&speakup_paste_work.work);
+	tty_kref_put(speakup_paste_work.tty);
+}
--- a/drivers/staging/speakup/speakup.h
+++ b/drivers/staging/speakup/speakup.h
@@ -77,6 +77,7 @@ extern void synth_buffer_clear(void);
 extern void speakup_clear_selection(void);
 extern int speakup_set_selection(struct tty_struct *tty);
 extern int speakup_paste_selection(struct tty_struct *tty);
+extern void speakup_cancel_paste(void);
 extern void speakup_register_devsynth(void);
 extern void speakup_unregister_devsynth(void);
 extern void synth_write(const char *buf, size_t count);



  parent reply	other threads:[~2014-06-09 23:08 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 22:47 [PATCH 3.14 00/78] 3.14.7-stable review Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 01/78] sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in cpupri check Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 02/78] sched/deadline: Fix memory leak Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 03/78] sched: Sanitize irq accounting madness Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 04/78] perf: Prevent false warning in perf_swevent_add Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 05/78] perf: Limit perf_event_attr::sample_period to 63 bits Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 06/78] perf: Fix race in removing an event Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 07/78] mm/memory-failure.c: fix memory leak by race between poison and unpoison Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 08/78] Documentation: fix DOCBOOKS=... building Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 09/78] hwmon: (ntc_thermistor) Fix dependencies Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 10/78] hwmon: (ntc_thermistor) Fix OF device ID mapping Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 11/78] drm/gf119-/disp: fix nasty bug which can clobber SOR0s clock setup Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 16/78] SCSI: scsi_transport_sas: move bsg destructor into sas_rphy_remove Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 18/78] ARM: omap5: hwmod_data: Correct IDLEMODE for McPDM Greg Kroah-Hartman
2014-06-09 22:47 ` [PATCH 3.14 19/78] ARM: OMAP2+: nand: Fix NAND on OMAP2 and OMAP3 boards Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 21/78] ARM: OMAP4: Fix the boot regression with CPU_IDLE enabled Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 22/78] ARM: 8051/1: put_user: fix possible data corruption in put_user Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 24/78] cpufreq: cpu0: drop wrong devm usage Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 25/78] cpufreq: remove race while accessing cur_policy Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 26/78] firewire: revert to 4 GB RDMA, fix protocols using Memory Space Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 27/78] MIPS: Fix typo when reporting cache and ftlb errors for ImgTec cores Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 28/78] dm thin: add no_space_timeout dm-thin-pool module param Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 29/78] dm cache: always split discards on cache block boundaries Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 30/78] Revert "revert "mm: vmscan: do not swap anon pages just because free+file is low"" Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 31/78] virtio_blk: fix race between start and stop queue Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 32/78] sched: Disallow sched_attr::sched_policy < 0 Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 33/78] sched: Make sched_setattr() correctly return -EFBIG Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 34/78] sched/deadline: Change sched_getparam() behaviour vs SCHED_DEADLINE Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 35/78] sched/deadline: Restrict user params max value to 2^63 ns Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 36/78] sched: Fix hotplug vs. set_cpus_allowed_ptr() Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 37/78] sched/dl: Fix race in dl_task_timer() Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 39/78] drm/i915: Only copy back the modified fields to userspace from execbuffer Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 40/78] drm/radeon/dpm: resume fixes for some systems Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 42/78] libata: Blacklist queued trim for Crucial M500 Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 43/78] sched: Fix sched_policy < 0 comparison Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 44/78] md: always set MD_RECOVERY_INTR when aborting a reshape or other "resync" Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 45/78] md: always set MD_RECOVERY_INTR when interrupting a reshape thread Greg Kroah-Hartman
2014-06-09 22:48 ` Greg Kroah-Hartman [this message]
2014-06-09 22:48 ` [PATCH 3.14 48/78] staging: comedi: ni_daq_700: add mux settling delay Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 49/78] Staging: speakup: Update __speakup_paste_selection() tty (ab)usage to match vt Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 50/78] staging: r8192e_pci: fix htons error Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 51/78] Bluetooth: Fix L2CAP LE debugfs entries permissions Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 52/78] ALSA: hda/analog - Fix silent output on ASUS A8JN Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 53/78] ALSA: hda/realtek - Correction of fixup codes for PB V7900 laptop Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 54/78] ALSA: hda/realtek - Fix COEF widget NID for ALC260 replacer fixup Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 55/78] USB: ftdi_sio: add NovaTech OrionLXm product ID Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 58/78] USB: serial: option: add support for Novatel E371 PCIe card Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 59/78] USB: io_ti: fix firmware download on big-endian machines (part 2) Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 60/78] usb: pci-quirks: Prevent Sony VAIO t-series from switching usb ports Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 61/78] USB: Avoid runtime suspend loops for HCDs that cant handle suspend/resume Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 62/78] percpu-refcount: fix usage of this_cpu_ops Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 63/78] intel_pstate: remove unneeded sample buffers Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 64/78] intel_pstate: Remove C0 tracking Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 65/78] intel_pstate: Correct rounding in busy calculation Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 66/78] intel_pstate: add sample time scaling Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 67/78] intel_pstate: Improve initial busy calculation Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 68/78] mm: add !pte_present() check on existing hugetlb_entry callbacks Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 69/78] mm: rmap: fix use-after-free in __put_anon_vma Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 70/78] iser-target: Add missing target_put_sess_cmd for ImmedateData failure Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 71/78] iscsi-target: Fix wrong buffer / buffer overrun in iscsi_change_param_value() Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 72/78] target: Fix alua_access_state attribute OOPs for un-configured devices Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 73/78] netfilter: Fix potential use after free in ip6_route_me_harder() Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 74/78] netfilter: nfnetlink: Fix use after free when it fails to process batch Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 77/78] gpio: mcp23s08: Bug fix of SPI device tree registration Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.14 78/78] [stable PATCH] iommu/vt-d: Fix missing IOTLB flush in intel_iommu_unmap() Greg Kroah-Hartman
2014-06-09 22:48   ` Greg Kroah-Hartman
2014-06-10 13:26 ` [PATCH 3.14 00/78] 3.14.7-stable review Satoru Takeuchi
2014-06-10 13:26   ` Satoru Takeuchi
2014-06-10 18:46   ` Greg Kroah-Hartman
2014-06-10 15:11 ` Guenter Roeck

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=20140609224814.868544840@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ben@decadent.org.uk \
    --cc=elbrus@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.