Skip to content

Commit 0e0073e

Browse files
committed
Merge tag 'hyperv-next-signed-20221009' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull hyperv updates from Wei Liu: - Remove unnecessary delay while probing for VMBus (Stanislav Kinsburskiy) - Optimize vmbus_on_event (Saurabh Sengar) - Fix a race in Hyper-V DRM driver (Saurabh Sengar) - Miscellaneous clean-up patches from various people * tag 'hyperv-next-signed-20221009' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: x86/hyperv: Replace kmap() with kmap_local_page() drm/hyperv: Add ratelimit on error message hyperv: simplify and rename generate_guest_id Drivers: hv: vmbus: Split memcpy of flex-array scsi: storvsc: remove an extraneous "to" in a comment Drivers: hv: vmbus: Don't wait for the ACPI device upon initialization Drivers: hv: vmbus: Use PCI_VENDOR_ID_MICROSOFT for better discoverability Drivers: hv: vmbus: Fix kernel-doc drm/hyperv: Don't overwrite dirt_needed value set by host Drivers: hv: vmbus: Optimize vmbus_on_event
2 parents aa512c1 + 154fb14 commit 0e0073e

File tree

8 files changed

+40
-45
lines changed

8 files changed

+40
-45
lines changed

arch/arm64/hyperv/mshyperv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int __init hyperv_init(void)
3838
return 0;
3939

4040
/* Setup the guest ID */
41-
guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
41+
guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
4242
hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id);
4343

4444
/* Get the features and hints from Hyper-V */

arch/x86/hyperv/hv_init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ void __init hyperv_init(void)
426426
* 1. Register the guest ID
427427
* 2. Enable the hypercall and register the hypercall page
428428
*/
429-
guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
429+
guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
430430
wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
431431

432432
/* Hyper-V requires to write guest os id via ghcb in SNP IVM. */
@@ -459,13 +459,13 @@ void __init hyperv_init(void)
459459
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
460460

461461
pg = vmalloc_to_page(hv_hypercall_pg);
462-
dst = kmap(pg);
462+
dst = kmap_local_page(pg);
463463
src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE,
464464
MEMREMAP_WB);
465465
BUG_ON(!(src && dst));
466466
memcpy(dst, src, HV_HYP_PAGE_SIZE);
467467
memunmap(src);
468-
kunmap(pg);
468+
kunmap_local(dst);
469469
} else {
470470
hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
471471
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);

drivers/gpu/drm/hyperv/hyperv_drm_drv.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ static int hyperv_vmbus_probe(struct hv_device *hdev,
142142
if (ret)
143143
drm_warn(dev, "Failed to update vram location.\n");
144144

145-
hv->dirt_needed = true;
146-
147145
ret = hyperv_mode_config_init(hv);
148146
if (ret)
149147
goto err_free_mmio;

drivers/gpu/drm/hyperv/hyperv_drm_proto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static inline int hyperv_sendpacket(struct hv_device *hdev, struct synthvid_msg
208208
VM_PKT_DATA_INBAND, 0);
209209

210210
if (ret)
211-
drm_err(&hv->dev, "Unable to send packet via vmbus\n");
211+
drm_err_ratelimited(&hv->dev, "Unable to send packet via vmbus; error %d\n", ret);
212212

213213
return ret;
214214
}

drivers/hv/connection.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -431,34 +431,29 @@ struct vmbus_channel *relid2channel(u32 relid)
431431
void vmbus_on_event(unsigned long data)
432432
{
433433
struct vmbus_channel *channel = (void *) data;
434-
unsigned long time_limit = jiffies + 2;
434+
void (*callback_fn)(void *context);
435435

436436
trace_vmbus_on_event(channel);
437437

438438
hv_debug_delay_test(channel, INTERRUPT_DELAY);
439-
do {
440-
void (*callback_fn)(void *);
441439

442-
/* A channel once created is persistent even when
443-
* there is no driver handling the device. An
444-
* unloading driver sets the onchannel_callback to NULL.
445-
*/
446-
callback_fn = READ_ONCE(channel->onchannel_callback);
447-
if (unlikely(callback_fn == NULL))
448-
return;
449-
450-
(*callback_fn)(channel->channel_callback_context);
440+
/* A channel once created is persistent even when
441+
* there is no driver handling the device. An
442+
* unloading driver sets the onchannel_callback to NULL.
443+
*/
444+
callback_fn = READ_ONCE(channel->onchannel_callback);
445+
if (unlikely(!callback_fn))
446+
return;
451447

452-
if (channel->callback_mode != HV_CALL_BATCHED)
453-
return;
448+
(*callback_fn)(channel->channel_callback_context);
454449

455-
if (likely(hv_end_read(&channel->inbound) == 0))
456-
return;
450+
if (channel->callback_mode != HV_CALL_BATCHED)
451+
return;
457452

458-
hv_begin_read(&channel->inbound);
459-
} while (likely(time_before(jiffies, time_limit)));
453+
if (likely(hv_end_read(&channel->inbound) == 0))
454+
return;
460455

461-
/* The time limit (2 jiffies) has been reached */
456+
hv_begin_read(&channel->inbound);
462457
tasklet_schedule(&channel->callback_event);
463458
}
464459

