Skip to content

Commit af5a7e9

Browse files
committed
Merge tag 'hyperv-next-signed' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull Hyper-V updates from Sasha Levin: - first round of vmbus hibernation support (Dexuan Cui) - remove dependencies on PAGE_SIZE (Maya Nakamura) - move the hyper-v tools/ code into the tools build system (Andy Shevchenko) - hyper-v balloon cleanups (Dexuan Cui) * tag 'hyperv-next-signed' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: Drivers: hv: vmbus: Resume after fixing up old primary channels Drivers: hv: vmbus: Suspend after cleaning up hv_sock and sub channels Drivers: hv: vmbus: Clean up hv_sock channels by force upon suspend Drivers: hv: vmbus: Suspend/resume the vmbus itself for hibernation Drivers: hv: vmbus: Ignore the offers when resuming from hibernation Drivers: hv: vmbus: Implement suspend/resume for VSC drivers for hibernation Drivers: hv: vmbus: Add a helper function is_sub_channel() Drivers: hv: vmbus: Suspend/resume the synic for hibernation Drivers: hv: vmbus: Break out synic enable and disable operations HID: hv: Remove dependencies on PAGE_SIZE for ring buffer Tools: hv: move to tools buildsystem hv_balloon: Reorganize the probe function hv_balloon: Use a static page for the balloon_up send buffer
2 parents 0b36c9e + d8bd2d4 commit af5a7e9

10 files changed

Lines changed: 613 additions & 134 deletions

File tree

‎drivers/hid/hid-hyperv.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ struct synthhid_input_report {
104104

105105
#pragma pack(pop)
106106

107-
#define INPUTVSC_SEND_RING_BUFFER_SIZE (10*PAGE_SIZE)
108-
#define INPUTVSC_RECV_RING_BUFFER_SIZE (10*PAGE_SIZE)
107+
#define INPUTVSC_SEND_RING_BUFFER_SIZE (40 * 1024)
108+
#define INPUTVSC_RECV_RING_BUFFER_SIZE (40 * 1024)
109109

110110

111111
enum pipe_prot_msg_type {

‎drivers/hv/channel_mgmt.c‎

Lines changed: 144 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,15 @@ void hv_process_channel_removal(struct vmbus_channel *channel)
407407
cpumask_clear_cpu(channel->target_cpu,
408408
&primary_channel->alloced_cpus_in_node);
409409

410-
vmbus_release_relid(channel->offermsg.child_relid);
410+
/*
411+
* Upon suspend, an in-use hv_sock channel is marked as "rescinded" and
412+
* the relid is invalidated; after hibernation, when the user-space app
413+
* destroys the channel, the relid is INVALID_RELID, and in this case
414+
* it's unnecessary and unsafe to release the old relid, since the same
415+
* relid can refer to a completely different channel now.
416+
*/
417+
if (channel->offermsg.child_relid != INVALID_RELID)
418+
vmbus_release_relid(channel->offermsg.child_relid);
411419

412420
free_channel(channel);
413421
}
@@ -545,6 +553,10 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
545553

546554
mutex_lock(&vmbus_connection.channel_mutex);
547555

556+
/* Remember the channels that should be cleaned up upon suspend. */
557+
if (is_hvsock_channel(newchannel) || is_sub_channel(newchannel))
558+
atomic_inc(&vmbus_connection.nr_chan_close_on_suspend);
559+
548560
/*
549561
* Now that we have acquired the channel_mutex,
550562
* we can release the potentially racing rescind thread.
@@ -847,19 +859,126 @@ void vmbus_initiate_unload(bool crash)
847859
vmbus_wait_for_unload();
848860
}
849861

862+
static void check_ready_for_resume_event(void)
863+
{
864+
/*
865+
* If all the old primary channels have been fixed up, then it's safe
866+
* to resume.
867+
*/
868+
if (atomic_dec_and_test(&vmbus_connection.nr_chan_fixup_on_resume))
869+
complete(&vmbus_connection.ready_for_resume_event);
870+
}
871+
872+
static void vmbus_setup_channel_state(struct vmbus_channel *channel,
873+
struct vmbus_channel_offer_channel *offer)
874+
{
875+
/*
876+
* Setup state for signalling the host.
877+
*/
878+
channel->sig_event = VMBUS_EVENT_CONNECTION_ID;
879+
880+
if (vmbus_proto_version != VERSION_WS2008) {
881+
channel->is_dedicated_interrupt =
882+
(offer->is_dedicated_interrupt != 0);
883+
channel->sig_event = offer->connection_id;
884+
}
885+
886+
memcpy(&channel->offermsg, offer,
887+
sizeof(struct vmbus_channel_offer_channel));
888+
channel->monitor_grp = (u8)offer->monitorid / 32;
889+
channel->monitor_bit = (u8)offer->monitorid % 32;
890+
}
891+
892+
/*
893+
* find_primary_channel_by_offer - Get the channel object given the new offer.
894+
* This is only used in the resume path of hibernation.
895+
*/
896+
static struct vmbus_channel *
897+
find_primary_channel_by_offer(const struct vmbus_channel_offer_channel *offer)
898+
{
899+
struct vmbus_channel *channel = NULL, *iter;
900+
const guid_t *inst1, *inst2;
901+
902+
/* Ignore sub-channel offers. */
903+
if (offer->offer.sub_channel_index != 0)
904+
return NULL;
905+
906+
mutex_lock(&vmbus_connection.channel_mutex);
907+
908+
list_for_each_entry(iter, &vmbus_connection.chn_list, listentry) {
909+
inst1 = &iter->offermsg.offer.if_instance;
910+
inst2 = &offer->offer.if_instance;
911+
912+
if (guid_equal(inst1, inst2)) {
913+
channel = iter;
914+
break;
915+
}
916+
}
917+
918+
mutex_unlock(&vmbus_connection.channel_mutex);
919+
920+
return channel;
921+
}
922+
850923
/*
851924
* vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
852925
*
853926
*/
854927
static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
855928
{
856929
struct vmbus_channel_offer_channel *offer;
857-
struct vmbus_channel *newchannel;
930+
struct vmbus_channel *oldchannel, *newchannel;
931+
size_t offer_sz;
858932

859933
offer = (struct vmbus_channel_offer_channel *)hdr;
860934

861935
trace_vmbus_onoffer(offer);
862936

937+
oldchannel = find_primary_channel_by_offer(offer);
938+
939+
if (oldchannel != NULL) {
940+
atomic_dec(&vmbus_connection.offer_in_progress);
941+
942+
/*
943+
* We're resuming from hibernation: all the sub-channel and
944+
* hv_sock channels we had before the hibernation should have
945+
* been cleaned up, and now we must be seeing a re-offered
946+
* primary channel that we had before the hibernation.
947+
*/
948+
949+
WARN_ON(oldchannel->offermsg.child_relid != INVALID_RELID);
950+
/* Fix up the relid. */
951+
oldchannel->offermsg.child_relid = offer->child_relid;
952+
953+
offer_sz = sizeof(*offer);
954+
if (memcmp(offer, &oldchannel->offermsg, offer_sz) == 0) {
955+
check_ready_for_resume_event();
956+
return;
957+
}
958+
959+
/*
960+
* This is not an error, since the host can also change the
961+
* other field(s) of the offer, e.g. on WS RS5 (Build 17763),
962+
* the offer->connection_id of the Mellanox VF vmbus device
963+
* can change when the host reoffers the device upon resume.
964+
*/
965+
pr_debug("vmbus offer changed: relid=%d\n",
966+
offer->child_relid);
967+
968+
print_hex_dump_debug("Old vmbus offer: ", DUMP_PREFIX_OFFSET,
969+
16, 4, &oldchannel->offermsg, offer_sz,
970+
false);
971+
print_hex_dump_debug("New vmbus offer: ", DUMP_PREFIX_OFFSET,
972+
16, 4, offer, offer_sz, false);
973+
974+
/* Fix up the old channel. */
975+
vmbus_setup_channel_state(oldchannel, offer);
976+
977+
check_ready_for_resume_event();
978+
979+
return;
980+
}
981+
863982
/* Allocate the channel object and save this offer. */
864983
newchannel = alloc_channel();
865984
if (!newchannel) {
@@ -869,25 +988,21 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
869988
return;
870989
}
871990

872-
/*
873-
* Setup state for signalling the host.
874-
*/
875-
newchannel->sig_event = VMBUS_EVENT_CONNECTION_ID;
876-
877-
if (vmbus_proto_version != VERSION_WS2008) {
878-
newchannel->is_dedicated_interrupt =
879-
(offer->is_dedicated_interrupt != 0);
880-
newchannel->sig_event = offer->connection_id;
881-
}
882-
883-
memcpy(&newchannel->offermsg, offer,
884-
sizeof(struct vmbus_channel_offer_channel));
885-
newchannel->monitor_grp = (u8)offer->monitorid / 32;
886-
newchannel->monitor_bit = (u8)offer->monitorid % 32;
991+
vmbus_setup_channel_state(newchannel, offer);
887992

888993
vmbus_process_offer(newchannel);
889994
}
890995

