| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * An implementation of host initiated guest snapshot. |
|---|
| 3 | 4 | * |
|---|
| 4 | | - * |
|---|
| 5 | 5 | * Copyright (C) 2013, Microsoft, Inc. |
|---|
| 6 | 6 | * Author : K. Y. Srinivasan <kys@microsoft.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 9 | | - * under the terms of the GNU General Public License version 2 as published |
|---|
| 10 | | - * by the Free Software Foundation. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 13 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | | - * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
|---|
| 15 | | - * NON INFRINGEMENT. See the GNU General Public License for more |
|---|
| 16 | | - * details. |
|---|
| 17 | | - * |
|---|
| 18 | 7 | */ |
|---|
| 19 | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 20 | 9 | |
|---|
| .. | .. |
|---|
| 23 | 12 | #include <linux/connector.h> |
|---|
| 24 | 13 | #include <linux/workqueue.h> |
|---|
| 25 | 14 | #include <linux/hyperv.h> |
|---|
| 15 | +#include <asm/hyperv-tlfs.h> |
|---|
| 26 | 16 | |
|---|
| 27 | 17 | #include "hyperv_vmbus.h" |
|---|
| 28 | 18 | #include "hv_utils_transport.h" |
|---|
| .. | .. |
|---|
| 90 | 80 | { |
|---|
| 91 | 81 | /* Transaction is finished, reset the state here to avoid races. */ |
|---|
| 92 | 82 | vss_transaction.state = HVUTIL_READY; |
|---|
| 93 | | - hv_vss_onchannelcallback(channel); |
|---|
| 83 | + tasklet_schedule(&((struct vmbus_channel *)channel)->callback_event); |
|---|
| 94 | 84 | } |
|---|
| 95 | 85 | |
|---|
| 96 | 86 | /* |
|---|
| .. | .. |
|---|
| 308 | 298 | if (vss_transaction.state > HVUTIL_READY) |
|---|
| 309 | 299 | return; |
|---|
| 310 | 300 | |
|---|
| 311 | | - vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen, |
|---|
| 301 | + vmbus_recvpacket(channel, recv_buffer, HV_HYP_PAGE_SIZE * 2, &recvlen, |
|---|
| 312 | 302 | &requestid); |
|---|
| 313 | 303 | |
|---|
| 314 | 304 | if (recvlen > 0) { |
|---|
| .. | .. |
|---|
| 389 | 379 | return 0; |
|---|
| 390 | 380 | } |
|---|
| 391 | 381 | |
|---|
| 382 | +static void hv_vss_cancel_work(void) |
|---|
| 383 | +{ |
|---|
| 384 | + cancel_delayed_work_sync(&vss_timeout_work); |
|---|
| 385 | + cancel_work_sync(&vss_handle_request_work); |
|---|
| 386 | +} |
|---|
| 387 | + |
|---|
| 388 | +int hv_vss_pre_suspend(void) |
|---|
| 389 | +{ |
|---|
| 390 | + struct vmbus_channel *channel = vss_transaction.recv_channel; |
|---|
| 391 | + struct hv_vss_msg *vss_msg; |
|---|
| 392 | + |
|---|
| 393 | + /* |
|---|
| 394 | + * Fake a THAW message for the user space daemon in case the daemon |
|---|
| 395 | + * has frozen the file systems. It doesn't matter if there is already |
|---|
| 396 | + * a message pending to be delivered to the user space since we force |
|---|
| 397 | + * vss_transaction.state to be HVUTIL_READY, so the user space daemon's |
|---|
| 398 | + * write() will fail with EINVAL (see vss_on_msg()), and the daemon |
|---|
| 399 | + * will reset the device by closing and re-opening it. |
|---|
| 400 | + */ |
|---|
| 401 | + vss_msg = kzalloc(sizeof(*vss_msg), GFP_KERNEL); |
|---|
| 402 | + if (!vss_msg) |
|---|
| 403 | + return -ENOMEM; |
|---|
| 404 | + |
|---|
| 405 | + tasklet_disable(&channel->callback_event); |
|---|
| 406 | + |
|---|
| 407 | + vss_msg->vss_hdr.operation = VSS_OP_THAW; |
|---|
| 408 | + |
|---|
| 409 | + /* Cancel any possible pending work. */ |
|---|
| 410 | + hv_vss_cancel_work(); |
|---|
| 411 | + |
|---|
| 412 | + /* We don't care about the return value. */ |
|---|
| 413 | + hvutil_transport_send(hvt, vss_msg, sizeof(*vss_msg), NULL); |
|---|
| 414 | + |
|---|
| 415 | + kfree(vss_msg); |
|---|
| 416 | + |
|---|
| 417 | + vss_transaction.state = HVUTIL_READY; |
|---|
| 418 | + |
|---|
| 419 | + /* tasklet_enable() will be called in hv_vss_pre_resume(). */ |
|---|
| 420 | + return 0; |
|---|
| 421 | +} |
|---|
| 422 | + |
|---|
| 423 | +int hv_vss_pre_resume(void) |
|---|
| 424 | +{ |
|---|
| 425 | + struct vmbus_channel *channel = vss_transaction.recv_channel; |
|---|
| 426 | + |
|---|
| 427 | + tasklet_enable(&channel->callback_event); |
|---|
| 428 | + |
|---|
| 429 | + return 0; |
|---|
| 430 | +} |
|---|
| 431 | + |
|---|
| 392 | 432 | void hv_vss_deinit(void) |
|---|
| 393 | 433 | { |
|---|
| 394 | 434 | vss_transaction.state = HVUTIL_DEVICE_DYING; |
|---|
| 395 | | - cancel_delayed_work_sync(&vss_timeout_work); |
|---|
| 396 | | - cancel_work_sync(&vss_handle_request_work); |
|---|
| 435 | + |
|---|
| 436 | + hv_vss_cancel_work(); |
|---|
| 437 | + |
|---|
| 397 | 438 | hvutil_transport_destroy(hvt); |
|---|
| 398 | 439 | } |
|---|