drivers/hv/vmbus_drv.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ struct vmbus_dynid {
4646

4747
static struct acpi_device *hv_acpi_dev;
4848

49-
static struct completion probe_event;
50-
5149
static int hyperv_cpuhp_online;
5250

5351
static void *hv_panic_page;
@@ -1132,7 +1130,8 @@ void vmbus_on_msg_dpc(unsigned long data)
11321130
return;
11331131

11341132
INIT_WORK(&ctx->work, vmbus_onmessage_work);
1135-
memcpy(&ctx->msg, &msg_copy, sizeof(msg->header) + payload_size);
1133+
ctx->msg.header = msg_copy.header;
1134+
memcpy(&ctx->msg.payload, msg_copy.u.payload, payload_size);
11361135

11371136
/*
11381137
* The host can generate a rescind message while we
@@ -1573,7 +1572,7 @@ static int vmbus_bus_init(void)
15731572
}
15741573

15751574
/**
1576-
* __vmbus_child_driver_register() - Register a vmbus's driver
1575+
* __vmbus_driver_register() - Register a vmbus's driver
15771576
* @hv_driver: Pointer to driver structure you want to register
15781577
* @owner: owner module of the drv
15791578
* @mod_name: module name string
@@ -2052,7 +2051,7 @@ struct hv_device *vmbus_device_create(const guid_t *type,
20522051
child_device_obj->channel = channel;
20532052
guid_copy(&child_device_obj->dev_type, type);
20542053
guid_copy(&child_device_obj->dev_instance, instance);
2055-
child_device_obj->vendor_id = 0x1414; /* MSFT vendor ID */
2054+
child_device_obj->vendor_id = PCI_VENDOR_ID_MICROSOFT;
20562055

20572056
return child_device_obj;
20582057
}
@@ -2468,7 +2467,6 @@ static int vmbus_acpi_add(struct acpi_device *device)
24682467
ret_val = 0;
24692468

24702469
acpi_walk_err:
2471-
complete(&probe_event);
24722470
if (ret_val)
24732471
vmbus_acpi_remove(device);
24742472
return ret_val;
@@ -2647,6 +2645,7 @@ static struct acpi_driver vmbus_acpi_driver = {
26472645
.remove = vmbus_acpi_remove,
26482646
},
26492647
.drv.pm = &vmbus_bus_pm,
2648+
.drv.probe_type = PROBE_FORCE_SYNCHRONOUS,
26502649
};
26512650

26522651
static void hv_kexec_handler(void)
@@ -2719,16 +2718,14 @@ static struct syscore_ops hv_synic_syscore_ops = {
27192718

27202719
static int __init hv_acpi_init(void)
27212720
{
2722-
int ret, t;
2721+
int ret;
27232722

27242723
if (!hv_is_hyperv_initialized())
27252724
return -ENODEV;
27262725

27272726
if (hv_root_partition)
27282727
return 0;
27292728

2730-
init_completion(&probe_event);
2731-
27322729
/*
27332730
* Get ACPI resources first.
27342731
*/
@@ -2737,9 +2734,8 @@ static int __init hv_acpi_init(void)
27372734
if (ret)
27382735
return ret;
27392736

2740-
t = wait_for_completion_timeout(&probe_event, 5*HZ);
2741-
if (t == 0) {
2742-
ret = -ETIMEDOUT;
2737+
if (!hv_acpi_dev) {
2738+
ret = -ENODEV;
27432739
goto cleanup;
27442740
}
27452741

drivers/scsi/storvsc_drv.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
#define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
6161
#define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
6262

63+
/* channel callback timeout in ms */
64+
#define CALLBACK_TIMEOUT 2
65+
6366
/* Packet structure describing virtual storage requests. */
6467
enum vstor_packet_operation {
6568
VSTOR_OPERATION_COMPLETE_IO = 1,
@@ -1204,6 +1207,7 @@ static void storvsc_on_channel_callback(void *context)
12041207
struct hv_device *device;
12051208
struct storvsc_device *stor_device;
12061209
struct Scsi_Host *shost;
1210+
unsigned long time_limit = jiffies + msecs_to_jiffies(CALLBACK_TIMEOUT);
12071211

12081212
if (channel->primary_channel != NULL)
12091213
device = channel->primary_channel->device_obj;
@@ -1224,6 +1228,11 @@ static void storvsc_on_channel_callback(void *context)
12241228
u32 minlen = rqst_id ? sizeof(struct vstor_packet) :
12251229
sizeof(enum vstor_packet_operation);
12261230

1231+
if (unlikely(time_after(jiffies, time_limit))) {
1232+
hv_pkt_iter_close(channel);
1233+
return;
1234+
}
1235+
12271236
if (pktlen < minlen) {
12281237
dev_err(&device->device,
12291238
"Invalid pkt: id=%llu, len=%u, minlen=%u\n",
@@ -2059,7 +2068,7 @@ static int storvsc_probe(struct hv_device *device,
20592068
err_out2:
20602069
/*
20612070
* Once we have connected with the host, we would need to
2062-
* to invoke storvsc_dev_remove() to rollback this state and
2071+
* invoke storvsc_dev_remove() to rollback this state and
20632072
* this call also frees up the stor_device; hence the jump around
20642073
* err_out1 label.
20652074
*/

include/asm-generic/mshyperv.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,12 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16 rep_count, u16 varhead_size,
105105
}
106106

107107
/* Generate the guest OS identifier as described in the Hyper-V TLFS */
108-
static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,
109-
__u64 d_info2)
108+
static inline u64 hv_generate_guest_id(u64 kernel_version)
110109
{
111-
__u64 guest_id = 0;
110+
u64 guest_id;
112111

113-
guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48);
114-
guest_id |= (d_info1 << 48);
112+
guest_id = (((u64)HV_LINUX_VENDOR_ID) << 48);
115113
guest_id |= (kernel_version << 16);
116-
guest_id |= d_info2;
117114

118115
return guest_id;
119116
}

0 commit comments

Comments
 (0)