Commit 68747bc0 authored by Long Li's avatar Long Li Committed by Greg Kroah-Hartman

HV: properly delay KVP packets when negotiation is in progress

commit a3ade8cc upstream.

The host may send multiple negotiation packets
(due to timeout) before the KVP user-mode daemon
is connected. KVP user-mode daemon is connected.
We need to defer processing those packets
until the daemon is negotiated and connected.
It's okay for guest to respond
to all negotiation packets.

In addition, the host may send multiple staged
KVP requests as soon as negotiation is done.
We need to properly process those packets using one
tasklet for exclusive access to ring buffer.

This patch is based on the work of
Nick Meier <>.

The above is the original changelog of
a3ade8cc ("HV: properly delay KVP packets when negotiation is in progress"

Here I re-worked the original patch because the mainline version
can't work for the linux-4.4.y branch, on which channel->callback_event
doesn't exist yet. In the mainline, channel->callback_event was added by:
631e63a9 ("vmbus: change to per channel tasklet"). Here we don't want
to backport it to v4.4, as it requires extra supporting changes and fixes,
which are unnecessary as to the KVP bug we're trying to resolve.

NOTE: before this patch is used, we should cherry-pick the other related
3 patches from the mainline first:

The background of this backport request is that: recently Wang Jian reported
some KVP issues:
e.g. the /var/lib/hyperv/.kvp_pool_* files can not be updated, and sometimes
if the hv_kvp_daemon doesn't timely start, the host may not be able to query
the VM's IP address via KVP.
Reported-by: default avatarWang Jian <>
Tested-by: default avatarWang Jian <>
Signed-off-by: default avatarDexuan Cui <>
Signed-off-by: default avatarLong Li <>
Signed-off-by: default avatarK. Y. Srinivasan <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 7dd55897
......@@ -616,21 +616,22 @@ void hv_kvp_onchannelcallback(void *context)
if (host_negotiatied == NEGO_NOT_STARTED &&
kvp_transaction.state < HVUTIL_READY) {
if (kvp_transaction.state < HVUTIL_READY) {
* If userspace daemon is not connected and host is asking
* us to negotiate we need to delay to not lose messages.
* This is important for Failover IP setting.
host_negotiatied = NEGO_IN_PROGRESS;
if (host_negotiatied == NEGO_NOT_STARTED) {
host_negotiatied = NEGO_IN_PROGRESS;
if (kvp_transaction.state > HVUTIL_READY)
vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 4, &recvlen,
......@@ -707,6 +708,8 @@ void hv_kvp_onchannelcallback(void *context)
host_negotiatied = NEGO_FINISHED;
goto recheck;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment