From patchwork Tue Jun 2 02:07:57 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: 1302009 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 49bb782Cq8z9sSJ; Tue, 2 Jun 2020 12:08:34 +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 1jfwLs-0005CJ-Ax; Tue, 02 Jun 2020 02:08:28 +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 1jfwLq-0005C7-CD for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:26 +0000 Received: from mail-qv1-f72.google.com ([209.85.219.72]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwLp-0001xz-US for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:26 +0000 Received: by mail-qv1-f72.google.com with SMTP id t20so2035311qvy.16 for ; Mon, 01 Jun 2020 19:08:25 -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=McMZdUNxEtwbf7ECmzRmX3haNrkLnJ9bCJ/JlYfZECU=; b=YRw2l0ZobLn1Fg//2ORBnT7xhEp/vfW7M7eO8amsBfY63o9ttrnulA4kM87O5546lF xZH6JGnxNpZ+PpLsZ25s3fUQ0Zrz3gFCLtmMdiDOjv+od+QB6n5tjFzL6RUjbH1nRl7e q4WxCEXU9UNbq9C5vDaebRjEhMOy/LpALeqVkHUXbx+HMqyzBeVS2VSjJU06bwEd484h K7IRbGbVwqRoc9/JSoda+nnlycpk/sPBHL5HWzyLSbRyFDaAj/YtV9GEmgaPtQbkziVX 7r91XbY46uuOsldI54cV7XrVhvGNWgONc3LsezXG1ru9r/DIN8siXgi1hxtD/8HvvDYc Y7+g== X-Gm-Message-State: AOAM531lxC9n2vQROa2iJMJZ91IpbCxBGSVhH3M9PURn7f5fPLEpj+/q dZrZTkD2/5YapOtVTikalHA8JFJbhI55wKKwL05lB/6hHv9W05zS9i/YbI2nJ2Iz+/EL3q3QIhH wuC0aYBLy5O8vX3Nxtv32K3UaSuaveZIJ2lwxIO+7 X-Received: by 2002:ac8:374e:: with SMTP id p14mr25368654qtb.361.1591063704184; Mon, 01 Jun 2020 19:08:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGem6jVVUARlJumFQtgMzKS5bqtJfxBLuDWvQFxgHHfnB2P96EfEcD/L6PnPqDHbtyu3kwgA== X-Received: by 2002:ac8:374e:: with SMTP id p14mr25368628qtb.361.1591063703547; Mon, 01 Jun 2020 19:08:23 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:22 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 01/21] x86/hyperv: Initialize clockevents earlier in CPU onlining Date: Mon, 1 Jun 2020 23:07:57 -0300 Message-Id: <20200602020817.236422-2-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: Michael Kelley BugLink: http://bugs.launchpad.net/bugs/1880032 Hyper-V has historically initialized stimer-based clockevents late in the process of onlining a CPU because clockevents depend on stimer interrupts. In the original Hyper-V design, stimer interrupts generate a VMbus message, so the VMbus machinery must be running first, and VMbus can't be initialized until relatively late. On x86/64, LAPIC timer based clockevents are used during early initialization before VMbus and stimer-based clockevents are ready, and again during CPU offlining after the stimer clockevents have been shut down. Unfortunately, this design creates problems when offlining CPUs for hibernation or other purposes. stimer-based clockevents are shut down relatively early in the offlining process, so clockevents_unbind_device() must be used to fallback to the LAPIC-based clockevents for the remainder of the offlining process. Furthermore, the late initialization and early shutdown of stimer-based clockevents doesn't work well on ARM64 since there is no other timer like the LAPIC to fallback to. So CPU onlining and offlining doesn't work properly. Fix this by recognizing that stimer Direct Mode is the normal path for newer versions of Hyper-V on x86/64, and the only path on other architectures. With stimer Direct Mode, stimer interrupts don't require any VMbus machinery. stimer clockevents can be initialized and shut down consistent with how it is done for other clockevent devices. While the old VMbus-based stimer interrupts must still be supported for backward compatibility on x86, that mode of operation can be treated as legacy. So add a new Hyper-V stimer entry in the CPU hotplug state list, and use that new state when in Direct Mode. Update the Hyper-V clocksource driver to allocate and initialize stimer clockevents earlier during boot. Update Hyper-V initialization and the VMbus driver to use this new design. As a result, the LAPIC timer is no longer used during boot or CPU onlining/offlining and clockevents_unbind_device() is not called. But retain the old design as a legacy implementation for older versions of Hyper-V that don't support Direct Mode. Signed-off-by: Michael Kelley Signed-off-by: Thomas Gleixner Tested-by: Dexuan Cui Reviewed-by: Dexuan Cui Link: https://lkml.kernel.org/r/1573607467-9456-1-git-send-email-mikelley@microsoft.com (cherry picked from commit 4df4cb9e99f83b70d54bc0e25081ac23cceafcbc) Signed-off-by: Marcelo Henrique Cerri --- arch/x86/hyperv/hv_init.c | 6 ++ drivers/clocksource/hyperv_timer.c | 154 +++++++++++++++++++++++------ drivers/hv/hv.c | 4 +- drivers/hv/vmbus_drv.c | 30 +++--- include/clocksource/hyperv_timer.h | 7 +- include/linux/cpuhotplug.h | 1 + 6 files changed, 151 insertions(+), 51 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 5739fa0886b1..60458769931b 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -320,6 +320,12 @@ void __init hyperv_init(void) hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + /* + * Ignore any errors in setting up stimer clockevents + * as we can run with the LAPIC timer as a fallback. + */ + (void)hv_stimer_alloc(); + hv_apic_init(); x86_init.pci.arch_init = hv_pci_init; diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 36933e2b3b0d..0d29b05d8889 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,15 @@ static u64 hv_sched_clock_offset __ro_after_init; * mechanism is used when running on older versions of Hyper-V * that don't support Direct Mode. While Hyper-V provides * four stimer's per CPU, Linux uses only stimer0. + * + * Because Direct Mode does not require processing a VMbus + * message, stimer interrupts can be enabled earlier in the + * process of booting a CPU, and consistent with when timer + * interrupts are enabled for other clocksource drivers. + * However, for legacy versions of Hyper-V when Direct Mode + * is not enabled, setting up stimer interrupts must be + * delayed until VMbus is initialized and can process the + * interrupt message. */ static bool direct_mode_enabled; @@ -102,17 +112,12 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt) /* * hv_stimer_init - Per-cpu initialization of the clockevent */ -void hv_stimer_init(unsigned int cpu) +static int hv_stimer_init(unsigned int cpu) { struct clock_event_device *ce; - /* - * Synthetic timers are always available except on old versions of - * Hyper-V on x86. In that case, just return as Linux will use a - * clocksource based on emulated PIT or LAPIC timer hardware. - */ - if (!(ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE)) - return; + if (!hv_clock_event) + return 0; ce = per_cpu_ptr(hv_clock_event, cpu); ce->name = "Hyper-V clockevent"; @@ -127,28 +132,55 @@ void hv_stimer_init(unsigned int cpu) HV_CLOCK_HZ, HV_MIN_DELTA_TICKS, HV_MAX_MAX_DELTA_TICKS); + return 0; } -EXPORT_SYMBOL_GPL(hv_stimer_init); /* * hv_stimer_cleanup - Per-cpu cleanup of the clockevent */ -void hv_stimer_cleanup(unsigned int cpu) +int hv_stimer_cleanup(unsigned int cpu) { struct clock_event_device *ce; - /* Turn off clockevent device */ - if (ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE) { - ce = per_cpu_ptr(hv_clock_event, cpu); + if (!hv_clock_event) + return 0; + + /* + * In the legacy case where Direct Mode is not enabled + * (which can only be on x86/64), stimer cleanup happens + * relatively early in the CPU offlining process. We + * must unbind the stimer-based clockevent device so + * that the LAPIC timer can take over until clockevents + * are no longer needed in the offlining process. Note + * that clockevents_unbind_device() eventually calls + * hv_ce_shutdown(). + * + * The unbind should not be done when Direct Mode is + * enabled because we may be on an architecture where + * there are no other clockevent devices to fallback to. + */ + ce = per_cpu_ptr(hv_clock_event, cpu); + if (direct_mode_enabled) hv_ce_shutdown(ce); - } + else + clockevents_unbind_device(ce, cpu); + + return 0; } EXPORT_SYMBOL_GPL(hv_stimer_cleanup); /* hv_stimer_alloc - Global initialization of the clockevent and stimer0 */ -int hv_stimer_alloc(int sint) +int hv_stimer_alloc(void) { - int ret; + int ret = 0; + + /* + * Synthetic timers are always available except on old versions of + * Hyper-V on x86. In that case, return as error as Linux will use a + * clockevent based on emulated LAPIC timer hardware. + */ + if (!(ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE)) + return -EINVAL; hv_clock_event = alloc_percpu(struct clock_event_device); if (!hv_clock_event) @@ -159,22 +191,78 @@ int hv_stimer_alloc(int sint) if (direct_mode_enabled) { ret = hv_setup_stimer0_irq(&stimer0_irq, &stimer0_vector, hv_stimer0_isr); - if (ret) { - free_percpu(hv_clock_event); - hv_clock_event = NULL; - return ret; - } + if (ret) + goto free_percpu; + + /* + * Since we are in Direct Mode, stimer initialization + * can be done now with a CPUHP value in the same range + * as other clockevent devices. + */ + ret = cpuhp_setup_state(CPUHP_AP_HYPERV_TIMER_STARTING, + "clockevents/hyperv/stimer:starting", + hv_stimer_init, hv_stimer_cleanup); + if (ret < 0) + goto free_stimer0_irq; } + return ret; - stimer0_message_sint = sint; - return 0; +free_stimer0_irq: + hv_remove_stimer0_irq(stimer0_irq); + stimer0_irq = 0; +free_percpu: + free_percpu(hv_clock_event); + hv_clock_event = NULL; + return ret; } EXPORT_SYMBOL_GPL(hv_stimer_alloc); +/* + * hv_stimer_legacy_init -- Called from the VMbus driver to handle + * the case when Direct Mode is not enabled, and the stimer + * must be initialized late in the CPU onlining process. + * + */ +void hv_stimer_legacy_init(unsigned int cpu, int sint) +{ + if (direct_mode_enabled) + return; + + /* + * This function gets called by each vCPU, so setting the + * global stimer_message_sint value each time is conceptually + * not ideal, but the value passed in is always the same and + * it avoids introducing yet another interface into this + * clocksource driver just to set the sint in the legacy case. + */ + stimer0_message_sint = sint; + (void)hv_stimer_init(cpu); +} +EXPORT_SYMBOL_GPL(hv_stimer_legacy_init); + +/* + * hv_stimer_legacy_cleanup -- Called from the VMbus driver to + * handle the case when Direct Mode is not enabled, and the + * stimer must be cleaned up early in the CPU offlining + * process. + */ +void hv_stimer_legacy_cleanup(unsigned int cpu) +{ + if (direct_mode_enabled) + return; + (void)hv_stimer_cleanup(cpu); +} +EXPORT_SYMBOL_GPL(hv_stimer_legacy_cleanup); + + /* hv_stimer_free - Free global resources allocated by hv_stimer_alloc() */ void hv_stimer_free(void) { - if (direct_mode_enabled && (stimer0_irq != 0)) { + if (!hv_clock_event) + return; + + if (direct_mode_enabled) { + cpuhp_remove_state(CPUHP_AP_HYPERV_TIMER_STARTING); hv_remove_stimer0_irq(stimer0_irq); stimer0_irq = 0; } @@ -190,14 +278,20 @@ EXPORT_SYMBOL_GPL(hv_stimer_free); void hv_stimer_global_cleanup(void) { int cpu; - struct clock_event_device *ce; - if (ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE) { - for_each_present_cpu(cpu) { - ce = per_cpu_ptr(hv_clock_event, cpu); - clockevents_unbind_device(ce, cpu); - } + /* + * hv_stime_legacy_cleanup() will stop the stimer if Direct + * Mode is not enabled, and fallback to the LAPIC timer. + */ + for_each_present_cpu(cpu) { + hv_stimer_legacy_cleanup(cpu); } + + /* + * If Direct Mode is enabled, the cpuhp teardown callback + * (hv_stimer_cleanup) will be run on all CPUs to stop the + * stimers. + */ hv_stimer_free(); } EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup); diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index fcc52797c169..6098e0cbdb4b 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -202,7 +202,7 @@ int hv_synic_init(unsigned int cpu) { hv_synic_enable_regs(cpu); - hv_stimer_init(cpu); + hv_stimer_legacy_init(cpu, VMBUS_MESSAGE_SINT); return 0; } @@ -277,7 +277,7 @@ int hv_synic_cleanup(unsigned int cpu) if (channel_found && vmbus_connection.conn_state == CONNECTED) return -EBUSY; - hv_stimer_cleanup(cpu); + hv_stimer_legacy_cleanup(cpu); hv_synic_disable_regs(cpu); diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 9cdd434bb340..a8648fe63357 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1375,10 +1375,6 @@ static int vmbus_bus_init(void) if (ret) goto err_alloc; - ret = hv_stimer_alloc(VMBUS_MESSAGE_SINT); - if (ret < 0) - goto err_alloc; - /* * Initialize the per-cpu interrupt state and stimer state. * Then connect to the host. @@ -1445,9 +1441,8 @@ static int vmbus_bus_init(void) err_connect: cpuhp_remove_state(hyperv_cpuhp_online); err_cpuhp: - hv_stimer_free(); -err_alloc: hv_synic_free(); +err_alloc: hv_remove_vmbus_irq(); bus_unregister(&hv_bus); @@ -2366,20 +2361,23 @@ static void hv_crash_handler(struct pt_regs *regs) static int hv_synic_suspend(void) { /* - * When we reach here, all the non-boot CPUs have been offlined, and - * the stimers on them have been unbound in hv_synic_cleanup() -> + * When we reach here, all the non-boot CPUs have been offlined. + * If we're in a legacy configuration where stimer Direct Mode is + * not enabled, the stimers on the non-boot CPUs have been unbound + * in hv_synic_cleanup() -> hv_stimer_legacy_cleanup() -> * hv_stimer_cleanup() -> clockevents_unbind_device(). * - * hv_synic_suspend() only runs on CPU0 with interrupts disabled. Here - * we do not unbind the stimer on CPU0 because: 1) it's unnecessary - * because the interrupts remain disabled between syscore_suspend() - * and syscore_resume(): see create_image() and resume_target_kernel(); + * hv_synic_suspend() only runs on CPU0 with interrupts disabled. + * Here we do not call hv_stimer_legacy_cleanup() on CPU0 because: + * 1) it's unnecessary as interrupts remain disabled between + * syscore_suspend() and syscore_resume(): see create_image() and + * resume_target_kernel() * 2) the stimer on CPU0 is automatically disabled later by * syscore_suspend() -> timekeeping_suspend() -> tick_suspend() -> ... - * -> clockevents_shutdown() -> ... -> hv_ce_shutdown(); 3) a warning - * would be triggered if we call clockevents_unbind_device(), which - * may sleep, in an interrupts-disabled context. So, we intentionally - * don't call hv_stimer_cleanup(0) here. + * -> clockevents_shutdown() -> ... -> hv_ce_shutdown() + * 3) a warning would be triggered if we call + * clockevents_unbind_device(), which may sleep, in an + * interrupts-disabled context. */ hv_synic_disable_regs(0); diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h index 422f5e5237be..553e539469f0 100644 --- a/include/clocksource/hyperv_timer.h +++ b/include/clocksource/hyperv_timer.h @@ -21,10 +21,11 @@ #define HV_MIN_DELTA_TICKS 1 /* Routines called by the VMbus driver */ -extern int hv_stimer_alloc(int sint); +extern int hv_stimer_alloc(void); extern void hv_stimer_free(void); -extern void hv_stimer_init(unsigned int cpu); -extern void hv_stimer_cleanup(unsigned int cpu); +extern int hv_stimer_cleanup(unsigned int cpu); +extern void hv_stimer_legacy_init(unsigned int cpu, int sint); +extern void hv_stimer_legacy_cleanup(unsigned int cpu); extern void hv_stimer_global_cleanup(void); extern void hv_stimer0_isr(void); diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 2d55cee638fc..363e81766823 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -130,6 +130,7 @@ enum cpuhp_state { CPUHP_AP_ARC_TIMER_STARTING, CPUHP_AP_RISCV_TIMER_STARTING, CPUHP_AP_CSKY_TIMER_STARTING, + CPUHP_AP_HYPERV_TIMER_STARTING, CPUHP_AP_KVM_STARTING, CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, CPUHP_AP_KVM_ARM_VGIC_STARTING, From patchwork Tue Jun 2 02:07:58 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: 1302011 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 49bb782gRMz9sSf; Tue, 2 Jun 2020 12:08:34 +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 1jfwLu-0005Cn-GQ; Tue, 02 Jun 2020 02:08:30 +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 1jfwLr-0005CD-B4 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:27 +0000 Received: from mail-qk1-f197.google.com ([209.85.222.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwLr-0001y5-11 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:27 +0000 Received: by mail-qk1-f197.google.com with SMTP id v6so10020741qkh.7 for ; Mon, 01 Jun 2020 19:08:26 -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=AJ87Pr5G2rIqi3bey6f73wywyydo7i2ACChsoLahVRY=; b=GeJ4ONJ7xTxdkawSZZTPdo2ZWvhfDpMbb8pD3bC3Xq9BYgAE5up2Nw5gp3TXnNa1OW iwKi4GW3YvtpoMK+BuudX0v5QZMfXw5+tYAUe3LG3+B1CUjuQfj8ygtYregcyUPVo2eS Hfm6BLK6Rw6d6gxXVguQZtT4zR+Lln7PLjPtob42Nii8AQa1kUL1zeqtB3oGMtrJZvIF 7Tu7ZvCS8GR6t4NDXFKxs2LWxUtdnTrC14U8hh1WmokM9Pe196nwSNCQ4gFFlv5OGTva /mUwMhW/MyvyK4sE2CVVBnkb6lb4MSyj+5dtiJ3HL6jjnuOMirtk9NX4bo8oq0RFADoE APhA== X-Gm-Message-State: AOAM5328emRinh8DRPGpb76Hft43LwT97FSGj/+Qm5S/lCKfieBINuIG RL9/St/eG4E+xgSvesytriJhPYy/XvRjWEyItxgw0eRc9E3NVZqRqZqJcfbzpTkfsbqvQltnEis h4YTv9Y14WRpvZTM20cjdwGjWYcSmlKlbnFEvlgaM X-Received: by 2002:a0c:c2c2:: with SMTP id c2mr22521581qvi.150.1591063705627; Mon, 01 Jun 2020 19:08:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3rkCyo1PapIoSPzm4z5JBPFNqK5pceHOKcqk4vCFFcLUHIR2buIq1d3t8LYKwqLtopW7G4A== X-Received: by 2002:a0c:c2c2:: with SMTP id c2mr22521571qvi.150.1591063705308; Mon, 01 Jun 2020 19:08:25 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:24 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 02/21] scsi: storvsc: Add the support of hibernation Date: Mon, 1 Jun 2020 23:07:58 -0300 Message-Id: <20200602020817.236422-3-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 When we're in storvsc_suspend(), we're sure the SCSI layer has quiesced the scsi device by scsi_bus_suspend() -> ... -> scsi_device_quiesce(), so the low level SCSI adapter driver only needs to suspend/resume its own state. Signed-off-by: Dexuan Cui Acked-by: Martin K. Petersen Signed-off-by: Sasha Levin (cherry picked from commit 56fb105859345d65aed08ebbb0f6160c4f0777eb) Signed-off-by: Marcelo Henrique Cerri --- drivers/scsi/storvsc_drv.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 7402bc63cdc2..423972dfefae 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1727,6 +1727,13 @@ static const struct hv_vmbus_device_id id_table[] = { MODULE_DEVICE_TABLE(vmbus, id_table); +static const struct { guid_t guid; } fc_guid = { HV_SYNTHFC_GUID }; + +static bool hv_dev_is_fc(struct hv_device *hv_dev) +{ + return guid_equal(&fc_guid.guid, &hv_dev->dev_type); +} + static int storvsc_probe(struct hv_device *device, const struct hv_vmbus_device_id *dev_id) { @@ -1942,11 +1949,45 @@ static int storvsc_remove(struct hv_device *dev) return 0; } +static int storvsc_suspend(struct hv_device *hv_dev) +{ + struct storvsc_device *stor_device = hv_get_drvdata(hv_dev); + struct Scsi_Host *host = stor_device->host; + struct hv_host_device *host_dev = shost_priv(host); + + storvsc_wait_to_drain(stor_device); + + drain_workqueue(host_dev->handle_error_wq); + + vmbus_close(hv_dev->channel); + + memset(stor_device->stor_chns, 0, + num_possible_cpus() * sizeof(void *)); + + kfree(stor_device->stor_chns); + stor_device->stor_chns = NULL; + + cpumask_clear(&stor_device->alloced_cpus); + + return 0; +} + +static int storvsc_resume(struct hv_device *hv_dev) +{ + int ret; + + ret = storvsc_connect_to_vsp(hv_dev, storvsc_ringbuffer_size, + hv_dev_is_fc(hv_dev)); + return ret; +} + static struct hv_driver storvsc_drv = { .name = KBUILD_MODNAME, .id_table = id_table, .probe = storvsc_probe, .remove = storvsc_remove, + .suspend = storvsc_suspend, + .resume = storvsc_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, From patchwork Tue Jun 2 02:07:59 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: 1302012 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 49bb782WtGz9sSW; Tue, 2 Jun 2020 12:08:35 +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 1jfwLu-0005D1-O3; Tue, 02 Jun 2020 02:08:30 +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 1jfwLt-0005CX-47 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:29 +0000 Received: from mail-qt1-f199.google.com ([209.85.160.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwLs-0001yB-QY for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:28 +0000 Received: by mail-qt1-f199.google.com with SMTP id o11so12285700qti.23 for ; Mon, 01 Jun 2020 19:08:28 -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=w1dcrAoOteaIIIqjARRW+scCMcLNO1fUJDC++Mwgy8E=; b=pBK6PQB2xkn6b+qCx6hMX968hAYHr27SwrJwJ555NhWUY+8OxKRshzGoENGdcRBZnQ Il4xDvk54rNTPwsWCb1dfXsxNLpiDwaXWTJN2hriA/Mp13NjVzNrj8Ym4ijxaggxIXt6 dhAWKuNS+hfIyVYI1kd3ypOPXOY6vyJoHY4bgyH2wYaVmF6smlYQP72iLJtxfak81WTm f4bqcLFrkcuEPo9pa5HFKce6tFppKLcviUKsLWmh4DmIgvGhVXSpSCXuG7bkwkfA35TG UeCKB7VW0qYx3I3YT0tKEWxkPVqw3vut0kxcGcKOqiDdhSbrBDzi+Dqhk2GUrqTggu8t GuVg== X-Gm-Message-State: AOAM5309Xko2rESAGXOvmblnck7OGI+HAthmNCtljOQD5HEzSrngL580 ARB+46MsR9YYsDaSLJBDQ43InRNAVUmWUZKGQAkfTSDQUtDNj4Tc+5a0rxOU0NISG+oZ3um+i7g YIGyrI5cC+hHbW6zAaFZMPG9NhZ0hqV26AFRKVCss X-Received: by 2002:a37:a416:: with SMTP id n22mr22341264qke.49.1591063707470; Mon, 01 Jun 2020 19:08:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0Z7Lm0HgT+3UrCmGES761vQ3+BPFk9s/isdqIQqT8iVF08OCRkJIApyn3SQjDdIOcGIplcg== X-Received: by 2002:a37:a416:: with SMTP id n22mr22341257qke.49.1591063707121; Mon, 01 Jun 2020 19:08:27 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:26 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 03/21] video: hyperv_fb: Add the support of hibernation Date: Mon, 1 Jun 2020 23:07:59 -0300 Message-Id: <20200602020817.236422-4-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 This patch depends on the vmbus side change of the definition of struct hv_driver. Signed-off-by: Dexuan Cui Signed-off-by: Sasha Levin (cherry picked from commit 1ecf302021040194ae46cceefe33ab75577e356d) Signed-off-by: Marcelo Henrique Cerri --- drivers/video/fbdev/hyperv_fb.c | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c index 2dcb7c58b31e..fe4731f97df7 100644 --- a/drivers/video/fbdev/hyperv_fb.c +++ b/drivers/video/fbdev/hyperv_fb.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -211,6 +212,7 @@ struct hvfb_par { struct delayed_work dwork; bool update; + bool update_saved; /* The value of 'update' before hibernation */ u32 pseudo_palette[16]; u8 init_buf[MAX_VMBUS_PKT_SIZE]; @@ -878,6 +880,61 @@ static int hvfb_remove(struct hv_device *hdev) return 0; } +static int hvfb_suspend(struct hv_device *hdev) +{ + struct fb_info *info = hv_get_drvdata(hdev); + struct hvfb_par *par = info->par; + + console_lock(); + + /* 1 means do suspend */ + fb_set_suspend(info, 1); + + cancel_delayed_work_sync(&par->dwork); + + par->update_saved = par->update; + par->update = false; + par->fb_ready = false; + + vmbus_close(hdev->channel); + + console_unlock(); + + return 0; +} + +static int hvfb_resume(struct hv_device *hdev) +{ + struct fb_info *info = hv_get_drvdata(hdev); + struct hvfb_par *par = info->par; + int ret; + + console_lock(); + + ret = synthvid_connect_vsp(hdev); + if (ret != 0) + goto out; + + ret = synthvid_send_config(hdev); + if (ret != 0) { + vmbus_close(hdev->channel); + goto out; + } + + par->fb_ready = true; + par->update = par->update_saved; + + schedule_delayed_work(&par->dwork, HVFB_UPDATE_DELAY); + + /* 0 means do resume */ + fb_set_suspend(info, 0); + +out: + console_unlock(); + + return ret; +} + static const struct pci_device_id pci_stub_id_table[] = { { @@ -901,6 +958,8 @@ static struct hv_driver hvfb_drv = { .id_table = id_table, .probe = hvfb_probe, .remove = hvfb_remove, + .suspend = hvfb_suspend, + .resume = hvfb_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, From patchwork Tue Jun 2 02:08:00 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: 1302013 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 49bb793LpTz9sSy; Tue, 2 Jun 2020 12:08:37 +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 1jfwLx-0005Ep-Dl; Tue, 02 Jun 2020 02:08:33 +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 1jfwLu-0005DM-W1 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:30 +0000 Received: from mail-qt1-f199.google.com ([209.85.160.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwLu-0001yK-JV for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:30 +0000 Received: by mail-qt1-f199.google.com with SMTP id n37so12306091qtf.18 for ; Mon, 01 Jun 2020 19:08:30 -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=NhXx/Ylc4HmsbcUQ2/+VddzqCTlfyegg6XTDkbMHvy4=; b=bWG1ObmHyTIV+lyQkksU38HiiwVqbz5a9yiN86xzJwFdzqRVlIi6XK9Kh7p8YuU0Sz zSkb/SlntcsFxkrqgG/++GWniZ2/aG/Af5xZSwJN03q8T1V23uHf2qmID8cbO4fIAjcN fEEwfpSjFJk1RqEzon1M0cUkCISm7JxbhfdrpGhE2+Um9uj7Z4oEPK1j2jZQwHSIErPY n6ixKmAaF9uV5iYK+SXOueHCnHkhhpdJO3GjKKFnoe4N0VwOv1ECFTWMhw0OBl1eIzyx KkqhzUOaod8xdam7tDVw+MLZ5vK4GeQu4tqkU35EWhrA1/dvyhpT+tycuoishtK+rJWk 9yAw== X-Gm-Message-State: AOAM5329FOSsX7Lqxa/I+YFvSDv4bLWi54335GkQUKswxyM/dqeLdqFv d+eYteSlbYW2/d5bQg8jmNEI6pRwWGXhPUptEjVrtq8V1QkBVTOFZjf7bQR7LU+MrraTHVg/HlN +RKrDkZD2e20213lT7Wz7i2+3h7I+9BQFTlhx8ck2 X-Received: by 2002:a0c:ffca:: with SMTP id h10mr11074466qvv.238.1591063709199; Mon, 01 Jun 2020 19:08:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvRCbrIdV5GPzfHrWK5nFo4nklfUMtyKSH9brA75YgnuEZgIWm2x+7ULZXQ00mQ+2KgeKvog== X-Received: by 2002:a0c:ffca:: with SMTP id h10mr11074448qvv.238.1591063708862; Mon, 01 Jun 2020 19:08:28 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:28 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 04/21] hv_sock: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:00 -0300 Message-Id: <20200602020817.236422-5-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 Add the necessary dummy callbacks for hibernation. Signed-off-by: Dexuan Cui Acked-by: David S. Miller Signed-off-by: Sasha Levin (cherry picked from commit 2194c2eb6717f2ea7dc793ad9cbf44d359a3f696) Signed-off-by: Marcelo Henrique Cerri --- net/vmw_vsock/hyperv_transport.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c index 463cefc1e5ae..db33a412ccf9 100644 --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -888,6 +888,24 @@ static int hvs_remove(struct hv_device *hdev) return 0; } +/* hv_sock connections can not persist across hibernation, and all the hv_sock + * channels are forced to be rescinded before hibernation: see + * vmbus_bus_suspend(). Here the dummy hvs_suspend() and hvs_resume() + * are only needed because hibernation requires that every vmbus device's + * driver should have a .suspend and .resume callback: see vmbus_suspend(). + */ +static int hvs_suspend(struct hv_device *hv_dev) +{ + /* Dummy */ + return 0; +} + +static int hvs_resume(struct hv_device *dev) +{ + /* Dummy */ + return 0; +} + /* This isn't really used. See vmbus_match() and vmbus_probe() */ static const struct hv_vmbus_device_id id_table[] = { {}, @@ -899,6 +917,8 @@ static struct hv_driver hvs_drv = { .id_table = id_table, .probe = hvs_probe, .remove = hvs_remove, + .suspend = hvs_suspend, + .resume = hvs_resume, }; static int __init hvs_init(void) From patchwork Tue Jun 2 02:08:01 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: 1302014 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 49bb7B3nfnz9sT5; Tue, 2 Jun 2020 12:08:38 +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 1jfwLy-0005GE-JK; Tue, 02 Jun 2020 02:08:34 +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 1jfwLx-0005EF-4f for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:33 +0000 Received: from mail-qk1-f200.google.com ([209.85.222.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwLw-0001yP-Jb for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:32 +0000 Received: by mail-qk1-f200.google.com with SMTP id w14so10070966qkb.0 for ; Mon, 01 Jun 2020 19:08:32 -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=N82XOjdEOecw930sgYr6sFh7uBRdkUmIfG+5BN3r1AQ=; b=pvzaIEr78t6iW1NKqh4y17YFNQbl5l8N9HOj4ZYHqigJEsXPUpnKLbUAqVVkbSjCCg mit4PmNQRMHO1VrUd5QtBLjpbvKSTeN/TI/YcxrbuI1cr5Ze5UHpar1q8+HO9QgaIxF4 zSQ9ubq2KvAjO8eE3jD0W3T5BaK3UB/irxkm9Sv2YmbmOCDUOCgd9sRvEciAJzqF6bUe umSugVnbwMs9eOcdNQBmE0XAXuyPcR2tEGrxO4FxqoP9QBUJ47hSAaY6u3gc69CG95sl 1KY2MarqXwYCrl89mD5VP+fhNZCQinWs6yjFQXlWWU4EFEUiLVi2b3pif6tXKDThYhVN y5Gw== X-Gm-Message-State: AOAM530RDU1N2NZ0bjamDAQj7nqPlEqOo6JT8fjEylR/vK1TVj58vrFY rwfjFq52fmn35aIwXqHiPHpF3FtHAapn+4qajdexavj8hkbAu0uzSH2hhWGNueqV80DM50eyI+p UUdHmeSX2GIhnkufyGtBWkPAZB9v56MPbk1FEGuXg X-Received: by 2002:a05:620a:483:: with SMTP id 3mr21530594qkr.299.1591063711226; Mon, 01 Jun 2020 19:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUOeTeOKR8Y2bhPOrRvHEptedcqV7y13PyYGxVEHZRSOwnySmnbRxXuacGxzESrnGB73tkzA== X-Received: by 2002:a05:620a:483:: with SMTP id 3mr21530583qkr.299.1591063710907; Mon, 01 Jun 2020 19:08:30 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:30 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 05/21] hv_netvsc: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:01 -0300 Message-Id: <20200602020817.236422-6-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 The existing netvsc_detach() and netvsc_attach() APIs make it easy to implement the suspend/resume callbacks. Signed-off-by: Dexuan Cui Reviewed-by: Haiyang Zhang Signed-off-by: Sasha Levin (cherry picked from commit 0efeea5fb15357f0a582c89c02ef0b6ef58defb5) Signed-off-by: Marcelo Henrique Cerri --- drivers/net/hyperv/hyperv_net.h | 3 ++ drivers/net/hyperv/netvsc_drv.c | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index a2cd533e2b71..64b90451443a 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -957,6 +957,9 @@ struct net_device_context { u32 vf_alloc; /* Serial number of the VF to team with */ u32 vf_serial; + + /* Used to temporarily save the config info across hibernation */ + struct netvsc_device_info *saved_netvsc_dev_info; }; /* Per channel data */ diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index ca16ae8c8332..06185e3eacaa 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2423,6 +2423,61 @@ static int netvsc_remove(struct hv_device *dev) return 0; } +static int netvsc_suspend(struct hv_device *dev) +{ + struct net_device_context *ndev_ctx; + struct net_device *vf_netdev, *net; + struct netvsc_device *nvdev; + int ret; + + net = hv_get_drvdata(dev); + + ndev_ctx = netdev_priv(net); + cancel_delayed_work_sync(&ndev_ctx->dwork); + + rtnl_lock(); + + nvdev = rtnl_dereference(ndev_ctx->nvdev); + if (nvdev == NULL) { + ret = -ENODEV; + goto out; + } + + vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev); + if (vf_netdev) + netvsc_unregister_vf(vf_netdev); + + /* Save the current config info */ + ndev_ctx->saved_netvsc_dev_info = netvsc_devinfo_get(nvdev); + + ret = netvsc_detach(net, nvdev); +out: + rtnl_unlock(); + + return ret; +} + +static int netvsc_resume(struct hv_device *dev) +{ + struct net_device *net = hv_get_drvdata(dev); + struct net_device_context *net_device_ctx; + struct netvsc_device_info *device_info; + int ret; + + rtnl_lock(); + + net_device_ctx = netdev_priv(net); + device_info = net_device_ctx->saved_netvsc_dev_info; + + ret = netvsc_attach(net, device_info); + + rtnl_unlock(); + + kfree(device_info); + net_device_ctx->saved_netvsc_dev_info = NULL; + + return ret; +} static const struct hv_vmbus_device_id id_table[] = { /* Network guid */ { HV_NIC_GUID, }, @@ -2437,6 +2492,8 @@ static struct hv_driver netvsc_drv = { .id_table = id_table, .probe = netvsc_probe, .remove = netvsc_remove, + .suspend = netvsc_suspend, + .resume = netvsc_resume, .driver = { .probe_type = PROBE_FORCE_SYNCHRONOUS, }, From patchwork Tue Jun 2 02:08:02 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: 1302015 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 49bb7D3khFz9sTN; Tue, 2 Jun 2020 12:08:40 +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 1jfwM0-0005Hi-Ri; Tue, 02 Jun 2020 02:08:36 +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 1jfwLz-0005Gc-0z for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:35 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwLy-0001yV-Lp for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:34 +0000 Received: by mail-qt1-f197.google.com with SMTP id q21so12327769qtn.20 for ; Mon, 01 Jun 2020 19:08:34 -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=wC4pQrftnoUcv+bvpZOCuYamBLDdGmK7Y1trfjNRLFg=; b=hTFS7e9Iqw8hpXR8DtWVrwT3KDewREoLYhtijZaSfXENyOTwgEwuY9jjJNx8yaj8fQ Jzuxx5v2Z4KcJDWi036GO3vN8eiq2CBfiVt9+D/0nu1L4Z2Gmuz0IQcgo6ziSHz3P0x4 qHHse0T6fezJK4eRyPLjWhgsX6OjO0pt/L3x/QV4Z5qZuvWJSFJOXNNCXi5u4WLkp0SM G2wHYSnoucOISLANKiAuoE4nh9iel/HiyFBBghQvQnMuRNYRIcuhcVKKwDdZ954rDdM0 WD87hS7OBa/qZucfHxYUqk7WMv0eJxut91KFfX/rSj4RAQ5xM6ZApdQxAuf/EnqR40Pq J0Lg== X-Gm-Message-State: AOAM532ue+WrHvIpIYNgtAiHNCaKd2ilZUqKNKVSBZReyKSkFTnrmT5K 0wdsrwgXzk6qiAHRD8j64mmjqAxgq03B0kU6mIvcqfwDxCoWzMCRdDNg3f4v3Zs6go/YGnkB9A9 cWu59kq2pKk8g16EM6GMBamSFsmZyQW+Tsg0w4uIq X-Received: by 2002:a05:620a:219c:: with SMTP id g28mr23140830qka.227.1591063713231; Mon, 01 Jun 2020 19:08:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6VV0Ph6wsf7D7x6z/4UNLOrA35pyFnnL4c3skVqzjft9kvVoIsmNYClQ2meOzi3qgYRWDwg== X-Received: by 2002:a05:620a:219c:: with SMTP id g28mr23140817qka.227.1591063712799; Mon, 01 Jun 2020 19:08:32 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:32 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 06/21] x86/hyperv: Implement hv_is_hibernation_supported() Date: Mon, 1 Jun 2020 23:08:02 -0300 Message-Id: <20200602020817.236422-7-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 The API will be used by the hv_balloon and hv_vmbus drivers. Balloon up/down and hot-add of memory must not be active if the user wants the Linux VM to support hibernation, because they are incompatible with hibernation according to Hyper-V team, e.g. upon suspend the balloon VSP doesn't save any info about the ballooned-out pages (if any); so, after Linux resumes, Linux balloon VSC expects that the VSP will return the pages if Linux is under memory pressure, but the VSP will never do that, since the VSP thinks it never stole the pages from the VM. So, if the user wants Linux VM to support hibernation, Linux must forbid balloon up/down and hot-add, and the only functionality of the balloon VSC driver is reporting the VM's memory pressure to the host. Ideally, when Linux detects that the user wants it to support hibernation, the balloon VSC should tell the VSP that it does not support ballooning and hot-add. However, the current version of the VSP requires the VSC should support these capabilities, otherwise the capability negotiation fails and the VSC can not load at all, so with the later changes to the VSC driver, Linux VM still reports to the VSP that the VSC supports these capabilities, but the VSC ignores the VSP's requests of balloon up/down and hot add, and reports an error to the VSP, when applicable. BTW, in the future the balloon VSP driver will allow the VSC to not support the capabilities of balloon up/down and hot add. The ACPI S4 state is not a must for hibernation to work, because Linux is able to hibernate as long as the system can shut down. However in practice we decide to artificially use the presence of the virtual ACPI S4 state as an indicator of the user's intent of using hibernation, because Linux VM must find a way to know if the user wants to use the hibernation feature or not. By default, Hyper-V does not enable the virtual ACPI S4 state; on recent Hyper-V hosts (e.g. RS5, 19H1), the administrator is able to enable the state for a VM by WMI commands. Once all the vmbus and VSC patches for the hibernation feature are accepted, an extra patch will be submitted to forbid hibernation if the virtual ACPI S4 state is absent, i.e. hv_is_hibernation_supported() is false. Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Acked-by: Thomas Gleixner Signed-off-by: Sasha Levin (cherry picked from commit b96f86534fa3102fd07246cf8b6cb5cc96788597) Signed-off-by: Marcelo Henrique Cerri --- arch/x86/hyperv/hv_init.c | 7 +++++++ include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 60458769931b..b4c49cabb436 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -7,6 +7,7 @@ * Author : K. Y. Srinivasan */ +#include #include #include #include @@ -449,3 +450,9 @@ bool hv_is_hyperv_initialized(void) return hypercall_msr.enable; } EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized); + +bool hv_is_hibernation_supported(void) +{ + return acpi_sleep_state_supported(ACPI_STATE_S4); +} +EXPORT_SYMBOL_GPL(hv_is_hibernation_supported); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 53759d2b9c26..1c4fd950f091 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -166,10 +166,12 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die); void hyperv_report_panic_msg(phys_addr_t pa, size_t size); bool hv_is_hyperv_initialized(void); +bool hv_is_hibernation_supported(void); void hyperv_cleanup(void); void hv_setup_sched_clock(void *sched_clock); #else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized(void) { return false; } +static inline bool hv_is_hibernation_supported(void) { return false; } static inline void hyperv_cleanup(void) {} #endif /* CONFIG_HYPERV */ From patchwork Tue Jun 2 02:08:03 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: 1302016 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 49bb7H1rfGz9sSn; Tue, 2 Jun 2020 12:08:43 +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 1jfwM3-0005Jc-9m; Tue, 02 Jun 2020 02:08:39 +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 1jfwM0-0005Ha-OG for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:36 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM0-0001yZ-Aw for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:36 +0000 Received: by mail-qt1-f197.google.com with SMTP id h49so10089220qtk.10 for ; Mon, 01 Jun 2020 19:08:36 -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=mPP0+GEC7TyE8NH5W8GqE3o9YrbLM0l5xaPBNXVzPPk=; b=rg3vPZLa7w0AbjgASJRBiE+l437dSq1ClP/vB6/xDIBsnX8orEjiIgqY5Bt4y7RfA/ VXuLLEI4TP0b/s/51r7KCQ8mmifYiRMx2yRf7JMvweLn4LXHLJ+vpx7REGqS0LejLf8V QCcj6yy3MovoF+HakNOPuJ+sDdzVrCFFObPgd0WPSbgvCA0K2ZQ9OBUDgBuxGTmEBTh0 J0NBSGVjSvdyBAty/MKDcAvE7x8V1B963qaKnouRk5sylPSvop0vqxHqNm90hKHqJSr4 N6u5lVrydMfL5hcKMh4G45UHdqikj/94GeHLIt8AB+z2cdV0bj6yoRd0jM0LTnPmWiaD to8g== X-Gm-Message-State: AOAM532qZSfLoisuOhdiyo8NEUANG6DIvTeJKfr6/KjsCU0T2kysajA3 WBEZzzcsoYirwLPrWZcbwJ757xEKHffFHwafFxMkI162dB8lnJNuxUMqtJJRdPk12YDb6S+qZ8u +cxp8Q2uQzRRGXZsJBx/TICzhGqfDYP4wkewokbZ4 X-Received: by 2002:ad4:5222:: with SMTP id r2mr24024434qvq.82.1591063714921; Mon, 01 Jun 2020 19:08:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwC2y96p38TC9g1Q4IktRU4Qloi1SyQtiLiSs4ThgVqVODgo+4PvQwdvy4X7j6rj0+EJgK5g== X-Received: by 2002:ad4:5222:: with SMTP id r2mr24024424qvq.82.1591063714587; Mon, 01 Jun 2020 19:08:34 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:33 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 07/21] hv_balloon: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:03 -0300 Message-Id: <20200602020817.236422-8-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 When hibernation is enabled, we must ignore the balloon up/down and hot-add requests from the host, if any. Signed-off-by: Dexuan Cui Acked-by: David Hildenbrand Signed-off-by: Sasha Levin (cherry picked from commit 25bd2b2f1f05347a4cd633138d0e4c2fd5788359) Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/hv_balloon.c | 87 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 930674117533..e75419391fa8 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -24,6 +24,8 @@ #include +#include + #define CREATE_TRACE_POINTS #include "hv_trace_balloon.h" @@ -457,6 +459,7 @@ struct hot_add_wrk { struct work_struct wrk; }; +static bool allow_hibernation; static bool hot_add = true; static bool do_hot_add; /* @@ -1053,8 +1056,12 @@ static void hot_add_req(struct work_struct *dummy) else resp.result = 0; - if (!do_hot_add || (resp.page_count == 0)) - pr_err("Memory hot add failed\n"); + if (!do_hot_add || resp.page_count == 0) { + if (!allow_hibernation) + pr_err("Memory hot add failed\n"); + else + pr_info("Ignore hot-add request!\n"); + } dm->state = DM_INITIALIZED; resp.hdr.trans_id = atomic_inc_return(&trans_id); @@ -1502,6 +1509,11 @@ static void balloon_onchannelcallback(void *context) break; case DM_BALLOON_REQUEST: + if (allow_hibernation) { + pr_info("Ignore balloon-up request!\n"); + break; + } + if (dm->state == DM_BALLOON_UP) pr_warn("Currently ballooning\n"); bal_msg = (struct dm_balloon *)recv_buffer; @@ -1511,6 +1523,11 @@ static void balloon_onchannelcallback(void *context) break; case DM_UNBALLOON_REQUEST: + if (allow_hibernation) { + pr_info("Ignore balloon-down request!\n"); + break; + } + dm->state = DM_BALLOON_DOWN; balloon_down(dm, (struct dm_unballoon_request *)recv_buffer); @@ -1616,6 +1633,11 @@ static int balloon_connect_vsp(struct hv_device *dev) cap_msg.hdr.size = sizeof(struct dm_capabilities); cap_msg.hdr.trans_id = atomic_inc_return(&trans_id); + /* + * When hibernation (i.e. virtual ACPI S4 state) is enabled, the host + * currently still requires the bits to be set, so we have to add code + * to fail the host's hot-add and balloon up/down requests, if any. + */ cap_msg.caps.cap_bits.balloon = 1; cap_msg.caps.cap_bits.hot_add = 1; @@ -1665,6 +1687,10 @@ static int balloon_probe(struct hv_device *dev, { int ret; + allow_hibernation = hv_is_hibernation_supported(); + if (allow_hibernation) + hot_add = false; + #ifdef CONFIG_MEMORY_HOTPLUG do_hot_add = hot_add; #else @@ -1704,6 +1730,8 @@ static int balloon_probe(struct hv_device *dev, return 0; probe_error: + dm_device.state = DM_INIT_ERROR; + dm_device.thread = NULL; vmbus_close(dev->channel); #ifdef CONFIG_MEMORY_HOTPLUG unregister_memory_notifier(&hv_memory_nb); @@ -1745,6 +1773,59 @@ static int balloon_remove(struct hv_device *dev) return 0; } +static int balloon_suspend(struct hv_device *hv_dev) +{ + struct hv_dynmem_device *dm = hv_get_drvdata(hv_dev); + + tasklet_disable(&hv_dev->channel->callback_event); + + cancel_work_sync(&dm->balloon_wrk.wrk); + cancel_work_sync(&dm->ha_wrk.wrk); + + if (dm->thread) { + kthread_stop(dm->thread); + dm->thread = NULL; + vmbus_close(hv_dev->channel); + } + + tasklet_enable(&hv_dev->channel->callback_event); + + return 0; + +} + +static int balloon_resume(struct hv_device *dev) +{ + int ret; + + dm_device.state = DM_INITIALIZING; + + ret = balloon_connect_vsp(dev); + + if (ret != 0) + goto out; + + dm_device.thread = + kthread_run(dm_thread_func, &dm_device, "hv_balloon"); + if (IS_ERR(dm_device.thread)) { + ret = PTR_ERR(dm_device.thread); + dm_device.thread = NULL; + goto close_channel; + } + + dm_device.state = DM_INITIALIZED; + return 0; +close_channel: + vmbus_close(dev->channel); +out: + dm_device.state = DM_INIT_ERROR; +#ifdef CONFIG_MEMORY_HOTPLUG + unregister_memory_notifier(&hv_memory_nb); + restore_online_page_callback(&hv_online_page); +#endif + return ret; +} + static const struct hv_vmbus_device_id id_table[] = { /* Dynamic Memory Class ID */ /* 525074DC-8985-46e2-8057-A307DC18A502 */ @@ -1759,6 +1840,8 @@ static struct hv_driver balloon_drv = { .id_table = id_table, .probe = balloon_probe, .remove = balloon_remove, + .suspend = balloon_suspend, + .resume = balloon_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, 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, }, From patchwork Tue Jun 2 02:08:05 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: 1302018 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 49bb7S0XQtz9sSf; Tue, 2 Jun 2020 12:08:52 +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 1jfwM9-0005Oz-IE; Tue, 02 Jun 2020 02:08:45 +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 1jfwM6-0005LT-1t for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:42 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM4-0001yh-92 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:40 +0000 Received: by mail-qt1-f197.google.com with SMTP id p31so12346418qte.1 for ; Mon, 01 Jun 2020 19:08:40 -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=ZmPcJtX4qf/CHtc42BKnd/g3uyCKozUnOZWdmn4A48k=; b=o0rvJ66tL3yz5JpmCBh51NNMtynNBKlt8eecA12YhBsVbV4i+BIjmOMlhgpb+JZLMd t6Hu+Y9VcFYCF45c2L0UrbIxUYVsM1RPcOiOskueVYYL6Z3l9otqlJGMGCcKrhZBe/WF SV97BvL0kemv3SesoptoO5snbAal9CC8tERU+buc77J1DnGlnJnGE1gmxZTtjdWDlNsw 1ZaCrWVoa7FDI/eJ38F0QtWO+oKmXBaFHJoTF9pseA42aK8HJBcFPilidHaGxR5Quu/L 4p0LtMkDerRRYakjfbmoRSZ+L7JJZZlcnRa8Rh3tg3CIO0DqTO79pfkDyjKA9acVgbqA fDTg== X-Gm-Message-State: AOAM5330HFdEf+1A7W/oIrh9amnvyR2YA+77IOBgq0LFunNF7Ulbo3tI 3NQ6FSOy26tJ4RJCcnmc8erNWl1LQnp2wPVJ+gLW/JTB4nZlmh3qhW6PLEhR+XQkBBZEn7DaySg Kc2jbLqe+gAQP+Rx0d11R49SOyJQbw1Ho4l79Ns5v X-Received: by 2002:a05:620a:126c:: with SMTP id b12mr11481675qkl.7.1591063718909; Mon, 01 Jun 2020 19:08:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9kMAIePBz7utGW9VHs50ljO2t8HBM3EiA91mCUAGJ4QbFm1Qh4XLhcg+ekk9oPXiD8BsnFQ== X-Received: by 2002:a05:620a:126c:: with SMTP id b12mr11481660qkl.7.1591063718564; Mon, 01 Jun 2020 19:08:38 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:37 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 09/21] PCI: hv: Reorganize the code in preparation of hibernation Date: Mon, 1 Jun 2020 23:08:05 -0300 Message-Id: <20200602020817.236422-10-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 There is no functional change. This is just preparatory for a later patch which adds the hibernation support for the pci-hyperv driver. Signed-off-by: Dexuan Cui Signed-off-by: Lorenzo Pieralisi Reviewed-by: Michael Kelley (cherry picked from commit a8e37506e79a7a08d0ee217f389fa1710e7a2ea4) Signed-off-by: Marcelo Henrique Cerri --- drivers/pci/controller/pci-hyperv.c | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 9c50fe7d5d3d..70d0dc30373f 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2392,7 +2392,9 @@ static void hv_pci_onchannelcallback(void *context) * failing if the host doesn't support the necessary protocol * level. */ -static int hv_pci_protocol_negotiation(struct hv_device *hdev) +static int hv_pci_protocol_negotiation(struct hv_device *hdev, + enum pci_protocol_version_t version[], + int num_version) { struct pci_version_request *version_req; struct hv_pci_compl comp_pkt; @@ -2416,8 +2418,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) version_req = (struct pci_version_request *)&pkt->message; version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION; - for (i = 0; i < ARRAY_SIZE(pci_protocol_versions); i++) { - version_req->protocol_version = pci_protocol_versions[i]; + for (i = 0; i < num_version; i++) { + version_req->protocol_version = version[i]; ret = vmbus_sendpacket(hdev->channel, version_req, sizeof(struct pci_version_request), (unsigned long)pkt, VM_PKT_DATA_INBAND, @@ -2433,7 +2435,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) } if (comp_pkt.completion_status >= 0) { - pci_protocol_version = pci_protocol_versions[i]; + pci_protocol_version = version[i]; dev_info(&hdev->device, "PCI VMBus probing: Using version %#x\n", pci_protocol_version); @@ -2943,7 +2945,8 @@ static int hv_pci_probe(struct hv_device *hdev, hv_set_drvdata(hdev, hbus); - ret = hv_pci_protocol_negotiation(hdev); + ret = hv_pci_protocol_negotiation(hdev, pci_protocol_versions, + ARRAY_SIZE(pci_protocol_versions)); if (ret) goto close; @@ -3024,7 +3027,7 @@ static int hv_pci_probe(struct hv_device *hdev, return ret; } -static void hv_pci_bus_exit(struct hv_device *hdev) +static int hv_pci_bus_exit(struct hv_device *hdev, bool hibernating) { struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); struct { @@ -3040,16 +3043,20 @@ static void hv_pci_bus_exit(struct hv_device *hdev) * access the per-channel ringbuffer any longer. */ if (hdev->channel->rescind) - return; + return 0; - /* Delete any children which might still exist. */ - memset(&relations, 0, sizeof(relations)); - hv_pci_devices_present(hbus, &relations); + if (!hibernating) { + /* Delete any children which might still exist. */ + memset(&relations, 0, sizeof(relations)); + hv_pci_devices_present(hbus, &relations); + } ret = hv_send_resources_released(hdev); - if (ret) + if (ret) { dev_err(&hdev->device, "Couldn't send resources released packet(s)\n"); + return ret; + } memset(&pkt.teardown_packet, 0, sizeof(pkt.teardown_packet)); init_completion(&comp_pkt.host_event); @@ -3062,8 +3069,13 @@ static void hv_pci_bus_exit(struct hv_device *hdev) (unsigned long)&pkt.teardown_packet, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (!ret) - wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ); + if (ret) + return ret; + + if (wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ) == 0) + return -ETIMEDOUT; + + return 0; } /** @@ -3075,6 +3087,7 @@ static void hv_pci_bus_exit(struct hv_device *hdev) static int hv_pci_remove(struct hv_device *hdev) { struct hv_pcibus_device *hbus; + int ret; hbus = hv_get_drvdata(hdev); if (hbus->state == hv_pcibus_installed) { @@ -3087,7 +3100,7 @@ static int hv_pci_remove(struct hv_device *hdev) hbus->state = hv_pcibus_removed; } - hv_pci_bus_exit(hdev); + ret = hv_pci_bus_exit(hdev, false); vmbus_close(hdev->channel); @@ -3104,7 +3117,7 @@ static int hv_pci_remove(struct hv_device *hdev) hv_put_dom_num(hbus->sysdata.domain); free_page((unsigned long)hbus); - return 0; + return ret; } static const struct hv_vmbus_device_id hv_pci_id_table[] = { From patchwork Tue Jun 2 02:08:06 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: 1302019 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 49bb7T3fwtz9sSy; Tue, 2 Jun 2020 12:08:53 +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 1jfwMB-0005R3-Gb; Tue, 02 Jun 2020 02:08:47 +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 1jfwM6-0005N7-UB for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:42 +0000 Received: from mail-qk1-f200.google.com ([209.85.222.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM6-0001ys-7y for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:42 +0000 Received: by mail-qk1-f200.google.com with SMTP id t18so2463270qke.8 for ; Mon, 01 Jun 2020 19:08:42 -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=zKpQ7+KLiPaBUOL/ITkf8YB+t2asCsAfrTAEN1tj1Hw=; b=bFfPsbYJjLhrQEQWuKL3GgjGwZ0JN+41T9cQF2KObmamSTP/ZIC94g5CkGn2sR3CNj GWRG7LQFeEt0WOpjm+MuSgN7ltC69Ym1jS+kQIxb+x+TI/IgnWXOm6bOum9hmXNjDbbE 2CrRyv62agxOaYt03TeUOvWHr4Nu2yIi3BQ6bqQycBRyoPjrGws+xqIVKzMNvAyDZRwa GzLI68JeXVsYxG/gkNG340FVOlU20nJ16w6xgoIjVz3GX4kaNMdR5H+wwKFxEp/pEt2o VYg4gK3ML4oDmwPUMjZV5SA6m7V2DGXA9AL9rJGVVKtMgQI8WoCY+SCSfaXrSlfST8mR Fkew== X-Gm-Message-State: AOAM532ce12W8eify0n9UnePoA6q69ej9dc68sQUWp3g+NZjl1oKhiLp dxaVuyXSy+C/oEZriGDlwG68g70FzF5ixBzIJnS8/y3QxUTUHe8a/+d861HitV55fISQdpHCi7/ +KhsucT0TwoAqANM0I6WNobCOpr1sj6Oj7g4aq415 X-Received: by 2002:a05:6214:a72:: with SMTP id ef18mr3584236qvb.239.1591063720790; Mon, 01 Jun 2020 19:08:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKy6YVmvNz3y8sNvNPRvJODq1fwG0vuk+LlazHllExuUhBQU0F3W5DuywWfx2KocLDYng+4A== X-Received: by 2002:a05:6214:a72:: with SMTP id ef18mr3584220qvb.239.1591063720304; Mon, 01 Jun 2020 19:08:40 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:39 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 10/21] PCI: hv: Add hibernation support Date: Mon, 1 Jun 2020 23:08:06 -0300 Message-Id: <20200602020817.236422-11-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 Add suspend() and resume() functions so that Hyper-V virtual PCI devices are handled properly when the VM hibernates and resumes from hibernation. Note that the suspend() function must make sure there are no pending work items before calling vmbus_close(), since it runs in a process context as a callback in dpm_suspend(). When it starts to run, the channel callback hv_pci_onchannelcallback(), which runs in a tasklet context, can be still running concurrently and scheduling new work items onto hbus->wq in hv_pci_devices_present() and hv_pci_eject_device(), and the work item handlers can access the vmbus channel, which can be being closed by hv_pci_suspend(), e.g. the work item handler pci_devices_present_work() -> new_pcichild_device() writes to the vmbus channel. To eliminate the race, hv_pci_suspend() disables the channel callback tasklet, sets hbus->state to hv_pcibus_removing, and re-enables the tasklet. This way, when hv_pci_suspend() proceeds, it knows that no new work item can be scheduled, and then it flushes hbus->wq and safely closes the vmbus channel. Signed-off-by: Dexuan Cui Signed-off-by: Lorenzo Pieralisi Reviewed-by: Michael Kelley (cherry picked from commit ac82fc83270884adea31d9dec22db09392058bf7) Signed-off-by: Marcelo Henrique Cerri --- drivers/pci/controller/pci-hyperv.c | 125 +++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 70d0dc30373f..b759934eca95 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -455,6 +455,7 @@ enum hv_pcibus_state { hv_pcibus_init = 0, hv_pcibus_probed, hv_pcibus_installed, + hv_pcibus_removing, hv_pcibus_removed, hv_pcibus_maximum }; @@ -1681,6 +1682,23 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) spin_lock_irqsave(&hbus->device_list_lock, flags); + /* + * Clear the memory enable bit, in case it's already set. This occurs + * in the suspend path of hibernation, where the device is suspended, + * resumed and suspended again: see hibernation_snapshot() and + * hibernation_platform_enter(). + * + * If the memory enable bit is already set, Hyper-V sliently ignores + * the below BAR updates, and the related PCI device driver can not + * work, because reading from the device register(s) always returns + * 0xFFFFFFFF. + */ + list_for_each_entry(hpdev, &hbus->children, list_entry) { + _hv_pcifront_read_config(hpdev, PCI_COMMAND, 2, &command); + command &= ~PCI_COMMAND_MEMORY; + _hv_pcifront_write_config(hpdev, PCI_COMMAND, 2, command); + } + /* Pick addresses for the BARs. */ do { list_for_each_entry(hpdev, &hbus->children, list_entry) { @@ -2120,6 +2138,12 @@ static void hv_pci_devices_present(struct hv_pcibus_device *hbus, unsigned long flags; bool pending_dr; + if (hbus->state == hv_pcibus_removing) { + dev_info(&hbus->hdev->device, + "PCI VMBus BUS_RELATIONS: ignored\n"); + return; + } + dr_wrk = kzalloc(sizeof(*dr_wrk), GFP_NOWAIT); if (!dr_wrk) return; @@ -2236,11 +2260,19 @@ static void hv_eject_device_work(struct work_struct *work) */ static void hv_pci_eject_device(struct hv_pci_dev *hpdev) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct hv_device *hdev = hbus->hdev; + + if (hbus->state == hv_pcibus_removing) { + dev_info(&hdev->device, "PCI VMBus EJECT: ignored\n"); + return; + } + hpdev->state = hv_pcichild_ejecting; get_pcichild(hpdev); INIT_WORK(&hpdev->wrk, hv_eject_device_work); - get_hvpcibus(hpdev->hbus); - queue_work(hpdev->hbus->wq, &hpdev->wrk); + get_hvpcibus(hbus); + queue_work(hbus->wq, &hpdev->wrk); } /** @@ -3120,6 +3152,93 @@ static int hv_pci_remove(struct hv_device *hdev) return ret; } +static int hv_pci_suspend(struct hv_device *hdev) +{ + struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); + enum hv_pcibus_state old_state; + int ret; + + /* + * hv_pci_suspend() must make sure there are no pending work items + * before calling vmbus_close(), since it runs in a process context + * as a callback in dpm_suspend(). When it starts to run, the channel + * callback hv_pci_onchannelcallback(), which runs in a tasklet + * context, can be still running concurrently and scheduling new work + * items onto hbus->wq in hv_pci_devices_present() and + * hv_pci_eject_device(), and the work item handlers can access the + * vmbus channel, which can be being closed by hv_pci_suspend(), e.g. + * the work item handler pci_devices_present_work() -> + * new_pcichild_device() writes to the vmbus channel. + * + * To eliminate the race, hv_pci_suspend() disables the channel + * callback tasklet, sets hbus->state to hv_pcibus_removing, and + * re-enables the tasklet. This way, when hv_pci_suspend() proceeds, + * it knows that no new work item can be scheduled, and then it flushes + * hbus->wq and safely closes the vmbus channel. + */ + tasklet_disable(&hdev->channel->callback_event); + + /* Change the hbus state to prevent new work items. */ + old_state = hbus->state; + if (hbus->state == hv_pcibus_installed) + hbus->state = hv_pcibus_removing; + + tasklet_enable(&hdev->channel->callback_event); + + if (old_state != hv_pcibus_installed) + return -EINVAL; + + flush_workqueue(hbus->wq); + + ret = hv_pci_bus_exit(hdev, true); + if (ret) + return ret; + + vmbus_close(hdev->channel); + + return 0; +} + +static int hv_pci_resume(struct hv_device *hdev) +{ + struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); + enum pci_protocol_version_t version[1]; + int ret; + + hbus->state = hv_pcibus_init; + + ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, + hv_pci_onchannelcallback, hbus); + if (ret) + return ret; + + /* Only use the version that was in use before hibernation. */ + version[0] = pci_protocol_version; + ret = hv_pci_protocol_negotiation(hdev, version, 1); + if (ret) + goto out; + + ret = hv_pci_query_relations(hdev); + if (ret) + goto out; + + ret = hv_pci_enter_d0(hdev); + if (ret) + goto out; + + ret = hv_send_resources_allocated(hdev); + if (ret) + goto out; + + prepopulate_bars(hbus); + + hbus->state = hv_pcibus_installed; + return 0; +out: + vmbus_close(hdev->channel); + return ret; +} + static const struct hv_vmbus_device_id hv_pci_id_table[] = { /* PCI Pass-through Class ID */ /* 44C4F61D-4444-4400-9D52-802E27EDE19F */ @@ -3134,6 +3253,8 @@ static struct hv_driver hv_pci_drv = { .id_table = hv_pci_id_table, .probe = hv_pci_probe, .remove = hv_pci_remove, + .suspend = hv_pci_suspend, + .resume = hv_pci_resume, }; static void __exit exit_hv_pci_drv(void) From patchwork Tue Jun 2 02:08:07 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: 1302020 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 49bb7Z4dFsz9sSf; Tue, 2 Jun 2020 12:08:58 +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 1jfwMF-0005UL-7C; Tue, 02 Jun 2020 02:08:51 +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 1jfwM9-0005OY-Q1 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:45 +0000 Received: from mail-qv1-f69.google.com ([209.85.219.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwM7-0001yy-Sr for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:44 +0000 Received: by mail-qv1-f69.google.com with SMTP id f18so2027792qvr.22 for ; Mon, 01 Jun 2020 19:08:43 -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=9JCY0FyEjTsnr0pyyWOyihz0k5t3g2IBhYrdQTObP5E=; b=QZRE2gVQdhD/+X5FfCZVmwff2vWJ+oVN4/pjPiiZpPB989zGv5Qw+QoQOrmI/fZlYb EWibq3TkCv8jDt0Fih4eU/OWo2RADm07X8kzUwi3a17OiQfJYHWqVXEfXM0ottdRaYjG I7/Ba6Ni1Lcb5nTycQdBKW96CplA+0PQwezNBrrkCzqfEPrVYLE43Qk6Ple0hsAPfoQF FUBZ1JGFb34kAyDTyfWRdwFLFmu8A0N892x7fUDLpvDGnHaXCmqc+ReenaIER0ngV/pE pJ6/txRO5Mu1Y75iMoGHaDocU9GlR7jdUx7kKWZ1C2cjM5GGIuhVF6LDUjVQ1RhtG8Ke v5cw== X-Gm-Message-State: AOAM531LaiNNIaM7ydzI6ySrLmdSGXgENu9rqNPtFcp8Ch1AhlSyfn52 kXsyKM+3cUTXWUE5mPKDpzgpjpoJqVhTMO5PwAAKTfkM+q1wjhqekgJjpH48rC/rdVFCXG2SQxl pMeFsHzCsMI0VU0ijMnU+XFoMX8rzxKGac9freTwb X-Received: by 2002:a37:6115:: with SMTP id v21mr21698330qkb.420.1591063722548; Mon, 01 Jun 2020 19:08:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE/pQBk5unQQjRq3AxM2T69WAxocMMnDGZCloDLLn8Ein0KyMHy+jOOiVZuOk7suQUsVfFxQ== X-Received: by 2002:a37:6115:: with SMTP id v21mr21698315qkb.420.1591063722184; Mon, 01 Jun 2020 19:08:42 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:41 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 11/21] clocksource/drivers/hyper-v: Suspend/resume Hyper-V clocksource for hibernation Date: Mon, 1 Jun 2020 23:08:07 -0300 Message-Id: <20200602020817.236422-12-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 This is needed for hibernation, e.g. when we resume the old kernel, we need to disable the "current" kernel's TSC page and then resume the old kernel's. Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/1574233946-48377-1-git-send-email-decui@microsoft.com (cherry picked from commit 1349401ff1aa425e7381ed26feb63e0d6b557fc6) Signed-off-by: Marcelo Henrique Cerri --- drivers/clocksource/hyperv_timer.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 0d29b05d8889..3325ec9bc67e 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -331,12 +331,37 @@ static u64 read_hv_sched_clock_tsc(void) (NSEC_PER_SEC / HV_CLOCK_HZ); } +static void suspend_hv_clock_tsc(struct clocksource *arg) +{ + u64 tsc_msr; + + /* Disable the TSC page */ + hv_get_reference_tsc(tsc_msr); + tsc_msr &= ~BIT_ULL(0); + hv_set_reference_tsc(tsc_msr); +} + + +static void resume_hv_clock_tsc(struct clocksource *arg) +{ + phys_addr_t phys_addr = virt_to_phys(&tsc_pg); + u64 tsc_msr; + + /* Re-enable the TSC page */ + hv_get_reference_tsc(tsc_msr); + tsc_msr &= GENMASK_ULL(11, 0); + tsc_msr |= BIT_ULL(0) | (u64)phys_addr; + hv_set_reference_tsc(tsc_msr); +} + static struct clocksource hyperv_cs_tsc = { .name = "hyperv_clocksource_tsc_page", .rating = 400, .read = read_hv_clock_tsc, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, + .suspend= suspend_hv_clock_tsc, + .resume = resume_hv_clock_tsc, }; static u64 notrace read_hv_clock_msr(struct clocksource *arg) From patchwork Tue Jun 2 02:08:08 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: 1302021 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 49bb7d2htzz9sSW; Tue, 2 Jun 2020 12:09:01 +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 1jfwMI-0005Ws-91; Tue, 02 Jun 2020 02:08:54 +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 1jfwMB-0005QW-JR for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:47 +0000 Received: from mail-qv1-f70.google.com ([209.85.219.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMA-0001z9-3H for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:46 +0000 Received: by mail-qv1-f70.google.com with SMTP id t11so2076336qvv.11 for ; Mon, 01 Jun 2020 19:08:46 -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=rx58XKayY8ULsTbvVQBsCUn2nPEK/mfrBHo/Yk/dWg0=; b=jxcGVTvWax7hM16buKrREU3WcPGN8JRd5exUksTpiNyXzBo9K8/ppF2xtKvIjMZYLI jul7N9lppAcntsaIb+wi3WPAfp5k8ox5htzz6i3HQacGsrAcf5qxeBSIDeAU1IvBQ79w U5bPLBPa0uPNso6Q+pvFI5myFJngdMnlYRPjU7nQnjyyZiGotxdiH/VsLGAOAxeqGbu/ YQeivxI0Hvk1wLagfR/MUfxvaDDMp4zZ2irE3N9eHLshuoePo+GGpzMxSuPnJjlGRsYV o6TsE1RLLRSJPD1WvYdTckByq40HF/90+/kUskxWPvrK92rhLi5nuOoI3pXsI3crVZGF O+sg== X-Gm-Message-State: AOAM532whC6KQ3HM8viAhCLHAuLt9SLO9qlbsegYw1sL06Ctwg+W6jNe pVwmi5xdRil1xEO7WE2zKYrxiPw3Y+KLuUkBhnlz3n2f82c7vTvhT84+pQhJhScTHFvWEOO39jc HGhhxPkBsjDONLcnnYR/tAaZKCmYL7/GrbRTummnF X-Received: by 2002:a37:2e86:: with SMTP id u128mr20387692qkh.26.1591063724724; Mon, 01 Jun 2020 19:08:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWjHnYSjXuMvg0f4upqoR3rCPnUweDUZUibo+9c+Gxju7d6vsI9VDlwv0ubM2Uof+daNpEjA== X-Received: by 2002:a37:2e86:: with SMTP id u128mr20387673qkh.26.1591063724384; Mon, 01 Jun 2020 19:08:44 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:43 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 12/21] Input: hyperv-keyboard: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:08 -0300 Message-Id: <20200602020817.236422-13-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 Add suspend() and resume() functions so the Hyper-V virtual keyboard can participate in VM hibernation. Note that the keyboard is a "wakeup" device that could abort an in-progress hibernation if there is keyboard event. No attempt is made to suppress this behavior. If desired, a sysadmin can disable the keyboard as a wakeup device using standard mechanisms such as: echo disabled > /sys/bus/vmbus/drivers/hyperv_keyboard/XXX/power/wakeup (where XXX is the device's GUID) Reviewed-by: Michael Kelley Signed-off-by: Dexuan Cui Signed-off-by: Sasha Levin (cherry picked from commit e2379b30324ca5ba808f16cb3d2504349264912f) Signed-off-by: Marcelo Henrique Cerri --- drivers/input/serio/hyperv-keyboard.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c index e486a8a74c40..df4e9f6f4529 100644 --- a/drivers/input/serio/hyperv-keyboard.c +++ b/drivers/input/serio/hyperv-keyboard.c @@ -259,6 +259,8 @@ static int hv_kbd_connect_to_vsp(struct hv_device *hv_dev) u32 proto_status; int error; + reinit_completion(&kbd_dev->wait_event); + request = &kbd_dev->protocol_req; memset(request, 0, sizeof(struct synth_kbd_protocol_request)); request->header.type = __cpu_to_le32(SYNTH_KBD_PROTOCOL_REQUEST); @@ -380,6 +382,29 @@ static int hv_kbd_remove(struct hv_device *hv_dev) return 0; } +static int hv_kbd_suspend(struct hv_device *hv_dev) +{ + vmbus_close(hv_dev->channel); + + return 0; +} + +static int hv_kbd_resume(struct hv_device *hv_dev) +{ + int ret; + + ret = vmbus_open(hv_dev->channel, + KBD_VSC_SEND_RING_BUFFER_SIZE, + KBD_VSC_RECV_RING_BUFFER_SIZE, + NULL, 0, + hv_kbd_on_channel_callback, + hv_dev); + if (ret == 0) + ret = hv_kbd_connect_to_vsp(hv_dev); + + return ret; +} + static const struct hv_vmbus_device_id id_table[] = { /* Keyboard guid */ { HV_KBD_GUID, }, @@ -393,6 +418,8 @@ static struct hv_driver hv_kbd_drv = { .id_table = id_table, .probe = hv_kbd_probe, .remove = hv_kbd_remove, + .suspend = hv_kbd_suspend, + .resume = hv_kbd_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, From patchwork Tue Jun 2 02:08:09 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: 1302022 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 49bb7l1Vynz9sSW; Tue, 2 Jun 2020 12:09:07 +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 1jfwMP-0005cN-2R; Tue, 02 Jun 2020 02:09:01 +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 1jfwMD-0005S8-0D for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:49 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMC-0001zN-5G for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:48 +0000 Received: by mail-qt1-f197.google.com with SMTP id o11so12286456qti.23 for ; Mon, 01 Jun 2020 19:08:48 -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=Iw8msjtJJlr9m69v+6Ps/DkP0NWXTs/+/365NpALang=; b=qXuSLldXUuBlTXU1Y1krGx3ZDHtxNsfVh0jWyIbDIXWvK+IKa2iG/Oekc9Om5JqKiM Gtc7m4aoCLPX18uSbRiLHDdzkfOtM1VI53/ayRZFPidg+F7n7ogG6EsJhoeTHjSRwB+E VkhyZqwDqZm/oFVU1VB9K190LC8Clku/KGn6InlOm5nzwHIrURsUc+jWuBVa7UgH5rMS 0+jqFAcZOOyKHya8IlANiQ+GdhvtWWQp6z3D7WFQ9gO5uRE44MSwYJ1ahM5A03flvA2J 9oSOp7TWbf5ARBq3697aLfHWCDkvoxRZPx5SnmRO8hrDV1gRydaLMO2zDGIkNoAcE/LF XEpg== X-Gm-Message-State: AOAM533Ao4Vt3Xk0cHgk3RbLqPYN3Su025VDhlS1K1LJG5huPrvCcd04 NhZhYbgGmkmT9zfwbn9EBgKWvcOv/ADJREQZqDvWzP78e1AJW1pOnYFnrrY7RczSiUaYJlFfAbz KYlAVEbGshHLZTZzzvEr0bEfTv4xQKhJBufOROb37 X-Received: by 2002:a05:620a:1456:: with SMTP id i22mr15215072qkl.423.1591063726792; Mon, 01 Jun 2020 19:08:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM0tjIo1ZtK2ooOvDkDSgs0ZY/B8BUT44rn6jyJeM+3Jd+QCDf6qN2Wh21QobHXH3gvQUSJQ== X-Received: by 2002:a05:620a:1456:: with SMTP id i22mr15215064qkl.423.1591063726464; Mon, 01 Jun 2020 19:08:46 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:45 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 13/21] video: hyperv_fb: Fix hibernation for the deferred IO feature Date: Mon, 1 Jun 2020 23:08:09 -0300 Message-Id: <20200602020817.236422-14-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 fb_deferred_io_work() can access the vmbus ringbuffer by calling fbdefio->deferred_io() -> synthvid_deferred_io() -> synthvid_update(). Because the vmbus ringbuffer is inaccessible between hvfb_suspend() and hvfb_resume(), we must cancel info->deferred_work before calling vmbus_close() and then reschedule it after we reopen the channel in hvfb_resume(). Fixes: a4ddb11d297e ("video: hyperv: hyperv_fb: Support deferred IO for Hyper-V frame buffer driver") Fixes: 824946a8b6fb ("video: hyperv_fb: Add the support of hibernation") Signed-off-by: Dexuan Cui Reviewed-by: Wei Hu Acked-by: Bartlomiej Zolnierkiewicz Signed-off-by: Sasha Levin (cherry picked from commit 382a46221757250966621f046e91d8c05adac12b) Signed-off-by: Marcelo Henrique Cerri --- drivers/video/fbdev/hyperv_fb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c index fe4731f97df7..5017b4b20781 100644 --- a/drivers/video/fbdev/hyperv_fb.c +++ b/drivers/video/fbdev/hyperv_fb.c @@ -891,6 +891,7 @@ static int hvfb_suspend(struct hv_device *hdev) fb_set_suspend(info, 1); cancel_delayed_work_sync(&par->dwork); + cancel_delayed_work_sync(&info->deferred_work); par->update_saved = par->update; par->update = false; @@ -924,6 +925,7 @@ static int hvfb_resume(struct hv_device *hdev) par->fb_ready = true; par->update = par->update_saved; + schedule_delayed_work(&info->deferred_work, info->fbdefio->delay); schedule_delayed_work(&par->dwork, HVFB_UPDATE_DELAY); /* 0 means do resume */ From patchwork Tue Jun 2 02:08:10 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: 1302023 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 49bb7q0MQ7z9sSJ; Tue, 2 Jun 2020 12:09:11 +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 1jfwMS-0005g5-SG; Tue, 02 Jun 2020 02:09:04 +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 1jfwMG-0005UP-MW for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:52 +0000 Received: from mail-qt1-f199.google.com ([209.85.160.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwME-0001zY-Jg for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:50 +0000 Received: by mail-qt1-f199.google.com with SMTP id h49so10089810qtk.10 for ; Mon, 01 Jun 2020 19:08:50 -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=deWAbRzzkQrVbm57GxgHbzRdTV6GnjDoEBn8WJCjBb8=; b=sE+Tjo3/38411v1IMkynqIltl4z1VqjauXPWZLAnODkHf5/4G4ZFM6pNBwZunAPbp3 WQdKDocQq+3drmolLBa4VeB/niqjlH7PiRGkjtM3ZhEmGACG1xIO8xeejxxHgqv+5a6n +ezlbIw6aBvPJl5FoIGe293PAIY0kesMRXfQ2R8glwge7TiKyYhJ8T2Ye7TKCpZGsSbY Di1XZMD6ng8hJvGyd3aE/8clp4doHe8TVPrvsj8KwkrA5rwr/tmXJzLz2WMzrI4/GExv wKSKBLJj0M6Ts5Cpi8gzGc9t20EeIN+KSxJOujvhVR9/YKIrSNM97TEVZaP5Xr4IPKLE D5Qg== X-Gm-Message-State: AOAM531znnVv7Du4455EvO/YCVLw2iZ36Fk80lEyF0ImdVnTG/Y7rWf9 XSWGlgiq2MlPEVjToykpI/4mbYWOarGKtjvFhFOX5oapmRI5xfXdpuqnXzBOlEARuiRFst/+sbO m+ZJzn91BV7vvo8c39c8BEK4OmDFGOVEmSBN+sPe9 X-Received: by 2002:a05:620a:786:: with SMTP id 6mr20224330qka.407.1591063729077; Mon, 01 Jun 2020 19:08:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLoLOYstlenCdDuctZM9KcJkezGXx5e0BwMs0LJ9Fy3dY+IV+7OGLWQgT4TVkdh3jzyCAXvg== X-Received: by 2002:a05:620a:786:: with SMTP id 6mr20224308qka.407.1591063728552; Mon, 01 Jun 2020 19:08:48 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:47 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 14/21] Tools: hv: Reopen the devices if read() or write() returns errors Date: Mon, 1 Jun 2020 23:08:10 -0300 Message-Id: <20200602020817.236422-15-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 The state machine in the hv_utils driver can run out of order in some corner cases, e.g. if the kvp daemon doesn't call write() fast enough due to some reason, kvp_timeout_func() can run first and move the state to HVUTIL_READY; next, when kvp_on_msg() is called it returns -EINVAL since kvp_transaction.state is smaller than HVUTIL_USERSPACE_REQ; later, the daemon's write() gets an error -EINVAL, and the daemon will exit(). We can reproduce the issue by sending a SIGSTOP signal to the daemon, wait for 1 minute, and send a SIGCONT signal to the daemon: the daemon will exit() quickly. We can fix the issue by forcing a reset of the device (which means the daemon can close() and open() the device again) and doing extra necessary clean-up. Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Signed-off-by: Sasha Levin (cherry picked from commit 9fc3c01a1fae669a2ef9f13ee1e1a26e057d79f8) Signed-off-by: Marcelo Henrique Cerri --- tools/hv/hv_fcopy_daemon.c | 37 ++++++++++++++++++++++++---- tools/hv/hv_kvp_daemon.c | 36 ++++++++++++++++------------ tools/hv/hv_vss_daemon.c | 49 +++++++++++++++++++++++++++++--------- 3 files changed, 91 insertions(+), 31 deletions(-) diff --git a/tools/hv/hv_fcopy_daemon.c b/tools/hv/hv_fcopy_daemon.c index aea2d91ab364..16d629b22c25 100644 --- a/tools/hv/hv_fcopy_daemon.c +++ b/tools/hv/hv_fcopy_daemon.c @@ -80,6 +80,8 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg) error = 0; done: + if (error) + target_fname[0] = '\0'; return error; } @@ -108,15 +110,29 @@ static int hv_copy_data(struct hv_do_fcopy *cpmsg) return ret; } +/* + * Reset target_fname to "" in the two below functions for hibernation: if + * the fcopy operation is aborted by hibernation, the daemon should remove the + * partially-copied file; to achieve this, the hv_utils driver always fakes a + * CANCEL_FCOPY message upon suspend, and later when the VM resumes back, + * the daemon calls hv_copy_cancel() to remove the file; if a file is copied + * successfully before suspend, hv_copy_finished() must reset target_fname to + * avoid that the file can be incorrectly removed upon resume, since the faked + * CANCEL_FCOPY message is spurious in this case. + */ static int hv_copy_finished(void) { close(target_fd); + target_fname[0] = '\0'; return 0; } static int hv_copy_cancel(void) { close(target_fd); - unlink(target_fname); + if (strlen(target_fname) > 0) { + unlink(target_fname); + target_fname[0] = '\0'; + } return 0; } @@ -131,7 +147,7 @@ void print_usage(char *argv[]) int main(int argc, char *argv[]) { - int fcopy_fd; + int fcopy_fd = -1; int error; int daemonize = 1, long_index = 0, opt; int version = FCOPY_CURRENT_VERSION; @@ -141,7 +157,7 @@ int main(int argc, char *argv[]) struct hv_do_fcopy copy; __u32 kernel_modver; } buffer = { }; - int in_handshake = 1; + int in_handshake; static struct option long_options[] = { {"help", no_argument, 0, 'h' }, @@ -170,6 +186,12 @@ int main(int argc, char *argv[]) openlog("HV_FCOPY", 0, LOG_USER); syslog(LOG_INFO, "starting; pid is:%d", getpid()); +reopen_fcopy_fd: + if (fcopy_fd != -1) + close(fcopy_fd); + /* Remove any possible partially-copied file on error */ + hv_copy_cancel(); + in_handshake = 1; fcopy_fd = open("/dev/vmbus/hv_fcopy", O_RDWR); if (fcopy_fd < 0) { @@ -196,7 +218,7 @@ int main(int argc, char *argv[]) len = pread(fcopy_fd, &buffer, sizeof(buffer), 0); if (len < 0) { syslog(LOG_ERR, "pread failed: %s", strerror(errno)); - exit(EXIT_FAILURE); + goto reopen_fcopy_fd; } if (in_handshake) { @@ -231,9 +253,14 @@ int main(int argc, char *argv[]) } + /* + * pwrite() may return an error due to the faked CANCEL_FCOPY + * message upon hibernation. Ignore the error by resetting the + * dev file, i.e. closing and re-opening it. + */ if (pwrite(fcopy_fd, &error, sizeof(int), 0) != sizeof(int)) { syslog(LOG_ERR, "pwrite failed: %s", strerror(errno)); - exit(EXIT_FAILURE); + goto reopen_fcopy_fd; } } } diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index 57c804abd2e8..f05d3b38b180 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c @@ -76,7 +76,7 @@ enum { DNS }; -static int in_hand_shake = 1; +static int in_hand_shake; static char *os_name = ""; static char *os_major = ""; @@ -1360,7 +1360,7 @@ void print_usage(char *argv[]) int main(int argc, char *argv[]) { - int kvp_fd, len; + int kvp_fd = -1, len; int error; struct pollfd pfd; char *p; @@ -1400,14 +1400,6 @@ int main(int argc, char *argv[]) openlog("KVP", 0, LOG_USER); syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); - kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC); - - if (kvp_fd < 0) { - syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s", - errno, strerror(errno)); - exit(EXIT_FAILURE); - } - /* * Retrieve OS release information. */ @@ -1423,6 +1415,18 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } +reopen_kvp_fd: + if (kvp_fd != -1) + close(kvp_fd); + in_hand_shake = 1; + kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC); + + if (kvp_fd < 0) { + syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s", + errno, strerror(errno)); + exit(EXIT_FAILURE); + } + /* * Register ourselves with the kernel. */ @@ -1456,9 +1460,7 @@ int main(int argc, char *argv[]) if (len != sizeof(struct hv_kvp_msg)) { syslog(LOG_ERR, "read failed; error:%d %s", errno, strerror(errno)); - - close(kvp_fd); - return EXIT_FAILURE; + goto reopen_kvp_fd; } /* @@ -1617,13 +1619,17 @@ int main(int argc, char *argv[]) break; } - /* Send the value back to the kernel. */ + /* + * Send the value back to the kernel. Note: the write() may + * return an error due to hibernation; we can ignore the error + * by resetting the dev file, i.e. closing and re-opening it. + */ kvp_done: len = write(kvp_fd, hv_msg, sizeof(struct hv_kvp_msg)); if (len != sizeof(struct hv_kvp_msg)) { syslog(LOG_ERR, "write failed; error: %d %s", errno, strerror(errno)); - exit(EXIT_FAILURE); + goto reopen_kvp_fd; } } diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c index 92902a88f671..dd111870beee 100644 --- a/tools/hv/hv_vss_daemon.c +++ b/tools/hv/hv_vss_daemon.c @@ -28,6 +28,8 @@ #include #include +static bool fs_frozen; + /* Don't use syslog() in the function since that can cause write to disk */ static int vss_do_freeze(char *dir, unsigned int cmd) { @@ -155,18 +157,27 @@ static int vss_operate(int operation) continue; } error |= vss_do_freeze(ent->mnt_dir, cmd); - if (error && operation == VSS_OP_FREEZE) - goto err; + if (operation == VSS_OP_FREEZE) { + if (error) + goto err; + fs_frozen = true; + } } endmntent(mounts); if (root_seen) { error |= vss_do_freeze("/", cmd); - if (error && operation == VSS_OP_FREEZE) - goto err; + if (operation == VSS_OP_FREEZE) { + if (error) + goto err; + fs_frozen = true; + } } + if (operation == VSS_OP_THAW && !error) + fs_frozen = false; + goto out; err: save_errno = errno; @@ -175,6 +186,7 @@ static int vss_operate(int operation) endmntent(mounts); } vss_operate(VSS_OP_THAW); + fs_frozen = false; /* Call syslog after we thaw all filesystems */ if (ent) syslog(LOG_ERR, "FREEZE of %s failed; error:%d %s", @@ -196,13 +208,13 @@ void print_usage(char *argv[]) int main(int argc, char *argv[]) { - int vss_fd, len; + int vss_fd = -1, len; int error; struct pollfd pfd; int op; struct hv_vss_msg vss_msg[1]; int daemonize = 1, long_index = 0, opt; - int in_handshake = 1; + int in_handshake; __u32 kernel_modver; static struct option long_options[] = { @@ -232,6 +244,18 @@ int main(int argc, char *argv[]) openlog("Hyper-V VSS", 0, LOG_USER); syslog(LOG_INFO, "VSS starting; pid is:%d", getpid()); +reopen_vss_fd: + if (vss_fd != -1) + close(vss_fd); + if (fs_frozen) { + if (vss_operate(VSS_OP_THAW) || fs_frozen) { + syslog(LOG_ERR, "failed to thaw file system: err=%d", + errno); + exit(EXIT_FAILURE); + } + } + + in_handshake = 1; vss_fd = open("/dev/vmbus/hv_vss", O_RDWR); if (vss_fd < 0) { syslog(LOG_ERR, "open /dev/vmbus/hv_vss failed; error: %d %s", @@ -284,8 +308,7 @@ int main(int argc, char *argv[]) if (len != sizeof(struct hv_vss_msg)) { syslog(LOG_ERR, "read failed; error:%d %s", errno, strerror(errno)); - close(vss_fd); - return EXIT_FAILURE; + goto reopen_vss_fd; } op = vss_msg->vss_hdr.operation; @@ -312,14 +335,18 @@ int main(int argc, char *argv[]) default: syslog(LOG_ERR, "Illegal op:%d\n", op); } + + /* + * The write() may return an error due to the faked VSS_OP_THAW + * message upon hibernation. Ignore the error by resetting the + * dev file, i.e. closing and re-opening it. + */ vss_msg->error = error; len = write(vss_fd, vss_msg, sizeof(struct hv_vss_msg)); if (len != sizeof(struct hv_vss_msg)) { syslog(LOG_ERR, "write failed; error: %d %s", errno, strerror(errno)); - - if (op == VSS_OP_FREEZE) - vss_operate(VSS_OP_THAW); + goto reopen_vss_fd; } } From patchwork Tue Jun 2 02:08:11 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: 1302024 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 49bb7s1sdmz9sSJ; Tue, 2 Jun 2020 12:09:13 +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 1jfwMV-0005iV-94; Tue, 02 Jun 2020 02:09:07 +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 1jfwMH-0005Vt-Nt for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:53 +0000 Received: from mail-qv1-f70.google.com ([209.85.219.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMG-0001zf-BR for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:52 +0000 Received: by mail-qv1-f70.google.com with SMTP id w6so2055059qvj.4 for ; Mon, 01 Jun 2020 19:08:52 -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=O+odfO5pf6DcdGAisTXHr6liQ/5x2qNhYCSqCptbol4=; b=O6sx8wyeROvmKKrb3XgIPKFes1dIybBRZBtwNIthQ8MgYV50sAf3g+ywIV8X7Whf7Q YA/l3M0/5zDSdRoTVDvZxAjUPrAeRsYCZy+Y/MX8yyfhqXWt241DVHkOnDJYyTwHB6CY j2Nl/vamTzvMqFrIEzsodwX/dr9VvMvngOjiTntzZP71y/SHJ0Hl/bBNOOgUVqvEmyCL b/Y2t5Y74X+UpiefDDe/5F64CFZsOIgcFM/PxbbUl/fpkD7cQZorp/0v3Vd4AaL3JTWl aujobtpwdgfOJ7MosCCrcyaTjCRvzIIV+9GRVNsY0jCMiBHDL0nY67G1Nvtl4Wipj4Zp UVzA== X-Gm-Message-State: AOAM5332AvdWd4vTzwPtmmOynDxDKVTZWYTPQAbErdikKF+6j9FlsWn0 2ohDxUn5iVRLHofI3jR3nYDaoe+8rjgVIqNdc7Cx3ryq5nJKr42QVwPW/mL0j3YrgENV2MTgTzI NLXo95pegMYKtikdj1O+69cllCgBjk7IYSvqgyuE1 X-Received: by 2002:a37:b903:: with SMTP id j3mr22743068qkf.356.1591063730940; Mon, 01 Jun 2020 19:08:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH6FXeEzt7GKvC8hoyEmrOCVStRYZckj0CDlrmENjUYXWzTFsWdODUiKGctAl7P29igywCuw== X-Received: by 2002:a37:b903:: with SMTP id j3mr22743057qkf.356.1591063730558; Mon, 01 Jun 2020 19:08:50 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:49 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 15/21] hv_utils: Support host-initiated restart request Date: Mon, 1 Jun 2020 23:08:11 -0300 Message-Id: <20200602020817.236422-16-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 The hv_utils driver currently supports a "shutdown" operation initiated from the Hyper-V host. Newer versions of Hyper-V also support a "restart" operation. So add support for the updated protocol version that has "restart" support, and perform a clean reboot when such a message is received from Hyper-V. To test the restart functionality, run this PowerShell command on the Hyper-V host: Restart-VM -Type Reboot Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Signed-off-by: Sasha Levin (cherry picked from commit 3e9c72056ed5618bef253f602e79dd2312a0d8a5) Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/hv_util.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index e32681ee7b9f..d710e6dec971 100644 --- a/drivers/hv/hv_util.c +++ b/drivers/hv/hv_util.c @@ -24,6 +24,8 @@ #define SD_MAJOR 3 #define SD_MINOR 0 +#define SD_MINOR_1 1 +#define SD_VERSION_3_1 (SD_MAJOR << 16 | SD_MINOR_1) #define SD_VERSION (SD_MAJOR << 16 | SD_MINOR) #define SD_MAJOR_1 1 @@ -50,8 +52,9 @@ static int sd_srv_version; static int ts_srv_version; static int hb_srv_version; -#define SD_VER_COUNT 2 +#define SD_VER_COUNT 3 static const int sd_versions[] = { + SD_VERSION_3_1, SD_VERSION, SD_VERSION_1 }; @@ -118,17 +121,27 @@ static void perform_shutdown(struct work_struct *dummy) orderly_poweroff(true); } +static void perform_restart(struct work_struct *dummy) +{ + orderly_reboot(); +} + /* * Perform the shutdown operation in a thread context. */ static DECLARE_WORK(shutdown_work, perform_shutdown); +/* + * Perform the restart operation in a thread context. + */ +static DECLARE_WORK(restart_work, perform_restart); + static void shutdown_onchannelcallback(void *context) { struct vmbus_channel *channel = context; + struct work_struct *work = NULL; u32 recvlen; u64 requestid; - bool execute_shutdown = false; u8 *shut_txf_buf = util_shutdown.recv_buffer; struct shutdown_msg_data *shutdown_msg; @@ -157,19 +170,29 @@ static void shutdown_onchannelcallback(void *context) sizeof(struct vmbuspipe_hdr) + sizeof(struct icmsg_hdr)]; + /* + * shutdown_msg->flags can be 0(shut down), 2(reboot), + * or 4(hibernate). It may bitwise-OR 1, which means + * performing the request by force. Linux always tries + * to perform the request by force. + */ switch (shutdown_msg->flags) { case 0: case 1: icmsghdrp->status = HV_S_OK; - execute_shutdown = true; - + work = &shutdown_work; pr_info("Shutdown request received -" " graceful shutdown initiated\n"); break; + case 2: + case 3: + icmsghdrp->status = HV_S_OK; + work = &restart_work; + pr_info("Restart request received -" + " graceful restart initiated\n"); + break; default: icmsghdrp->status = HV_E_FAIL; - execute_shutdown = false; - pr_info("Shutdown request received -" " Invalid request\n"); break; @@ -184,8 +207,8 @@ static void shutdown_onchannelcallback(void *context) VM_PKT_DATA_INBAND, 0); } - if (execute_shutdown == true) - schedule_work(&shutdown_work); + if (work) + schedule_work(work); } /* From patchwork Tue Jun 2 02:08:12 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: 1302025 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 49bb7t1fJYz9sSf; Tue, 2 Jun 2020 12:09:14 +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 1jfwMX-0005ji-GZ; Tue, 02 Jun 2020 02:09:09 +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 1jfwMK-0005Xs-Or for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:56 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMI-0001zk-EJ for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:54 +0000 Received: by mail-qt1-f197.google.com with SMTP id h49so10089965qtk.10 for ; Mon, 01 Jun 2020 19:08:54 -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=26OJ7TlgHNZTHsfIolsf9622CYa9GYscXSjhPGJt2TI=; b=mgmvSy+5AGClIWj0XUPVOag7hr+ZdEBqkrQJ9Rz+AxByVx8pMADE1QcUsau5I4H8vq DGGdXSXmt+FRfURuSoztpjybWZzQo9cLhlSbpR3ECDndsWiBD33o8nV/NYcwEuOiRs+O zQb7fz5Wj2PN2SdeOExzKtxeg1CXZYamdRporpHP0rJ1P7PhqeP6bwSIGivL2gswNq+v tOVq4wWsuLiaI0/sBoM68Q9AVlb61YpEfwrb6BrdlddEQPEDI36fRZyyhjfWGkUMZZzQ QPb2bvaDrFHg1FQlt6chKIjPJ+vsvnoyJoOEjqTnkX/0lDhDXSWvfUoBno8Vh+pBhPlL gEHA== X-Gm-Message-State: AOAM530NZmCWMMVEBK+bLVdx/tAZ6PTjgY/HdSoPlbcKW4W65DHymfDn Q7mxwLzER1xPUkvMUtGP7x1R7u4NW+BbBuqkCORBkz2a7XPU/t49n2rw4IfJWUU7lExG3uv3xe4 IHC1jyh/pihtVr3C+BdPOT9tzXEKGJ4zj0xw2A5Db X-Received: by 2002:ac8:6bd3:: with SMTP id b19mr5163106qtt.27.1591063733072; Mon, 01 Jun 2020 19:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcg32yGV78WGYf/nbBB1FJ9xd62uELgSPHmdhq+zmq1Ad8CmYNwe8dnk7qgZuvS1L8PMa0Fg== X-Received: by 2002:ac8:6bd3:: with SMTP id b19mr5163083qtt.27.1591063732743; Mon, 01 Jun 2020 19:08:52 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:51 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 16/21] hv_utils: Support host-initiated hibernation request Date: Mon, 1 Jun 2020 23:08:12 -0300 Message-Id: <20200602020817.236422-17-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 Update the Shutdown IC version to 3.2, which is required for the host to send the hibernation request. The user is expected to create the below udev rule file, which is applied upon the host-initiated hibernation request: root@localhost:~# cat /usr/lib/udev/rules.d/40-vm-hibernation.rules SUBSYSTEM=="vmbus", ACTION=="change", DRIVER=="hv_utils", ENV{EVENT}=="hibernate", RUN+="/usr/bin/systemctl hibernate" Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Signed-off-by: Sasha Levin (cherry picked from commit ffd1d4a49336b7f0078f45332fa4b93d25720f6c) Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/hv_util.c | 49 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index d710e6dec971..f27a071da614 100644 --- a/drivers/hv/hv_util.c +++ b/drivers/hv/hv_util.c @@ -25,7 +25,9 @@ #define SD_MAJOR 3 #define SD_MINOR 0 #define SD_MINOR_1 1 +#define SD_MINOR_2 2 #define SD_VERSION_3_1 (SD_MAJOR << 16 | SD_MINOR_1) +#define SD_VERSION_3_2 (SD_MAJOR << 16 | SD_MINOR_2) #define SD_VERSION (SD_MAJOR << 16 | SD_MINOR) #define SD_MAJOR_1 1 @@ -52,8 +54,9 @@ static int sd_srv_version; static int ts_srv_version; static int hb_srv_version; -#define SD_VER_COUNT 3 +#define SD_VER_COUNT 4 static const int sd_versions[] = { + SD_VERSION_3_2, SD_VERSION_3_1, SD_VERSION, SD_VERSION_1 @@ -78,9 +81,45 @@ static const int fw_versions[] = { UTIL_WS2K8_FW_VERSION }; +/* + * Send the "hibernate" udev event in a thread context. + */ +struct hibernate_work_context { + struct work_struct work; + struct hv_device *dev; +}; + +static struct hibernate_work_context hibernate_context; +static bool hibernation_supported; + +static void send_hibernate_uevent(struct work_struct *work) +{ + char *uevent_env[2] = { "EVENT=hibernate", NULL }; + struct hibernate_work_context *ctx; + + ctx = container_of(work, struct hibernate_work_context, work); + + kobject_uevent_env(&ctx->dev->device.kobj, KOBJ_CHANGE, uevent_env); + + pr_info("Sent hibernation uevent\n"); +} + +static int hv_shutdown_init(struct hv_util_service *srv) +{ + struct vmbus_channel *channel = srv->channel; + + INIT_WORK(&hibernate_context.work, send_hibernate_uevent); + hibernate_context.dev = channel->device_obj; + + hibernation_supported = hv_is_hibernation_supported(); + + return 0; +} + static void shutdown_onchannelcallback(void *context); static struct hv_util_service util_shutdown = { .util_cb = shutdown_onchannelcallback, + .util_init = hv_shutdown_init, }; static int hv_timesync_init(struct hv_util_service *srv); @@ -191,6 +230,14 @@ static void shutdown_onchannelcallback(void *context) pr_info("Restart request received -" " graceful restart initiated\n"); break; + case 4: + case 5: + pr_info("Hibernation request received\n"); + icmsghdrp->status = hibernation_supported ? + HV_S_OK : HV_E_FAIL; + if (hibernation_supported) + work = &hibernate_context.work; + break; default: icmsghdrp->status = HV_E_FAIL; pr_info("Shutdown request received -" From patchwork Tue Jun 2 02:08:13 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: 1302026 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 49bb7w5zlSz9sSJ; Tue, 2 Jun 2020 12:09:16 +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 1jfwMY-0005lP-PB; Tue, 02 Jun 2020 02:09:10 +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 1jfwMN-0005a6-5u for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:59 +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 1jfwMK-0001zq-Mb for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:08:56 +0000 Received: by mail-qv1-f71.google.com with SMTP id t8so2075293qvs.19 for ; Mon, 01 Jun 2020 19:08:56 -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=vUOPK8tWzXcVw/vSSHZ0Jg6GAOFh10BxbKXUPHDK1hU=; b=pY8CJ/2BNy4sSLKxPyWvs5fVcOBIwCSWJghpMJcN2v0QwrwpRSNdTL+JP53A1ah9It W9hCTLP14lSkx4J+MAQMYsZsZZGZ8YMx+raWQYweStcVFr8AHxd35nAVLIBaGxG8gipG sdYUdhyXsOa+Ys+6Y3HXWW9MoelA0JiBdbNJHJb79zhWdaIaq4DRKe/vkOrqR6Lu+Y43 YGQwEjy2ycevL4yjh1TJjbF/KTSSLaECZ206AyjPhgHZzyColgRqRJkBnh9X0DkeIVhX xvMOEVWMKLT+Ywg6clfrJasCrQ6rvy+TgXbYtPsfSiResukRLkVZVifo9zyUOvxUTMAQ 2F+w== X-Gm-Message-State: AOAM531kaTv6nQ3lS4x01LFRMYgMyOFBB1LhJ8zb5dxYZKwZsVqvttEt md3qdnkKGATh3iLieRDqZiowgSpy17mQQMnbeA8a7wIpIoomo1Hw3JQUWvjKk8lgg4kp9feh092 EvOb5LeTUW1TL0xg1Ne6TyviTnunJLOFjhUJI40P3 X-Received: by 2002:a37:384:: with SMTP id 126mr22652708qkd.325.1591063735064; Mon, 01 Jun 2020 19:08:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYHEpF9oizkdAtosCsxeQB94sTIq5ydIss58Q6PqwCs7o6EIlUh1OTNZaEpS92x8OsxKDTZw== X-Received: by 2002:a37:384:: with SMTP id 126mr22652655qkd.325.1591063734569; Mon, 01 Jun 2020 19:08:54 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:53 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 17/21] hv_utils: Add the support of hibernation Date: Mon, 1 Jun 2020 23:08:13 -0300 Message-Id: <20200602020817.236422-18-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 Add util_pre_suspend() and util_pre_resume() for some hv_utils devices (e.g. kvp/vss/fcopy), because they need special handling before util_suspend() calls vmbus_close(). For kvp, all the possible pending work items should be cancelled. For vss and fcopy, some extra clean-up needs to be done, i.e. fake a THAW message for hv_vss_daemon and fake a CANCEL_FCOPY message for hv_fcopy_daemon, otherwise when the VM resums back, the daemons can end up in an inconsistent state (i.e. the file systems are frozen but will never be thawed; the file transmitted via fcopy may not be complete). Note: there is an extra patch for the daemons: "Tools: hv: Reopen the devices if read() or write() returns errors", because the hv_utils driver can not guarantee the whole transaction finishes completely once util_suspend() starts to run (at this time, all the userspace processes are frozen). util_probe() disables channel->callback_event to avoid the race with the channel callback. Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Signed-off-by: Sasha Levin (cherry picked from commit 54e19d34011fea26d39aa74781131de0ce642a01) Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/hv_fcopy.c | 54 +++++++++++++++++++++++++++++++++- drivers/hv/hv_kvp.c | 43 +++++++++++++++++++++++++-- drivers/hv/hv_snapshot.c | 55 ++++++++++++++++++++++++++++++++-- drivers/hv/hv_util.c | 62 ++++++++++++++++++++++++++++++++++++++- drivers/hv/hyperv_vmbus.h | 6 ++++ include/linux/hyperv.h | 2 ++ 6 files changed, 216 insertions(+), 6 deletions(-) diff --git a/drivers/hv/hv_fcopy.c b/drivers/hv/hv_fcopy.c index 7e30ae0635cc..be89db4b0a8f 100644 --- a/drivers/hv/hv_fcopy.c +++ b/drivers/hv/hv_fcopy.c @@ -345,9 +345,61 @@ int hv_fcopy_init(struct hv_util_service *srv) return 0; } +static void hv_fcopy_cancel_work(void) +{ + cancel_delayed_work_sync(&fcopy_timeout_work); + cancel_work_sync(&fcopy_send_work); +} + +int hv_fcopy_pre_suspend(void) +{ + struct vmbus_channel *channel = fcopy_transaction.recv_channel; + struct hv_fcopy_hdr *fcopy_msg; + + /* + * Fake a CANCEL_FCOPY message for the user space daemon in case the + * daemon is in the middle of copying some file. It doesn't matter if + * there is already a message pending to be delivered to the user + * space since we force fcopy_transaction.state to be HVUTIL_READY, so + * the user space daemon's write() will fail with EINVAL (see + * fcopy_on_msg()), and the daemon will reset the device by closing + * and re-opening it. + */ + fcopy_msg = kzalloc(sizeof(*fcopy_msg), GFP_KERNEL); + if (!fcopy_msg) + return -ENOMEM; + + tasklet_disable(&channel->callback_event); + + fcopy_msg->operation = CANCEL_FCOPY; + + hv_fcopy_cancel_work(); + + /* We don't care about the return value. */ + hvutil_transport_send(hvt, fcopy_msg, sizeof(*fcopy_msg), NULL); + + kfree(fcopy_msg); + + fcopy_transaction.state = HVUTIL_READY; + + /* tasklet_enable() will be called in hv_fcopy_pre_resume(). */ + return 0; +} + +int hv_fcopy_pre_resume(void) +{ + struct vmbus_channel *channel = fcopy_transaction.recv_channel; + + tasklet_enable(&channel->callback_event); + + return 0; +} + void hv_fcopy_deinit(void) { fcopy_transaction.state = HVUTIL_DEVICE_DYING; - cancel_delayed_work_sync(&fcopy_timeout_work); + + hv_fcopy_cancel_work(); + hvutil_transport_destroy(hvt); } diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c index 5054d1105236..6bf482e5c332 100644 --- a/drivers/hv/hv_kvp.c +++ b/drivers/hv/hv_kvp.c @@ -757,11 +757,50 @@ hv_kvp_init(struct hv_util_service *srv) return 0; } -void hv_kvp_deinit(void) +static void hv_kvp_cancel_work(void) { - kvp_transaction.state = HVUTIL_DEVICE_DYING; cancel_delayed_work_sync(&kvp_host_handshake_work); cancel_delayed_work_sync(&kvp_timeout_work); cancel_work_sync(&kvp_sendkey_work); +} + +int hv_kvp_pre_suspend(void) +{ + struct vmbus_channel *channel = kvp_transaction.recv_channel; + + tasklet_disable(&channel->callback_event); + + /* + * If there is a pending transtion, it's unnecessary to tell the host + * that the transaction will fail, because that is implied when + * util_suspend() calls vmbus_close() later. + */ + hv_kvp_cancel_work(); + + /* + * Forece the state to READY to handle the ICMSGTYPE_NEGOTIATE message + * later. The user space daemon may go out of order and its write() + * may fail with EINVAL: this doesn't matter since the daemon will + * reset the device by closing and re-opening it. + */ + kvp_transaction.state = HVUTIL_READY; + return 0; +} + +int hv_kvp_pre_resume(void) +{ + struct vmbus_channel *channel = kvp_transaction.recv_channel; + + tasklet_enable(&channel->callback_event); + + return 0; +} + +void hv_kvp_deinit(void) +{ + kvp_transaction.state = HVUTIL_DEVICE_DYING; + + hv_kvp_cancel_work(); + hvutil_transport_destroy(hvt); } diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c index 20ba95b75a94..560b62ee2443 100644 --- a/drivers/hv/hv_snapshot.c +++ b/drivers/hv/hv_snapshot.c @@ -378,10 +378,61 @@ hv_vss_init(struct hv_util_service *srv) return 0; } -void hv_vss_deinit(void) +static void hv_vss_cancel_work(void) { - vss_transaction.state = HVUTIL_DEVICE_DYING; cancel_delayed_work_sync(&vss_timeout_work); cancel_work_sync(&vss_handle_request_work); +} + +int hv_vss_pre_suspend(void) +{ + struct vmbus_channel *channel = vss_transaction.recv_channel; + struct hv_vss_msg *vss_msg; + + /* + * Fake a THAW message for the user space daemon in case the daemon + * has frozen the file systems. It doesn't matter if there is already + * a message pending to be delivered to the user space since we force + * vss_transaction.state to be HVUTIL_READY, so the user space daemon's + * write() will fail with EINVAL (see vss_on_msg()), and the daemon + * will reset the device by closing and re-opening it. + */ + vss_msg = kzalloc(sizeof(*vss_msg), GFP_KERNEL); + if (!vss_msg) + return -ENOMEM; + + tasklet_disable(&channel->callback_event); + + vss_msg->vss_hdr.operation = VSS_OP_THAW; + + /* Cancel any possible pending work. */ + hv_vss_cancel_work(); + + /* We don't care about the return value. */ + hvutil_transport_send(hvt, vss_msg, sizeof(*vss_msg), NULL); + + kfree(vss_msg); + + vss_transaction.state = HVUTIL_READY; + + /* tasklet_enable() will be called in hv_vss_pre_resume(). */ + return 0; +} + +int hv_vss_pre_resume(void) +{ + struct vmbus_channel *channel = vss_transaction.recv_channel; + + tasklet_enable(&channel->callback_event); + + return 0; +} + +void hv_vss_deinit(void) +{ + vss_transaction.state = HVUTIL_DEVICE_DYING; + + hv_vss_cancel_work(); + hvutil_transport_destroy(hvt); } diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index f27a071da614..ca4c85672cc1 100644 --- a/drivers/hv/hv_util.c +++ b/drivers/hv/hv_util.c @@ -123,12 +123,14 @@ static struct hv_util_service util_shutdown = { }; static int hv_timesync_init(struct hv_util_service *srv); +static int hv_timesync_pre_suspend(void); static void hv_timesync_deinit(void); static void timesync_onchannelcallback(void *context); static struct hv_util_service util_timesynch = { .util_cb = timesync_onchannelcallback, .util_init = hv_timesync_init, + .util_pre_suspend = hv_timesync_pre_suspend, .util_deinit = hv_timesync_deinit, }; @@ -140,18 +142,24 @@ static struct hv_util_service util_heartbeat = { static struct hv_util_service util_kvp = { .util_cb = hv_kvp_onchannelcallback, .util_init = hv_kvp_init, + .util_pre_suspend = hv_kvp_pre_suspend, + .util_pre_resume = hv_kvp_pre_resume, .util_deinit = hv_kvp_deinit, }; static struct hv_util_service util_vss = { .util_cb = hv_vss_onchannelcallback, .util_init = hv_vss_init, + .util_pre_suspend = hv_vss_pre_suspend, + .util_pre_resume = hv_vss_pre_resume, .util_deinit = hv_vss_deinit, }; static struct hv_util_service util_fcopy = { .util_cb = hv_fcopy_onchannelcallback, .util_init = hv_fcopy_init, + .util_pre_suspend = hv_fcopy_pre_suspend, + .util_pre_resume = hv_fcopy_pre_resume, .util_deinit = hv_fcopy_deinit, }; @@ -510,6 +518,44 @@ static int util_remove(struct hv_device *dev) return 0; } +/* + * When we're in util_suspend(), all the userspace processes have been frozen + * (refer to hibernate() -> freeze_processes()). The userspace is thawed only + * after the whole resume procedure, including util_resume(), finishes. + */ +static int util_suspend(struct hv_device *dev) +{ + struct hv_util_service *srv = hv_get_drvdata(dev); + int ret = 0; + + if (srv->util_pre_suspend) { + ret = srv->util_pre_suspend(); + if (ret) + return ret; + } + + vmbus_close(dev->channel); + + return 0; +} + +static int util_resume(struct hv_device *dev) +{ + struct hv_util_service *srv = hv_get_drvdata(dev); + int ret = 0; + + if (srv->util_pre_resume) { + ret = srv->util_pre_resume(); + if (ret) + return ret; + } + + ret = vmbus_open(dev->channel, 4 * HV_HYP_PAGE_SIZE, + 4 * HV_HYP_PAGE_SIZE, NULL, 0, srv->util_cb, + dev->channel); + return ret; +} + static const struct hv_vmbus_device_id id_table[] = { /* Shutdown guid */ { HV_SHUTDOWN_GUID, @@ -546,6 +592,8 @@ static struct hv_driver util_drv = { .id_table = id_table, .probe = util_probe, .remove = util_remove, + .suspend = util_suspend, + .resume = util_resume, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, @@ -615,11 +663,23 @@ static int hv_timesync_init(struct hv_util_service *srv) return 0; } +static void hv_timesync_cancel_work(void) +{ + cancel_work_sync(&adj_time_work); +} + +static int hv_timesync_pre_suspend(void) +{ + hv_timesync_cancel_work(); + return 0; +} + static void hv_timesync_deinit(void) { if (hv_ptp_clock) ptp_clock_unregister(hv_ptp_clock); - cancel_work_sync(&adj_time_work); + + hv_timesync_cancel_work(); } static int __init init_hyperv_utils(void) diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index af9379a3bf89..d09c81d75620 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -352,14 +352,20 @@ void vmbus_on_msg_dpc(unsigned long data); int hv_kvp_init(struct hv_util_service *srv); void hv_kvp_deinit(void); +int hv_kvp_pre_suspend(void); +int hv_kvp_pre_resume(void); void hv_kvp_onchannelcallback(void *context); int hv_vss_init(struct hv_util_service *srv); void hv_vss_deinit(void); +int hv_vss_pre_suspend(void); +int hv_vss_pre_resume(void); void hv_vss_onchannelcallback(void *context); int hv_fcopy_init(struct hv_util_service *srv); void hv_fcopy_deinit(void); +int hv_fcopy_pre_suspend(void); +int hv_fcopy_pre_resume(void); void hv_fcopy_onchannelcallback(void *context); void vmbus_initiate_unload(bool crash); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 6dcb1ad957e3..b7bf3624dac8 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1412,6 +1412,8 @@ struct hv_util_service { void (*util_cb)(void *); int (*util_init)(struct hv_util_service *); void (*util_deinit)(void); + int (*util_pre_suspend)(void); + int (*util_pre_resume)(void); }; struct vmbuspipe_hdr { From patchwork Tue Jun 2 02:08:14 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: 1302027 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 49bb7y4BFqz9sSW; Tue, 2 Jun 2020 12:09:18 +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 1jfwMb-0005mt-39; Tue, 02 Jun 2020 02:09:13 +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 1jfwMQ-0005c7-2H for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:02 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMN-00020d-Vl for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:00 +0000 Received: by mail-qt1-f197.google.com with SMTP id y7so4184059qti.8 for ; Mon, 01 Jun 2020 19:08:59 -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=Wqar0Ktg720XXYt2OtCON8tw0Cw0V6f/uba1PLavFl0=; b=dmh0ve4vo+5Wm36Kto3rQ8Wdkxnf2a3Fz2ROPSdrJrCsZib5Otai2a+dgZV1FThPf3 a/aS9xgJ6B0mWI4uN33V+vBtVSSq+eVnWPdj0CVzk9btcjdZKA72x0X/itKwMMeVPknK dJZvcYEgRL7e2P+s0VlfEoju8phDjuKQNjSHBctZeGG+mFU3mYoi0x2/DRJDkgeEl88U NHPUtwUpawfZStKrsm8nNymIcmBeRvNOGT28+MWt3790uLmSdt7DHftGP2GBvkgj8sOc aSg5FGOfXgSY3+Q3O5ZSSXADWMeW2vfPHWXaP4r3wNAecDS1V0ZROoaF/LF1j4OlVDL6 3q9A== X-Gm-Message-State: AOAM532WHIvoT6R9KlO9paod3NAne9uUhAJ1OiojSYfgzHMrNSl6bIp3 HcFolu6/8KWp+iLfAoT9Jlm6Y3LeVdVV7FnnLIesIdW0r0km3a/QGsL+GQYuBqqXRPIKf8F7LH4 2ifIylQ4c6MYjfFC/0c9wylcSRnNxzKwahfWq+kMd X-Received: by 2002:a0c:8b5e:: with SMTP id d30mr24146924qvc.45.1591063738649; Mon, 01 Jun 2020 19:08:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYaRLcYijtU235atgJF1aDzxRzsQvuCMUoFEKdpf4b0DeztIRo8J320GNYKYWUNd+e7iy+UA== X-Received: by 2002:a0c:8b5e:: with SMTP id d30mr24146823qvc.45.1591063736703; Mon, 01 Jun 2020 19:08:56 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:55 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 18/21] x86/hyperv: Suspend/resume the hypercall page for hibernation Date: Mon, 1 Jun 2020 23:08:14 -0300 Message-Id: <20200602020817.236422-19-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 For hibernation the hypercall page must be disabled before the hibernation image is created so that subsequent hypercall operations fail safely. On resume the hypercall page has to be restored and reenabled to ensure proper operation of the resumed kernel. Implement the necessary suspend/resume callbacks. [ tglx: Decrypted changelog ] Signed-off-by: Dexuan Cui Signed-off-by: Thomas Gleixner Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/1578350559-130275-1-git-send-email-decui@microsoft.com (cherry picked from commit 05bd330a7fd8875c423fc07d8ddcad73c10e556e) Signed-off-by: Marcelo Henrique Cerri --- arch/x86/hyperv/hv_init.c | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index b4c49cabb436..ce15f4228fde 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #ifndef PKG_ABI @@ -35,6 +36,9 @@ void *hv_hypercall_pg; EXPORT_SYMBOL_GPL(hv_hypercall_pg); +/* Storage to save the hypercall page temporarily for hibernation */ +static void *hv_hypercall_pg_saved; + u32 *hv_vp_index; EXPORT_SYMBOL_GPL(hv_vp_index); @@ -247,6 +251,48 @@ static int __init hv_pci_init(void) return 1; } +static int hv_suspend(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + + /* + * Reset the hypercall page as it is going to be invalidated + * accross hibernation. Setting hv_hypercall_pg to NULL ensures + * that any subsequent hypercall operation fails safely instead of + * crashing due to an access of an invalid page. The hypercall page + * pointer is restored on resume. + */ + hv_hypercall_pg_saved = hv_hypercall_pg; + hv_hypercall_pg = NULL; + + /* Disable the hypercall page in the hypervisor */ + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + hypercall_msr.enable = 0; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + + return 0; +} + +static void hv_resume(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + + /* Re-enable the hypercall page */ + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + hypercall_msr.enable = 1; + hypercall_msr.guest_physical_address = + vmalloc_to_pfn(hv_hypercall_pg_saved); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + + hv_hypercall_pg = hv_hypercall_pg_saved; + hv_hypercall_pg_saved = NULL; +} + +static struct syscore_ops hv_syscore_ops = { + .suspend = hv_suspend, + .resume = hv_resume, +}; + /* * This function is to be invoked early in the boot sequence after the * hypervisor has been detected. @@ -331,6 +377,8 @@ void __init hyperv_init(void) x86_init.pci.arch_init = hv_pci_init; + register_syscore_ops(&hv_syscore_ops); + return; remove_cpuhp_state: @@ -350,6 +398,8 @@ void hyperv_cleanup(void) { union hv_x64_msr_hypercall_contents hypercall_msr; + unregister_syscore_ops(&hv_syscore_ops); + /* Reset our OS id */ wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); From patchwork Tue Jun 2 02:08:15 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: 1302028 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 49bb7z6K2cz9sSJ; Tue, 2 Jun 2020 12:09:19 +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 1jfwMc-0005oj-U7; Tue, 02 Jun 2020 02:09:14 +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 1jfwMP-0005ck-HM for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:01 +0000 Received: from mail-qk1-f197.google.com ([209.85.222.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMO-00020l-GG for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:00 +0000 Received: by mail-qk1-f197.google.com with SMTP id v197so6029197qkb.16 for ; Mon, 01 Jun 2020 19:09:00 -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=kcLAe3wr3CHrmP1Ghh0tSVsaCFIUaCxKGmFBpTntorM=; b=bAViE0cOkM48wyrMNfUEpPCp56xyDTuBPdoVSLREjkMyFdMK7F4BhWAXgMp6QD/YoB grsABYE0TrR5W3ZZdVvfeIcepPWC5qSTkXhgt/dXGUuPXDGrsT3s5GTqgntMV/wbb8Mc 4HMHI1bmYNLfZS2wBXeBi9SLQ+GKh0pH0FA4ebOO9lWsLdnQTWaCoAfrR52PabxcCHad R/j4y5pYOa3Q3b1CHsNOMZ4R6SMiwYS/C9tNAAwa+gQBHqF52ATgbgMq3qqyBvZvb2hS vDIuVWQAAvG0JsFQEQwrzNWEynKwZU+V/kEJoZSL7w3gNOxX1e0VOTIFxoHgbN4wAktJ wWtg== X-Gm-Message-State: AOAM53172DW6W/D7DXzNpSHwKVwThmRwSp2wC8bRvJKkXrYStjDnZEN2 SAOHSQh/XcOwsiwRJZvDNsEQv1kVKl+I5GSuoH9t7BrTAGiQ/fbIYGtWDh1nuLlhEyHVAFehrrF URHg6mcMyNYx8WW4cWp73/BRMML3KQqSohXewarpy X-Received: by 2002:a0c:8c4a:: with SMTP id o10mr23863438qvb.123.1591063738832; Mon, 01 Jun 2020 19:08:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR/oh1N9ojAqA3Y2Dk89ncW/6FKBUpO/UZRfFSrRWpWXs/2UqGmhG5Npd8TAhHi3pKsvlbwA== X-Received: by 2002:a0c:8c4a:: with SMTP id o10mr23863425qvb.123.1591063738531; Mon, 01 Jun 2020 19:08:58 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:57 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 19/21] PM: hibernate: Propagate the return value of hibernation_restore() Date: Mon, 1 Jun 2020 23:08:15 -0300 Message-Id: <20200602020817.236422-20-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 If hibernation_restore() fails, the 'error' should not be zero. Signed-off-by: Dexuan Cui Signed-off-by: Rafael J. Wysocki (cherry picked from commit 3704a6a445790e6621c19be25d85dfadbeb16a69) Signed-off-by: Marcelo Henrique Cerri --- kernel/power/hibernate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index b6c5895ced36..5944a4c13e28 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -678,7 +678,7 @@ static int load_image_and_restore(void) error = swsusp_read(&flags); swsusp_close(FMODE_READ); if (!error) - hibernation_restore(flags & SF_PLATFORM_MODE); + error = hibernation_restore(flags & SF_PLATFORM_MODE); pr_err("Failed to load hibernation image, recovering.\n"); swsusp_free(); From patchwork Tue Jun 2 02:08:16 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: 1302029 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 49bb831Xq1z9sSJ; Tue, 2 Jun 2020 12:09:23 +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 1jfwMf-0005rG-1T; Tue, 02 Jun 2020 02:09:17 +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 1jfwMR-0005ex-Pt for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:03 +0000 Received: from mail-qv1-f70.google.com ([209.85.219.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMQ-00021r-Ct for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:02 +0000 Received: by mail-qv1-f70.google.com with SMTP id i6so2056199qvq.17 for ; Mon, 01 Jun 2020 19:09:02 -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=BFUuAJSvVjIdYeDuzYUxnsOcBe8hK01EBIPXwISjhMA=; b=ucKvowg/Mwc7CjIg0frKKwVN3D7iIPsaszHmHGMR8+zPSLQ1JoTqtxuFlolx4ARiCq MN61m5WtzqysUN5c+a7MePUROGM/liR+vWvpxFHtfCiyC3aFRTM4bRQiwGvegKcLzeqp j2jsAlN24emDF9UAhAZMZavCezBr7qMczBcPedOE94m7gx54kGX5nLBylCD2CfJ7h3lb 9vXGm5VKiG7vb1D7ZqbGz0H6vl2FrJ8gVDenNTyV/PRN/Z1LySrcsKXtokToa32Kbm5N iU1r/Knf18pY/K22q0KsBW+9fOpMX9BD5wKYNPNeQcZv7dSm0a2iT/W9kXTluwOtXu3w oXFA== X-Gm-Message-State: AOAM5323UphuSTyBW11LrPz1eP1Ohldu+1mKVJOMbAEZNwc11FIErC88 RAYHSEPnMqgjiZHYYqdFnMo7pEczcJ7lM+xx0YTonHu2zJl3Z99ZQ8tb4NZAL8IUj67b4N4R8NQ +RrkjE1L5MlPAsOOHSCut+d28r4q0wubZ54ZfcEFp X-Received: by 2002:ac8:7683:: with SMTP id g3mr25121718qtr.240.1591063740850; Mon, 01 Jun 2020 19:09:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH5617gFfI5reWZ1CV0Bo0XQGBxGhY0gKarsIZtHx5hPV1kXqHZmZ92LkOlKt0qjr4VPygdA== X-Received: by 2002:ac8:7683:: with SMTP id g3mr25121698qtr.240.1591063740442; Mon, 01 Jun 2020 19:09:00 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.08.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:08:59 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 20/21] x86/hyperv: Suspend/resume the VP assist page for hibernation Date: Mon, 1 Jun 2020 23:08:16 -0300 Message-Id: <20200602020817.236422-21-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 Unlike the other CPUs, CPU0 is never offlined during hibernation, so in the resume path, the "new" kernel's VP assist page is not suspended (i.e. not disabled), and later when we jump to the "old" kernel, the page is not properly re-enabled for CPU0 with the allocated page from the old kernel. So far, the VP assist page is used by hv_apic_eoi_write(), and is also used in the case of nested virtualization (running KVM atop Hyper-V). For hv_apic_eoi_write(), when the page is not properly re-enabled, hvp->apic_assist is always 0, so the HV_X64_MSR_EOI MSR is always written. This is not ideal with respect to performance, but Hyper-V can still correctly handle this according to the Hyper-V spec; nevertheless, Linux still must update the Hyper-V hypervisor with the correct VP assist page to prevent Hyper-V from writing to the stale page, which causes guest memory corruption and consequently may have caused the hangs and triple faults seen during non-boot CPUs resume. Fix the issue by calling hv_cpu_die()/hv_cpu_init() in the syscore ops. Without the fix, hibernation can fail at a rate of 1/300 ~ 1/500. With the fix, hibernation can pass a long-haul test of 2000 runs. In the case of nested virtualization, disabling/reenabling the assist page upon hibernation may be unsafe if there are active L2 guests. It looks KVM should be enhanced to abort the hibernation request if there is any active L2 guest. Fixes: 05bd330a7fd8 ("x86/hyperv: Suspend/resume the hypercall page for hibernation") Cc: stable@vger.kernel.org Signed-off-by: Dexuan Cui Link: https://lore.kernel.org/r/1587437171-2472-1-git-send-email-decui@microsoft.com Signed-off-by: Wei Liu (cherry picked from commit 421f090c819d695942a470051cd624dc43deaf95) Signed-off-by: Marcelo Henrique Cerri --- arch/x86/hyperv/hv_init.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index ce15f4228fde..c14469fe93d2 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -73,7 +73,8 @@ static int hv_cpu_init(unsigned int cpu) struct page *pg; input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); - pg = alloc_page(GFP_KERNEL); + /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ + pg = alloc_page(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); if (unlikely(!pg)) return -ENOMEM; *input_arg = page_address(pg); @@ -254,6 +255,7 @@ static int __init hv_pci_init(void) static int hv_suspend(void) { union hv_x64_msr_hypercall_contents hypercall_msr; + int ret; /* * Reset the hypercall page as it is going to be invalidated @@ -270,12 +272,17 @@ static int hv_suspend(void) hypercall_msr.enable = 0; wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); - return 0; + ret = hv_cpu_die(0); + return ret; } static void hv_resume(void) { union hv_x64_msr_hypercall_contents hypercall_msr; + int ret; + + ret = hv_cpu_init(0); + WARN_ON(ret); /* Re-enable the hypercall page */ rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); @@ -288,6 +295,7 @@ static void hv_resume(void) hv_hypercall_pg_saved = NULL; } +/* Note: when the ops are called, only CPU0 is online and IRQs are disabled. */ static struct syscore_ops hv_syscore_ops = { .suspend = hv_suspend, .resume = hv_resume, From patchwork Tue Jun 2 02:08:17 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: 1302030 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 49bb836GCDz9sSn; Tue, 2 Jun 2020 12:09:23 +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 1jfwMg-0005t3-Oq; Tue, 02 Jun 2020 02:09:18 +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 1jfwMU-0005g6-1d for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:06 +0000 Received: from mail-qv1-f69.google.com ([209.85.219.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jfwMS-00022M-2s for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 02:09:04 +0000 Received: by mail-qv1-f69.google.com with SMTP id i6so2056260qvq.17 for ; Mon, 01 Jun 2020 19:09:04 -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=NJRuraGrzp80qkod3Glqbj4dDmShPpDhrC3S90kZPyk=; b=uaCj1v/lp9yCvV4SyFYeB4tzI1B7JgzOO8HZs9W7+eptqhKbk20gLaZ/in4md74FsV SY9LsHajWA/PmNf5nppL40nz77zqP1wG+Cagm8cytFfQfZhJ2gxV6FOfISthqUyTDNUt vSk07SDaGnHXC5Fz4IIuQOT95ElzQhR4Gu6GLJRdeyaSIagjVQAwkq3qfb7ZwfwbGnVn lWxb+hRVNrhECfNbzzLTn2dtnQ01jMiFsGFFkC0pibmqh89uF+xhTPfF2xSW+3fjadYQ VB8ZFJWKdNQGyiqcFoMTELedc4IGh8jZAncF+/Ecmj6lQaqpzThp5IhxhbNCQXmOivGv 65ig== X-Gm-Message-State: AOAM533Lij8XRJmxKg4eQC4RIVPA8dM12meKqOjXB1WjiENIlbYCHuTW tmwf2usOBMKe5GBEXbnHFeFEDP7cBSDfMjQFQOCb75qlseFHrOTXDl9R/Qa3g25tZzBMS1qW5T6 fXM0iKkFHtlv/utrX4gadpQ5uO4UrUpklULqZWkXe X-Received: by 2002:a0c:aa4c:: with SMTP id e12mr22987093qvb.12.1591063742691; Mon, 01 Jun 2020 19:09:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQcTfbDvzoxei3nsOSCjPacc5FD+oTVuxyM/7FvQOVibXJlHgGoAGWb9THkzfh8tv9kXNt1A== X-Received: by 2002:a0c:aa4c:: with SMTP id e12mr22987078qvb.12.1591063742374; Mon, 01 Jun 2020 19:09:02 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id t13sm1138342qtc.77.2020.06.01.19.09.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 19:09:01 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][PATCH 21/21] net/mlx5: Fix crash upon suspend/resume Date: Mon, 1 Jun 2020 23:08:17 -0300 Message-Id: <20200602020817.236422-22-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: Mark Bloch BugLink: http://bugs.launchpad.net/bugs/1880032 Currently a Linux system with the mlx5 NIC always crashes upon hibernation - suspend/resume. Add basic callbacks so the NIC could be suspended and resumed. Fixes: 9603b61de1ee ("mlx5: Move pci device handling from mlx5_ib to mlx5_core") Tested-by: Dexuan Cui Signed-off-by: Mark Bloch Reviewed-by: Moshe Shemesh Signed-off-by: Saeed Mahameed (cherry picked from commit 8fc3e29be9248048f449793502c15af329f35c6e) Signed-off-by: Marcelo Henrique Cerri --- drivers/net/ethernet/mellanox/mlx5/core/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index c96a0e501007..297b5dc64a25 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1553,6 +1553,22 @@ static void shutdown(struct pci_dev *pdev) mlx5_pci_disable_device(dev); } +static int mlx5_suspend(struct pci_dev *pdev, pm_message_t state) +{ + struct mlx5_core_dev *dev = pci_get_drvdata(pdev); + + mlx5_unload_one(dev, false); + + return 0; +} + +static int mlx5_resume(struct pci_dev *pdev) +{ + struct mlx5_core_dev *dev = pci_get_drvdata(pdev); + + return mlx5_load_one(dev, false); +} + static const struct pci_device_id mlx5_core_pci_table[] = { { PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_CONNECTIB) }, { PCI_VDEVICE(MELLANOX, 0x1012), MLX5_PCI_DEV_IS_VF}, /* Connect-IB VF */ @@ -1596,6 +1612,8 @@ static struct pci_driver mlx5_core_driver = { .id_table = mlx5_core_pci_table, .probe = init_one, .remove = remove_one, + .suspend = mlx5_suspend, + .resume = mlx5_resume, .shutdown = shutdown, .err_handler = &mlx5_err_handler, .sriov_configure = mlx5_core_sriov_configure,