996+
static void check_ready_for_suspend_event(void)
997+
{
998+
/*
999+
* If all the sub-channels or hv_sock channels have been cleaned up,
1000+
* then it's safe to suspend.
1001+
*/
1002+
if (atomic_dec_and_test(&vmbus_connection.nr_chan_close_on_suspend))
1003+
complete(&vmbus_connection.ready_for_suspend_event);
1004+
}
1005+
8911006
/*
8921007
* vmbus_onoffer_rescind - Rescind offer handler.
8931008
*
@@ -898,6 +1013,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
8981013
struct vmbus_channel_rescind_offer *rescind;
8991014
struct vmbus_channel *channel;
9001015
struct device *dev;
1016+
bool clean_up_chan_for_suspend;
9011017

9021018
rescind = (struct vmbus_channel_rescind_offer *)hdr;
9031019

@@ -937,6 +1053,8 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
9371053
return;
9381054
}
9391055

1056+
clean_up_chan_for_suspend = is_hvsock_channel(channel) ||
1057+
is_sub_channel(channel);
9401058
/*
9411059
* Before setting channel->rescind in vmbus_rescind_cleanup(), we
9421060
* should make sure the channel callback is not running any more.
@@ -962,6 +1080,10 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
9621080
if (channel->device_obj) {
9631081
if (channel->chn_rescind_callback) {
9641082
channel->chn_rescind_callback(channel);
1083+
1084+
if (clean_up_chan_for_suspend)
1085+
check_ready_for_suspend_event();
1086+
9651087
return;
9661088
}
9671089
/*
@@ -994,6 +1116,11 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
9941116
}
9951117
mutex_unlock(&vmbus_connection.channel_mutex);
9961118
}
1119+
1120+
/* The "channel" may have been freed. Do not access it any longer. */
1121+
1122+
if (clean_up_chan_for_suspend)
1123+
check_ready_for_suspend_event();
9971124
}
9981125

9991126
void vmbus_hvsock_device_unregister(struct vmbus_channel *channel)

‎drivers/hv/connection.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
struct vmbus_connection vmbus_connection = {
2727
.conn_state = DISCONNECTED,
2828
.next_gpadl_handle = ATOMIC_INIT(0xE1E10),
29+
30+
.ready_for_suspend_event= COMPLETION_INITIALIZER(
31+
vmbus_connection.ready_for_suspend_event),
32+
.ready_for_resume_event = COMPLETION_INITIALIZER(
33+
vmbus_connection.ready_for_resume_event),
2934
};
3035
EXPORT_SYMBOL_GPL(vmbus_connection);
3136

@@ -59,8 +64,7 @@ static __u32 vmbus_get_next_version(__u32 current_version)
5964
}
6065
}
6166

