linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 3.12 098/100] Input: i8042 - break load dependency between atkbd/psmouse and i8042
Date: Fri, 19 Aug 2016 09:11:37 +0200	[thread overview]
Message-ID: <bf55b12c37a06031be8e5221d0ea65e60a46d1a9.1471589700.git.jslaby@suse.cz> (raw)
In-Reply-To: <bc76af4e1436406a1f53da243e76bd10327691f2.1471589700.git.jslaby@suse.cz>
In-Reply-To: <cover.1471589700.git.jslaby@suse.cz>

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>

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

===============

commit 4097461897df91041382ff6fcd2bfa7ee6b2448c upstream.

As explained in 1407814240-4275-1-git-send-email-decui@microsoft.com we
have a hard load dependency between i8042 and atkbd which prevents
keyboard from working on Gen2 Hyper-V VMs.

> hyperv_keyboard invokes serio_interrupt(), which needs a valid serio
> driver like atkbd.c.  atkbd.c depends on libps2.c because it invokes
> ps2_command().  libps2.c depends on i8042.c because it invokes
> i8042_check_port_owner().  As a result, hyperv_keyboard actually
> depends on i8042.c.
>
> For a Generation 2 Hyper-V VM (meaning no i8042 device emulated), if a
> Linux VM (like Arch Linux) happens to configure CONFIG_SERIO_I8042=m
> rather than =y, atkbd.ko can't load because i8042.ko can't load(due to
> no i8042 device emulated) and finally hyperv_keyboard can't work and
> the user can't input: https://bugs.archlinux.org/task/39820
> (Ubuntu/RHEL/SUSE aren't affected since they use CONFIG_SERIO_I8042=y)

To break the dependency we move away from using i8042_check_port_owner()
and instead allow serio port owner specify a mutex that clients should use
to serialize PS/2 command stream.

Reported-by: Mark Laws <mdl@60hz.org>
Tested-by: Mark Laws <mdl@60hz.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/input/serio/i8042.c  | 16 +---------------
 drivers/input/serio/libps2.c | 10 ++++------
 include/linux/i8042.h        |  6 ------
 include/linux/serio.h        | 24 +++++++++++++++++++-----
 4 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 42825216e83d..7ecca05bd7a5 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -1230,6 +1230,7 @@ static int __init i8042_create_kbd_port(void)
 	serio->start		= i8042_start;
 	serio->stop		= i8042_stop;
 	serio->close		= i8042_port_close;
+	serio->ps2_cmd_mutex	= &i8042_mutex;
 	serio->port_data	= port;
 	serio->dev.parent	= &i8042_platform_device->dev;
 	strlcpy(serio->name, "i8042 KBD port", sizeof(serio->name));
@@ -1321,21 +1322,6 @@ static void i8042_unregister_ports(void)
 	}
 }
 
