From patchwork Fri Apr 22 13:01:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Laws X-Patchwork-Id: 8911701 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6FFD2BF29F for ; Fri, 22 Apr 2016 13:01:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F14C2020F for ; Fri, 22 Apr 2016 13:01:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2913C201F2 for ; Fri, 22 Apr 2016 13:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752599AbcDVNBn (ORCPT ); Fri, 22 Apr 2016 09:01:43 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36536 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752370AbcDVNBm (ORCPT ); Fri, 22 Apr 2016 09:01:42 -0400 Received: by mail-pf0-f195.google.com with SMTP id p185so9852038pfb.3 for ; Fri, 22 Apr 2016 06:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=60hz-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WE0gHIJL0LAZ6jsDaveKbRoXZLx1MhrFodHrxIFFKuM=; b=IZ9U1t/tBhC2m/6i90wMnwa8aSPaKh7faimt8wrQQzdCAjQnjyBwdYJKuGYoxsLH2u VEU1TfVVLO+ovoQqEYl7KO/ahW4NrltDwLlzeZCeR5RRMZpjSJkL1Vu2mRCFWOqP7LSJ LGcndD4KvqutJc4Gv34tcjQSg3h/MNtJSK1nPvoG4vGV8rXlnt8OkoEFuwvWvbA1pwsw 0EEmUKix4UJO5vjjn/ToT2ZJaIitODRIsKwm1eAR2bk6qGr6X1obWNY4eatw1RIxrUap wzbGv4G2dP0XMLEIIMUuaGrFWP/fyLcFIMFJfdk//tvk+QtDjLxB8LNrHejog2Ca84d8 vSwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WE0gHIJL0LAZ6jsDaveKbRoXZLx1MhrFodHrxIFFKuM=; b=iNcCDkgrXFluhJRP6+j1rZ8EH9BnyYPmjq83Pr6qqG7+8oPVcN0NvJIA9qKZ6bRtzb HmxOktY8WDYgjfsZJnhCCJbAbEg7HU1swFMP1E9VnUUkAmmhIRBBnZ4yWHHq1p2qjV52 zq9DFFwQszWsF9liycLMNwmRxlfkxX/ozCEPtyYAiwy4QPaFl5wnveJu/Unvk4aIBEYQ E9xYjXwzhF1Tp/Yi82Cd4ThaskUEjTyW+v+SvCNQYafOKw1MasMjTOz4mhRBQSuNZTqw A/YAIkwmdk3XD3ECnoORnrnzm2y1rxOpHHpMlV0JsN7adJbDTxcdXpflMNN6NgFlRTMv U+3A== X-Gm-Message-State: AOPr4FU8PRtqacIY8SSpY8hVQJZVc/sJvcQCBci6tli9zzcx2otLiV84t+VSs9sGTPuZ3A== X-Received: by 10.98.8.75 with SMTP id c72mr28614541pfd.39.1461330101360; Fri, 22 Apr 2016 06:01:41 -0700 (PDT) Received: from arch-vm.localdomain (pl2290.nas82c.p-tokyo.nttpc.ne.jp. [219.102.86.242]) by smtp.gmail.com with ESMTPSA id h85sm8436045pfj.52.2016.04.22.06.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Apr 2016 06:01:40 -0700 (PDT) From: Mark Laws To: haiyangz@microsoft.com Cc: Mark Laws , devel@linuxdriverproject.org, linux-input@vger.kernel.org Subject: [PATCH] Input: i8042 - Fix console keyboard support on Gen2 Hyper-V VMs Date: Fri, 22 Apr 2016 22:01:00 +0900 Message-Id: <1461330060-35567-2-git-send-email-mdl@60hz.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1461330060-35567-1-git-send-email-mdl@60hz.org> References: <1461330060-35567-1-git-send-email-mdl@60hz.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As explained in 1407814240-4275-1-git-send-email-decui@microsoft.com: > 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) The transitive dependency on i8042.c is non-trivial--there appears to be no obvious way to untangle it other than by duplicating much of atkbd.c within hyperv-keyboard--so we employ a simple workaround: keep i8042.ko loaded even if no i8042 device is detected, but set a flag so that any calls into the module simply return (since we don't want to try to interact with the non-existent i8042). This allows atkbd.c and libps2.c to load, solving the problem. Signed-off-by: Mark Laws --- drivers/input/serio/i8042.c | 50 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index 4541957..00f73d3 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -132,6 +132,7 @@ struct i8042_port { static struct i8042_port i8042_ports[I8042_NUM_PORTS]; +static bool i8042_present; static unsigned char i8042_initial_ctr; static unsigned char i8042_ctr; static bool i8042_mux_present; @@ -163,6 +164,9 @@ int i8042_install_filter(bool (*filter)(unsigned char data, unsigned char str, unsigned long flags; int ret = 0; + if (!i8042_present) + return 0; + spin_lock_irqsave(&i8042_lock, flags); if (i8042_platform_filter) { @@ -184,6 +188,9 @@ int i8042_remove_filter(bool (*filter)(unsigned char data, unsigned char str, unsigned long flags; int ret = 0; + if (!i8042_present) + return 0; + spin_lock_irqsave(&i8042_lock, flags); if (i8042_platform_filter != filter) { @@ -313,6 +320,9 @@ int i8042_command(unsigned char *param, int command) unsigned long flags; int retval; + if (!i8042_present) + return 0; + spin_lock_irqsave(&i8042_lock, flags); retval = __i8042_command(param, command); spin_unlock_irqrestore(&i8042_lock, flags); @@ -1380,6 +1390,9 @@ bool i8042_check_port_owner(const struct serio *port) { int i; + if (!i8042_present) + return false; + for (i = 0; i < I8042_NUM_PORTS; i++) if (i8042_ports[i].serio == port) return true; @@ -1493,6 +1506,10 @@ static int __init i8042_probe(struct platform_device *dev) { int error; + error = i8042_controller_check(); + if (error) + return error; + i8042_platform_device = dev; if (i8042_reset) { @@ -1569,38 +1586,39 @@ static int __init i8042_init(void) dbg_init(); + i8042_present = false; + err = i8042_platform_init(); if (err) return err; - err = i8042_controller_check(); - if (err) - goto err_platform_exit; - pdev = platform_create_bundle(&i8042_driver, i8042_probe, NULL, 0, NULL, 0); - if (IS_ERR(pdev)) { - err = PTR_ERR(pdev); - goto err_platform_exit; - } + if (IS_ERR(pdev)) + return 0; /* load anyway since some modules depend on our symbols */ bus_register_notifier(&serio_bus, &i8042_kbd_bind_notifier_block); panic_blink = i8042_panic_blink; + i8042_present = true; return 0; - - err_platform_exit: - i8042_platform_exit(); - return err; } static void __exit i8042_exit(void) { - platform_device_unregister(i8042_platform_device); - platform_driver_unregister(&i8042_driver); + if (i8042_present) { + platform_device_unregister(i8042_platform_device); + platform_driver_unregister(&i8042_driver); + } + i8042_platform_exit(); - bus_unregister_notifier(&serio_bus, &i8042_kbd_bind_notifier_block); - panic_blink = NULL; + if (i8042_present) { + bus_unregister_notifier(&serio_bus, + &i8042_kbd_bind_notifier_block); + panic_blink = NULL; + } + + i8042_present = false; } module_init(i8042_init);