From patchwork Tue Jun 2 02:08:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1302017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bb7L6bS0z9sSW; Tue, 2 Jun 2020 12:08:46 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jfwM5-0005M1-RQ; Tue, 02 Jun 2020 02:08:41 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM3-0005JR-Ck for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:39 +0000 Received: from mail-qv1-f71.google.com ([209.85.219.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM2-0001yd-GE for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:38 +0000 Received: by mail-qv1-f71.google.com with SMTP id a8so2069511qvt.7 for ; Mon, 01 Jun 2020 19:08:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E8oYCXXi2XFrIawxCzNZ9aI89JiNehc5s9UUYswNBV0=; b=pJjHug+tiwb+iqZ4Stt+dLfpE4LlBk08CwFqmTf00H1W7Os5/lDJLgG8bo9WYt1VoF J1/Ysjn5XZaDFmGSCcWVaFNGd+8LZ/2NaQKEPWSLrq1s/N8NtYzu/LJ929TUBN1bppM2 4e3sUnoIdaZPA85n6E47pewLZCzoNc9j5TN4NNu3r+eq2crz8a/GlN44kLUgR7QOnahZ KtxrOkQ+YwwFDAs9VatESmkybMFaeX8IosWbPfOs3uG3+VYJGONW6XQ1XqHmyejGw/bh 08gKeadeg+ZB24MUXF158gkfZhAmeyjmyfBT+s8HgK3kgjjcTnEJ8mTkfDndvPG5nwyi sW4g== X-Gm-Message-State: AOAM532mU+Kk4oDoAQA/A9i4g5WCHYQuJvXXKesQHp8KpmGWgqOUu4Ly BrOHHiE8SOWswUl+O91E+JBd9MkD8lDccGc4JmKJ+NLa+0qjB6xx8mwOtquzOYuCfMNqLXFPZke U+ljZS6yB+Menm4YQOoV9E2t7Og0veqyVveRwdZxl X-Received: by 2002:aed:3907:: with SMTP id l7mr24735205qte.198.1591063717117; Mon, 01 Jun 2020 19:08:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTzQUntu2H+M1hToKU5WQjPdTulsTIzaA9vjGJaN12EHRo5uEYFYgLpovSkb2Ce5aDwwKSqg== X-Received: by 2002:aed:3907:: with SMTP id l7mr24735189qte.198.1591063716768; Mon, 01 Jun 2020 19:08:36 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:35 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 08/21] HID: hyperv: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:04 -0300 Message-Id: <20200602020817.236422-9-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602020817.236422-1-marcelo.cerri@canonical.com> References: <20200602020817.236422-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dexuan Cui BugLink: http://bugs.launchpad.net/bugs/1880032 During the suspend process and resume process, if there is any mouse event, there is a small chance the suspend and the resume process can be aborted because of mousevsc_on_receive() -> pm_wakeup_hard_event(). This behavior can be avoided by disabling the Hyper-V mouse device as a wakeup source: echo disabled > /sys/bus/vmbus/drivers/hid_hyperv/XXX/power/wakeup (XXX is the device's GUID). Signed-off-by: Dexuan Cui Acked-by: Jiri Kosina Signed-off-by: Sasha Levin (cherry picked from commit af13f9ed6f9aa6801d020c48aeb19dca9f0d4f97) Signed-off-by: Marcelo Henrique Cerri --- drivers/hid/hid-hyperv.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c index 79a28fc91521..dddfca555df9 100644 --- a/drivers/hid/hid-hyperv.c +++ b/drivers/hid/hid-hyperv.c @@ -192,6 +192,9 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, if (desc->bLength == 0) goto cleanup; + /* The pointer is not NULL when we resume from hibernation */ + if (input_device->hid_desc != NULL) + kfree(input_device->hid_desc); input_device->hid_desc = kmemdup(desc, desc->bLength, GFP_ATOMIC); if (!input_device->hid_desc) @@ -203,6 +206,9 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, goto cleanup; } + /* The pointer is not NULL when we resume from hibernation */ + if (input_device->report_desc != NULL) + kfree(input_device->report_desc); input_device->report_desc = kzalloc(input_device->report_desc_size, GFP_ATOMIC); @@ -342,6 +348,8 @@ static int mousevsc_connect_to_vsp(struct hv_device *device) struct mousevsc_prt_msg *request; struct mousevsc_prt_msg *response; + reinit_completion(&input_dev->wait_event); + request = &input_dev->protocol_req; memset(request, 0, sizeof(struct mousevsc_prt_msg)); @@ -541,6 +549,30 @@ static int mousevsc_remove(struct hv_device *dev) return 0; } +static int mousevsc_suspend(struct hv_device *dev) +{ + vmbus_close(dev->channel); + + return 0; +} + +static int mousevsc_resume(struct hv_device *dev) +{ + int ret; + + ret = vmbus_open(dev->channel, + INPUTVSC_SEND_RING_BUFFER_SIZE, + INPUTVSC_RECV_RING_BUFFER_SIZE, + NULL, 0, + mousevsc_on_channel_callback, + dev); + if (ret) + return ret; + + ret = mousevsc_connect_to_vsp(dev); + return ret; +} + static const struct hv_vmbus_device_id id_table[] = { /* Mouse guid */ { HV_MOUSE_GUID, }, @@ -554,6 +586,8 @@ static struct hv_driver mousevsc_drv = { .id_table = id_table, .probe = mousevsc_probe, .remove = mousevsc_remove, + .suspend = mousevsc_suspend, + .resume = mousevsc_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, },