-/*
- * Checks whether port belongs to i8042 controller.
- */
-bool i8042_check_port_owner(const struct serio *port)
-{
-	int i;
-
-	for (i = 0; i < I8042_NUM_PORTS; i++)
-		if (i8042_ports[i].serio == port)
-			return true;
-
-	return false;
-}
-EXPORT_SYMBOL(i8042_check_port_owner);
-
 static void i8042_free_irqs(void)
 {
 	if (i8042_aux_irq_registered)
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index 07a8363f3c5c..b5ec313cb9c9 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -57,19 +57,17 @@ EXPORT_SYMBOL(ps2_sendbyte);
 
 void ps2_begin_command(struct ps2dev *ps2dev)
 {
-	mutex_lock(&ps2dev->cmd_mutex);
+	struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex;
 
-	if (i8042_check_port_owner(ps2dev->serio))
-		i8042_lock_chip();
+	mutex_lock(m);
 }
 EXPORT_SYMBOL(ps2_begin_command);
 
 void ps2_end_command(struct ps2dev *ps2dev)
 {
-	if (i8042_check_port_owner(ps2dev->serio))
-		i8042_unlock_chip();
+	struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex;
 
-	mutex_unlock(&ps2dev->cmd_mutex);
+	mutex_unlock(m);
 }
 EXPORT_SYMBOL(ps2_end_command);
 
diff --git a/include/linux/i8042.h b/include/linux/i8042.h
index 0f9bafa17a02..d98780ca9604 100644
--- a/include/linux/i8042.h
+++ b/include/linux/i8042.h
@@ -62,7 +62,6 @@ struct serio;
 void i8042_lock_chip(void);
 void i8042_unlock_chip(void);
 int i8042_command(unsigned char *param, int command);
-bool i8042_check_port_owner(const struct serio *);
 int i8042_install_filter(bool (*filter)(unsigned char data, unsigned char str,
 					struct serio *serio));
 int i8042_remove_filter(bool (*filter)(unsigned char data, unsigned char str,
@@ -83,11 +82,6 @@ static inline int i8042_command(unsigned char *param, int command)
 	return -ENODEV;
 }
 
-static inline bool i8042_check_port_owner(const struct serio *serio)
-{
-	return false;
-}
-
 static inline int i8042_install_filter(bool (*filter)(unsigned char data, unsigned char str,
 					struct serio *serio))
 {
diff --git a/include/linux/serio.h b/include/linux/serio.h
index 9f779c7a2da4..27ae809edd70 100644
--- a/include/linux/serio.h
+++ b/include/linux/serio.h
@@ -29,7 +29,8 @@ struct serio {
 
 	struct serio_device_id id;
 
-	spinlock_t lock;		/* protects critical sections from port's interrupt handler */
+	/* Protects critical sections from port's interrupt handler */
+	spinlock_t lock;
 
 	int (*write)(struct serio *, unsigned char);
 	int (*open)(struct serio *);
@@ -38,16 +39,29 @@ struct serio {
 	void (*stop)(struct serio *);
 
 	struct serio *parent;
-	struct list_head child_node;	/* Entry in parent->children list */
+	/* Entry in parent->children list */
+	struct list_head child_node;
 	struct list_head children;
-	unsigned int depth;		/* level of nesting in serio hierarchy */
+	/* Level of nesting in serio hierarchy */
+	unsigned int depth;
 
-	struct serio_driver *drv;	/* accessed from interrupt, must be protected by serio->lock and serio->sem */
-	struct mutex drv_mutex;		/* protects serio->drv so attributes can pin driver */
+	/*
+	 * serio->drv is accessed from interrupt handlers; when modifying
+	 * caller should acquire serio->drv_mutex and serio->lock.
+	 */
+	struct serio_driver *drv;
+	/* Protects serio->drv so attributes can pin current driver */
+	struct mutex drv_mutex;
 
 	struct device dev;
 
 	struct list_head node;
+
+	/*
+	 * For use by PS/2 layer when several ports share hardware and
+	 * may get indigestion when exposed to concurrent access (i8042).
+	 */
+	struct mutex *ps2_cmd_mutex;
 };
 #define to_serio_port(d)	container_of(d, struct serio, dev)
 
-- 
2.9.3

  parent reply	other threads:[~2016-08-19  7:13 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19  7:09 [PATCH 3.12 000/100] 3.12.63-stable review Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 001/100] x86/mm: Add barriers and document switch_mm()-vs-flush synchronization Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 002/100] mm: migrate dirty page without clear_page_dirty_for_io etc Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 003/100] panic: release stale console lock to always get the logbuf printed out Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 004/100] printk: do cond_resched() between lines while outputting to consoles Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 005/100] um: Stop abusing __KERNEL__ Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 006/100] um: Fix out-of-tree build Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 007/100] um: Remove copy&paste code from init.h Jiri Slaby
