Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964916AbcLTTMj (ORCPT ); Tue, 20 Dec 2016 14:12:39 -0500 Received: from mail-eopbgr10104.outbound.protection.outlook.com ([40.107.1.104]:14991 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964852AbcLTTM3 (ORCPT ); Tue, 20 Dec 2016 14:12:29 -0500 X-Greylist: delayed 11715 seconds by postgrey-1.27 at vger.kernel.org; Tue, 20 Dec 2016 14:12:14 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; From: Roman Kagan To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , "K. Y. Srinivasan" , Vitaly Kuznetsov CC: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Haiyang Zhang , , , , "Denis V . Lunev" , Roman Kagan Subject: [PATCH 09/15] hyperv: unify Hyper-V msr definitions Date: Tue, 20 Dec 2016 18:55:56 +0300 Message-ID: <20161220155602.6298-10-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161220155602.6298-1-rkagan@virtuozzo.com> References: <20161220155602.6298-1-rkagan@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM4PR01CA0030.eurprd01.prod.exchangelabs.com (10.164.74.168) To VI1PR0802MB2478.eurprd08.prod.outlook.com (10.175.26.21) X-MS-Office365-Filtering-Correlation-Id: a15d4d73-c69d-4502-6e99-08d428f0d06f X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0802MB2478; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;3:owRPDvZ9kxehO3C1NHVPhTnKFt8VLuIktuSixzo1bOwYo0U+w/G/HqdGD3Y1T3ztQRZimS+tATu39PlenC6KwpMAIaa/ZIctgM1/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Hvi7EzuHCMICafAbRJ0WMP6zPnRHNlPxllKeDYFQQ36VsZyd4hIZEog1tqZV+uh7u04g0wESQq5LHVFQE/WXYEkriOqKzdxc6CKnzSGgSBa5uqlAABtBE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123555025)(20161123560025)(20161123558021)(20161123562025)(6072148);SRVR:VI1PR0802MB2478;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0802MB2478; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;4:7GwP15Llw2LBaYAuWkfFE+Nxo27eQDSkbT8duTALrkdj/O4290GfGiY5Ix3nB0suoAIaOsWMNp3fzHQjAgIuVqTzC4lRe5aD48FhOPitaRIZ9wBrnh4tgdKBJ+nYnlgQtfipzqg7YVVw5NYafai3KLX3y6tiWdIxFXj5HlwFUEaUTqy9PzGoloH5NmNhBJ164wYXICJ/AO/fF/0QvUoGDfzkU276kG55ImVYvf4KtPcOuyVtFDXZRRCE6zFjw4rRP66Uk5x+YDInoyEPF+lkRhQL/cjJFGQIUzuzfId8N7nTBaQn6YR16uXWY9CHHt9+kD4dGruIyysfQHebvo/+H8rBSrtNvGLEe8//H9/18sfDA2s2igPcInRb1kxzksD+++KbHZBCQ+OpB/IunE1dJV+/I+Q8cO/yF/xHcaR9KoiWjBEn/nL2CHaOZlCMNSyS/2ls78/tZXBM8+QWaPGmln681OgMXztSBXvAwO3GRevqmcQiDfT4PM27lWK18L49roiRe9FgFkb+xBxA4vAvAxP9qudmNHq3z7/GOxN8Szwf+LTw9o5teJRpLYLVcvPuTmZoFBEJQeRf5OOZkuLgqr4zaMLp7HA3Pg5KwlDnQRk= X-Forefront-PRVS: 0162ACCC24 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(199003)(189002)(97736004)(189998001)(101416001)(5001770100001)(4001430100002)(5003940100001)(36756003)(81166006)(47776003)(50986999)(66066001)(1511001)(2950100002)(50466002)(76176999)(5660300001)(81156014)(2906002)(8666005)(305945005)(69596002)(48376002)(7736002)(92566002)(7416002)(106356001)(53416004)(25786008)(6116002)(105586002)(6486002)(2421001)(6506006)(1076002)(3846002)(86362001)(4326007)(68736007)(8676002)(50226002)(42186005)(107886002)(2561002)(38730400001)(6512006)(33646002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0802MB2478;H:rkaganb.sw.ru;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR0802MB2478;23:e4zJrET2Uh6m/eJWoojA6Cte/zvDYBX8SwUFcO0?= =?us-ascii?Q?HS+uK2M+6Hgb7sCgs28GleZStrLXMUlC5cIVMD0IgJcGY7pfPXQFh6OOKZea?= =?us-ascii?Q?NacOJ++SMIRa45hZ+iwcwGCKTsZbPfPH/ab5OL/i6/a/W8i/DO5MU7ERcmIZ?= =?us-ascii?Q?IjwUCnmSX+buzv6921TidtxxnERZToWd0Nwf/6xfZjszjXyItIOcQraUHxrL?= =?us-ascii?Q?tDl9ydPYYMGVhhwyRj9cPev787sY/icYaBphPi5wM4ArJmG/dxZ4D4YE77n2?= =?us-ascii?Q?7DlKwzvffdBgMG408+JklHuUhc6Y3kG/El2tI2BPx1HokVaEoP1jxOjT8tXM?= =?us-ascii?Q?+iwkslMpFYIjxcWJY7piSGVoVWm3BZJnpdViivLgLW21FayF+FVK8vk0aZBm?= =?us-ascii?Q?gy1JmH5M8TF3rcTZUKtfa7EH2tN+DmfJ+iyx3tXDdj+8c0uq/rvmFn4tv2AM?= =?us-ascii?Q?uPSvtAgzcs0y++cykTcD8KW6nreEwmdVDP+tAx3ysU7KcGuVDAC1/NibpufT?= =?us-ascii?Q?yx8shMZWD6+ZfqbiOZ6OVoyBA05Kxp5mmqD9JTIYfgLamI+gW/gXZuoTOU+Y?= =?us-ascii?Q?Getbf7u8HHl3YzRuQP7PFDtaROuPN/0SalRss0+zkqA2BXjAhAepsKCSRbNF?= =?us-ascii?Q?oCSUpP9qbxMmmhtWQ08Nk9L5a7+ieKwCcnCrOZp2Zpw2qLMlC1mWm22q9Mqb?= =?us-ascii?Q?5NzScjl6SU0Lsjmf40pGn+PUzXSH98ln0TFJQlnWJyqO6ikJV2sCtq551unD?= =?us-ascii?Q?WVe+8OKPxaqDT9yK/1hiVJ2T9pGkcAYyTSSTCYlECSrV7grnjJeLAHypSh9V?= =?us-ascii?Q?XzV+414pdwFyoGablokrZJMmbFMEFovsAaj4vHcH5hGwk+ObCS7st5zyRd+Y?= =?us-ascii?Q?uE3mbgfpLFJW6FM7vSzC3bFFrRGNFMXZ38hU8hgUIU5b0LVyohpZKWe5n9cx?= =?us-ascii?Q?fsJUPUcwJmXxRdVo/O28/4bT7VVHbI0a+ufx8+OIdgMMPnya+WcyZVAbxI47?= =?us-ascii?Q?hrI0/yJI46kWux3mEmm6wmobTW7MJxwKi7FjT05eksB04D+TzV4GsfYdnLIu?= =?us-ascii?Q?rGY9t4DewiGvVfx+KLc8Qo9C18Y1xACA+tjyJg+XY8vG/SMvv0kZjXplTFTv?= =?us-ascii?Q?iKENt7VuSPEuifQMRJxnQotLmPJ4G742mIYQLSWkP9OfpfDgldChEW5L0b/T?= =?us-ascii?Q?cQX1tDOL8puSo5pPV3PnBRavf2TpERtgJHKwZEtBFCae1xIWaoPExjk1H6fU?= =?us-ascii?Q?ae55ROCEyEJW/G3TF9qo=3D?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR0802MB2478;6:nYcw2Rxz89mi+55MRo/uw4VxrEoM4oocropbFzIzVj73OoB9rSgGRDsQksPlCyUuebQkhRiPt1xOVdcWEcFFhNOexgtqbeWUVqy/TwehbnTJjqWnPmZzz2Bkhm7MlfcwIbLQNVOOltvIXifEnhGOfpzqBzX9nk7PtsIyhHlgh4JW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ly11vZ/hwhvdGwEePojBg==;20:NvfwjyuuwJFHHsJ81zpnZtV/ILfBDxtymjZeRGbW51xD6V3anIIkQPSpJEUao9ToEAdPpz6KG9GFDsL6v3jDzoAcbEPv3HMp/7OibESyFYuFT91YY1s8+LbunsPnor5ElVJtsZCFEPKe/u5L7Q4zeU5wn/ZlcgI/asr5Ssc4tg4=;23:f+7lyv1nvIaNNKRek3iVdofkKvaD39EiQ3wjkw3MYQ3Ps/vhQWwOqcjXcfdpX85rvH6r1W9C9sfArmCRcd3AAGOuQrVuG9IAIOyg/lYv1+UoJbZW55qil+NVN0zBeHpRKltFBRoz1a95WK79GZWSHA== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2016 15:56:51.0149 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2478 X-OriginatorOrg: virtuozzo.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10556 Lines: 379 Use the definitions already present in the uapi header. Besides, drop all bitfields for the msr values and use bitwise operations instead. Signed-off-by: Roman Kagan --- drivers/hv/hyperv_vmbus.h | 88 --------------------------- drivers/hv/hv.c | 150 ++++++++++++++++++---------------------------- 2 files changed, 59 insertions(+), 179 deletions(-) diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 7bf1b10..ac73832 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -94,63 +94,6 @@ struct hv_connection_info { }; }; -/* - * Timer configuration register. - */ -union hv_timer_config { - u64 as_uint64; - struct { - u64 enable:1; - u64 periodic:1; - u64 lazy:1; - u64 auto_enable:1; - u64 reserved_z0:12; - u64 sintx:4; - u64 reserved_z1:44; - }; -}; - -/* Define SynIC control register. */ -union hv_synic_scontrol { - u64 as_uint64; - struct { - u64 enable:1; - u64 reserved:63; - }; -}; - -/* Define synthetic interrupt source. */ -union hv_synic_sint { - u64 as_uint64; - struct { - u64 vector:8; - u64 reserved1:8; - u64 masked:1; - u64 auto_eoi:1; - u64 reserved2:46; - }; -}; - -/* Define the format of the SIMP register */ -union hv_synic_simp { - u64 as_uint64; - struct { - u64 simp_enabled:1; - u64 preserved:11; - u64 base_simp_gpa:52; - }; -}; - -/* Define the format of the SIEFP register */ -union hv_synic_siefp { - u64 as_uint64; - struct { - u64 siefp_enabled:1; - u64 preserved:11; - u64 base_siefp_gpa:52; - }; -}; - /* Definitions for the monitored notification facility */ union hv_monitor_trigger_group { u64 as_uint64; @@ -239,37 +182,6 @@ enum hv_guest_os_microsoft_ids { HVGUESTOS_MICROSOFT_WINDOWSCE = 0x05 }; -/* - * Declare the MSR used to identify the guest OS. - */ -#define HV_X64_MSR_GUEST_OS_ID 0x40000000 - -union hv_x64_msr_guest_os_id_contents { - u64 as_uint64; - struct { - u64 build_number:16; - u64 service_version:8; /* Service Pack, etc. */ - u64 minor_version:8; - u64 major_version:8; - u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */ - u64 vendor_id:16; /* enum hv_guest_os_vendor */ - }; -}; - -/* - * Declare the MSR used to setup pages used to communicate with the hypervisor. - */ -#define HV_X64_MSR_HYPERCALL 0x40000001 - -union hv_x64_msr_hypercall_contents { - u64 as_uint64; - struct { - u64 enable:1; - u64 reserved:11; - u64 guest_physical_address:52; - }; -}; - enum { VMBUS_MESSAGE_CONNECTION_ID = 1, diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index dddba07..7d2a3d1 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -181,7 +181,7 @@ static struct clocksource hyperv_cs_tsc = { int hv_init(void) { int max_leaf; - union hv_x64_msr_hypercall_contents hypercall_msr; + u64 hypercall_msr = 0; void *virtaddr = NULL; memset(hv_context.synic_event_page, 0, sizeof(void *) * NR_CPUS); @@ -206,30 +206,24 @@ int hv_init(void) hv_context.guestid = generate_guest_id(0, LINUX_VERSION_CODE, 0); wrmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid); - /* See if the hypercall page is already set */ - rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); - virtaddr = (void *)get_zeroed_page(GFP_KERNEL); if (!virtaddr || set_memory_x((unsigned long)virtaddr, 1)) goto cleanup; hv_context.hypercall_page = virtaddr; - hypercall_msr.enable = 1; - - hypercall_msr.guest_physical_address = - virt_to_phys(virtaddr) >> PAGE_SHIFT; - wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr); + hypercall_msr &= PAGE_MASK; + hypercall_msr = HV_X64_MSR_HYPERCALL_ENABLE | virt_to_phys(virtaddr); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr); /* Confirm that hypercall page did get setup. */ - hypercall_msr.as_uint64 = 0; - rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); - - if (!hypercall_msr.enable) + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr); + if (!(hypercall_msr & HV_X64_MSR_HYPERCALL_ENABLE)) goto cleanup; #ifdef CONFIG_X86_64 if (ms_hyperv.features & HV_X64_MSR_REFERENCE_TSC_AVAILABLE) { - union hv_x64_msr_hypercall_contents tsc_msr; + u64 tsc_msr; void *va_tsc; va_tsc = (void *)get_zeroed_page(GFP_KERNEL); @@ -237,21 +231,19 @@ int hv_init(void) goto cleanup; hv_context.tsc_page = va_tsc; - rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64); - - tsc_msr.enable = 1; - tsc_msr.guest_physical_address = - virt_to_phys(va_tsc) >> PAGE_SHIFT; - - wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64); + rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr); + tsc_msr &= PAGE_MASK; + tsc_msr |= HV_X64_MSR_TSC_REFERENCE_ENABLE | + virt_to_phys(va_tsc); + wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr); clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100); } #endif return 0; cleanup: - hypercall_msr.as_uint64 = 0; - wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + hypercall_msr &= ~HV_X64_MSR_HYPERCALL_ENABLE; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr); free_page((unsigned long)virtaddr); return -ENOTSUPP; @@ -264,13 +256,14 @@ int hv_init(void) */ void hv_cleanup(bool crash) { - union hv_x64_msr_hypercall_contents hypercall_msr; + u64 msr; /* Reset our OS id */ wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); - hypercall_msr.as_uint64 = 0; - wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + rdmsrl(HV_X64_MSR_HYPERCALL, msr); + msr &= ~HV_X64_MSR_HYPERCALL_ENABLE; + wrmsrl(HV_X64_MSR_HYPERCALL, msr); if (!crash) free_page((unsigned long)hv_context.hypercall_page); hv_context.hypercall_page = NULL; @@ -289,8 +282,9 @@ void hv_cleanup(bool crash) clocksource_unregister(&hyperv_cs_tsc); } - hypercall_msr.as_uint64 = 0; - wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64); + rdmsrl(HV_X64_MSR_REFERENCE_TSC, msr); + msr &= ~HV_X64_MSR_TSC_REFERENCE_ENABLE; + wrmsrl(HV_X64_MSR_REFERENCE_TSC, msr); if (!crash) free_page((unsigned long)hv_context.tsc_page); hv_context.tsc_page = NULL; @@ -352,12 +346,10 @@ static int hv_ce_shutdown(struct clock_event_device *evt) static int hv_ce_set_oneshot(struct clock_event_device *evt) { - union hv_timer_config timer_cfg; + u64 timer_cfg = HV_STIMER_ENABLE | HV_STIMER_AUTOENABLE | + (VMBUS_MESSAGE_SINT << 16); - timer_cfg.enable = 1; - timer_cfg.auto_enable = 1; - timer_cfg.sintx = VMBUS_MESSAGE_SINT; - wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64); + wrmsrl(HV_X64_MSR_STIMER0_CONFIG, timer_cfg); return 0; } @@ -474,52 +466,39 @@ void hv_synic_free(void) */ void hv_synic_init(void *arg) { - u64 version; - union hv_synic_simp simp; - union hv_synic_siefp siefp; - union hv_synic_sint shared_sint; - union hv_synic_scontrol sctrl; - u64 vp_index; - + u64 msr; int cpu = smp_processor_id(); if (!hv_context.hypercall_page) return; /* Check the version */ - rdmsrl(HV_X64_MSR_SVERSION, version); + rdmsrl(HV_X64_MSR_SVERSION, msr); /* Setup the Synic's message page */ - rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64); - simp.simp_enabled = 1; - simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu]) - >> PAGE_SHIFT; - - wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); + rdmsrl(HV_X64_MSR_SIMP, msr); + msr &= PAGE_MASK; + msr |= virt_to_phys(hv_context.synic_message_page[cpu]) | + HV_SYNIC_SIMP_ENABLE; + wrmsrl(HV_X64_MSR_SIMP, msr); /* Setup the Synic's event page */ - rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); - siefp.siefp_enabled = 1; - siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu]) - >> PAGE_SHIFT; - - wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); + rdmsrl(HV_X64_MSR_SIEFP, msr); + msr &= PAGE_MASK; + msr |= virt_to_phys(hv_context.synic_event_page[cpu]) | + HV_SYNIC_SIEFP_ENABLE; + wrmsrl(HV_X64_MSR_SIEFP, msr); /* Setup the shared SINT. */ - rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); - - shared_sint.as_uint64 = 0; - shared_sint.vector = HYPERVISOR_CALLBACK_VECTOR; - shared_sint.masked = false; - shared_sint.auto_eoi = true; - - wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); + rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr); + msr &= ~(HV_SYNIC_SINT_MASKED | HV_SYNIC_SINT_VECTOR_MASK); + msr |= HYPERVISOR_CALLBACK_VECTOR | HV_SYNIC_SINT_AUTO_EOI; + wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr); /* Enable the global synic bit */ - rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); - sctrl.enable = 1; - - wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); + rdmsrl(HV_X64_MSR_SCONTROL, msr); + msr |= HV_SYNIC_CONTROL_ENABLE; + wrmsrl(HV_X64_MSR_SCONTROL, msr); hv_context.synic_initialized = true; @@ -528,8 +507,8 @@ void hv_synic_init(void *arg) * of cpuid and Linux' notion of cpuid. * This array will be indexed using Linux cpuid. */ - rdmsrl(HV_X64_MSR_VP_INDEX, vp_index); - hv_context.vp_index[cpu] = (u32)vp_index; + rdmsrl(HV_X64_MSR_VP_INDEX, msr); + hv_context.vp_index[cpu] = (u32)msr; INIT_LIST_HEAD(&hv_context.percpu_list[cpu]); @@ -563,10 +542,7 @@ void hv_synic_clockevents_cleanup(void) */ void hv_synic_cleanup(void *arg) { - union hv_synic_sint shared_sint; - union hv_synic_simp simp; - union hv_synic_siefp siefp; - union hv_synic_scontrol sctrl; + u64 msr; int cpu = smp_processor_id(); if (!hv_context.synic_initialized) @@ -578,28 +554,20 @@ void hv_synic_cleanup(void *arg) hv_ce_shutdown(hv_context.clk_evt[cpu]); } - rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); - - shared_sint.masked = 1; - - /* Need to correctly cleanup in the case of SMP!!! */ - /* Disable the interrupt */ - wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); - - rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64); - simp.simp_enabled = 0; - simp.base_simp_gpa = 0; - - wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); + rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr); + msr |= HV_SYNIC_SINT_MASKED; + wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, msr); - rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); - siefp.siefp_enabled = 0; - siefp.base_siefp_gpa = 0; + rdmsrl(HV_X64_MSR_SIMP, msr); + msr &= ~HV_SYNIC_SIMP_ENABLE; + wrmsrl(HV_X64_MSR_SIMP, msr); - wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); + rdmsrl(HV_X64_MSR_SIEFP, msr); + msr &= ~HV_SYNIC_SIEFP_ENABLE; + wrmsrl(HV_X64_MSR_SIEFP, msr); /* Disable the global synic bit */ - rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); - sctrl.enable = 0; - wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); + rdmsrl(HV_X64_MSR_SCONTROL, msr); + msr &= ~HV_SYNIC_CONTROL_ENABLE; + wrmsrl(HV_X64_MSR_SCONTROL, msr); } -- 2.9.3