62-
static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
63-
__u32 version)
67+
int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
6468
{
6569
int ret = 0;
6670
unsigned int cur_cpu;

‎drivers/hv/hv.c‎

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void hv_synic_free(void)
154154
* retrieve the initialized message and event pages. Otherwise, we create and
155155
* initialize the message and event pages.
156156
*/
157-
int hv_synic_init(unsigned int cpu)
157+
void hv_synic_enable_regs(unsigned int cpu)
158158
{
159159
struct hv_per_cpu_context *hv_cpu
160160
= per_cpu_ptr(hv_context.cpu_context, cpu);
@@ -196,6 +196,11 @@ int hv_synic_init(unsigned int cpu)
196196
sctrl.enable = 1;
197197

198198
hv_set_synic_state(sctrl.as_uint64);
199+
}
200+
201+
int hv_synic_init(unsigned int cpu)
202+
{
203+
hv_synic_enable_regs(cpu);
199204

200205
hv_stimer_init(cpu);
201206

@@ -205,20 +210,45 @@ int hv_synic_init(unsigned int cpu)
205210
/*
206211
* hv_synic_cleanup - Cleanup routine for hv_synic_init().
207212
*/
208-
int hv_synic_cleanup(unsigned int cpu)
213+
void hv_synic_disable_regs(unsigned int cpu)
209214
{
210215
union hv_synic_sint shared_sint;
211216
union hv_synic_simp simp;
212217
union hv_synic_siefp siefp;
213218
union hv_synic_scontrol sctrl;
219+
220+
hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
221+
222+
shared_sint.masked = 1;
223+
224+
/* Need to correctly cleanup in the case of SMP!!! */
225+
/* Disable the interrupt */
226+
hv_set_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
227+
228+
hv_get_simp(simp.as_uint64);
229+
simp.simp_enabled = 0;
230+
simp.base_simp_gpa = 0;
231+
232+
hv_set_simp(simp.as_uint64);
233+
234+
hv_get_siefp(siefp.as_uint64);
235+
siefp.siefp_enabled = 0;
236+
siefp.base_siefp_gpa = 0;
237+
238+
hv_set_siefp(siefp.as_uint64);
239+
240+
/* Disable the global synic bit */
241+
hv_get_synic_state(sctrl.as_uint64);
242+
sctrl.enable = 0;
243+
hv_set_synic_state(sctrl.as_uint64);
244+
}
245+
246+
int hv_synic_cleanup(unsigned int cpu)
247+
{
214248
struct vmbus_channel *channel, *sc;
215249
bool channel_found = false;
216250
unsigned long flags;
217251

218-
hv_get_synic_state(sctrl.as_uint64);
219-
if (sctrl.enable != 1)
220-
return -EFAULT;
221-
222252
/*
223253
* Search for channels which are bound to the CPU we're about to
224254
* cleanup. In case we find one and vmbus is still connected we need to
@@ -249,29 +279,7 @@ int hv_synic_cleanup(unsigned int cpu)
249279

250280
hv_stimer_cleanup(cpu);
251281

252-
hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
253-
254-
shared_sint.masked = 1;
255-
256-
/* Need to correctly cleanup in the case of SMP!!! */
257-
/* Disable the interrupt */
258-
hv_set_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
259-
260-
hv_get_simp(simp.as_uint64);
261-
simp.simp_enabled = 0;
262-
simp.base_simp_gpa = 0;
263-
264-
hv_set_simp(simp.as_uint64);
265-
266-
hv_get_siefp(siefp.as_uint64);
267-
siefp.siefp_enabled = 0;
268-
siefp.base_siefp_gpa = 0;
269-
270-
hv_set_siefp(siefp.as_uint64);
271-
272-
/* Disable the global synic bit */
273-
sctrl.enable = 0;
274-
hv_set_synic_state(sctrl.as_uint64);
282+
hv_synic_disable_regs(cpu);
275283

276284
return 0;
277285
}

0 commit comments

Comments
 (0)