2016-08-19  7:08 ` [PATCH 3.12 008/100] netfilter: x_tables: validate targets of jumps Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 009/100] libceph: set 'exists' flag for newly up osd Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 010/100] libceph: apply new_state before new_up_client on incrementals Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 011/100] kvm: Fix irq route entries exceeding KVM_MAX_IRQ_ROUTES Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 012/100] tracing: Handle NULL formats in hold_module_trace_bprintk_format() Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 013/100] drm/radeon: fix asic initialization for virtualized environments Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 014/100] drm/i915/ilk: Don't disable SSC source if it's in use Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 015/100] iio: Fix error handling in iio_trigger_attach_poll_func Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 016/100] staging: iio: accel: fix error check Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 017/100] iio: accel: kxsd9: fix the usage of spi_w8r8() Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 018/100] iio:ad7266: Fix broken regulator error handling Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 019/100] iio:ad7266: Fix support for optional regulators Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 020/100] iio:ad7266: Fix probe deferral for vref Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 021/100] tty/vt/keyboard: fix OOB access in do_compute_shiftstate() Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 022/100] ALSA: dummy: Fix a use-after-free at closing Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 023/100] ALSA: au88x0: Fix calculation in vortex_wtdma_bufshift() Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 024/100] ALSA: ctl: Stop notification after disconnection Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 025/100] scsi: fix race between simultaneous decrements of ->host_failed Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 026/100] Fix reconnect to not defer smb3 session reconnect long after socket reconnect Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 027/100] xen/acpi: allow xen-acpi-processor driver to load on Xen 4.7 Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 028/100] tmpfs: don't undo fallocate past its last page Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 029/100] tmpfs: fix regression hang in fallocate undo Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 030/100] s390/seccomp: fix error return for filtered system calls Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 031/100] fs/nilfs2: fix potential underflow in call to crc32_le Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 032/100] arc: unwind: warn only once if DW2_UNWIND is disabled Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 033/100] xen/pciback: Fix conf_space read/write overlap check Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 034/100] Input: wacom_w8001 - w8001_MAX_LENGTH should be 13 Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 035/100] Input: xpad - validate USB endpoint count during probe Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 036/100] ext4: verify extent header depth Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 037/100] qeth: delete napi struct when removing a qeth device Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 038/100] mmc: block: fix packed command header endianness Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 039/100] mm: thp: fix SMP race condition between THP page fault and MADV_DONTNEED Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 040/100] x86, asmlinkage, lguest: Pass in globals into assembler statement Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 041/100] can: at91_can: RX queue could get stuck at high bus load Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 042/100] can: fix handling of unmodifiable configuration options fix Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 043/100] can: fix oops caused by wrong rtnl dellink usage Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 044/100] ipr: Clear interrupt on croc/crocodile when running with LSI Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 045/100] net: mvneta: set real interrupt per packet for tx_done Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 046/100] random32: add prandom_u32_max and convert open coded users Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 047/100] tcp: make challenge acks less predictable Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 048/100] net/irda: fix NULL pointer dereference on memory allocation failure Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 049/100] tcp: consider recv buf for the initial window scale Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 050/100] MIPS: KVM: Fix mapped fault broken commpage handling Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 051/100] MIPS: KVM: Add missing gfn range check Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 052/100] MIPS: KVM: Fix gfn range check in kseg0 tlb faults Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 053/100] MIPS: KVM: Propagate kseg0/mapped tlb fault errors Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 054/100] HID: i2c-hid: set power sleep before shutdown Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 055/100] HID: multitouch: Add MT_QUIRK_NOT_SEEN_MEANS_UP to Surface Pro 3 Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 056/100] x86/mm: Improve switch_mm() barrier comments Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 057/100] arm: oabi compat: add missing access checks Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 058/100] KEYS: 64-bit MIPS needs to use compat_sys_keyctl for 32-bit userspace Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 059/100] apparmor: fix ref count leak when profile sha1 hash is read Jiri Slaby
2016-08-19  7:10 ` [PATCH 3.12 060/100] block: fix use-after-free in seq file Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 061/100] sysv, ipc: fix security-layer leaking Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 062/100] fuse: fix wrong assignment of ->flags in fuse_send_init() Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 063/100] crypto: gcm - Filter out async ghash if necessary Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 064/100] crypto: scatterwalk - Fix test in scatterwalk_done Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 065/100] ext4: check for extents that wrap around Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 066/100] ext4: fix deadlock during page writeback Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 067/100] ext4: don't call ext4_should_journal_data() on the journal inode Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 068/100] ext4: short-cut orphan cleanup on error Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 069/100] ext4: fix reference counting bug on block allocation error Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 070/100] usb: renesas_usbhs: protect the CFIFOSEL setting in usbhsg_ep_enable() Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 071/100] USB: serial: option: add support for Telit LE910 PID 0x1206 Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 072/100] gpio: pca953x: Fix NBANK calculation for PCA9536 Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 073/100] s5p-mfc: Set device name for reserved memory region devs Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 074/100] s5p-mfc: Add release callback for " Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 075/100] Bluetooth: Fix l2cap_sock_setsockopt() with optname BT_RCVMTU Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 076/100] cifs: Check for existing directory when opening file with O_CREAT Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 077/100] cifs: fix crash due to race in hmac(md5) handling Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 078/100] CIFS: Fix a possible invalid memory access in smb2_query_symlink() Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 079/100] random: properly align get_random_int_hash Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 080/100] nfs: don't create zero-length requests Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 081/100] ARM: 8579/1: mm: Fix definition of pmd_mknotpresent Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 082/100] netlabel: add address family checks to netlbl_{sock,req}_delattr() Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 083/100] drm/radeon: add a delay after ATPX dGPU power off Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 084/100] drm/radeon: Poll for both connect/disconnect on analog connectors Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 085/100] drm/radeon: fix firmware info version checks Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 086/100] drm/radeon: support backlight control for UNIPHY3 Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 087/100] drm/i915/dp: Revert "drm/i915/dp: fall back to 18 bpp when sink capability is unknown" Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 088/100] balloon: check the number of available pages in leak balloon Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 089/100] ftrace/recordmcount: Work around for addition of metag magic but not relocations Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 090/100] metag: Fix __cmpxchg_u32 asm constraint for CMP Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 091/100] IB/mlx5: Fix MODIFY_QP command input structure Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 092/100] IB/mlx5: Fix returned values of query QP Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 093/100] IB/mlx5: Fix post send fence logic Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 094/100] IB/IPoIB: Don't update neigh validity for unresolved entries Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 095/100] IB/mlx4: Fix the SQ size of an RC QP Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 096/100] ubi: Make volume resize power cut aware Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 097/100] ubi: Fix race condition between ubi device creation and udev Jiri Slaby
2016-08-19  7:11 ` Jiri Slaby [this message]
2016-08-19 10:06   ` [PATCH 3.12 098/100] Input: i8042 - break load dependency between atkbd/psmouse and i8042 Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 099/100] dm flakey: error READ bios during the down_interval Jiri Slaby
2016-08-19  7:11 ` [PATCH 3.12 100/100] module: Invalidate signatures on force-loaded modules Jiri Slaby
2016-08-19  7:54 ` [PATCH 3.12 009/101] netfilter: x_tables: speed up jump target validation Jiri Slaby
2016-08-19 19:03 ` [PATCH 3.12 000/100] 3.12.63-stable review Guenter Roeck
2016-09-06 13:47   ` Jiri Slaby

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=bf55b12c37a06031be8e5221d0ea65e60a46d1a9.1471589700.git.jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=dmitry.torokhov@gmail.com \
    --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 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).