From patchwork Wed Jan 22 20:23:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6515B1580 for ; Wed, 22 Jan 2020 20:25:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 41AEF24655 for ; Wed, 22 Jan 2020 20:25:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KsxSjogJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41AEF24655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXa-0006EX-2Y; Wed, 22 Jan 2020 20:23:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXZ-0006ES-0A for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:23:53 +0000 X-Inumbo-ID: 187ed5e2-3d55-11ea-aecd-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 187ed5e2-3d55-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 20:23:48 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id q10so469430wrm.11 for ; Wed, 22 Jan 2020 12:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e3XL4uu/8zRUT3kMySEH+EKr0ciyiwuAqAEdw4QD6CY=; b=KsxSjogJ5n6kFS4/uLZMahdXLGE5/YcqDmekfNe8r/OW8+vxOKEIFSUpg2uamcIkEB UV0SU1M1b+NigKiGN7aHAYxrOlYohWJitqorzQNpkABLDQ3MClva1u2XnDvN9ehvDwh8 7O+ozmWr/vdQT4otGp/FwHB7pruUMlOZkAdkhb3oZ+/PW+qiROAST1VbsX375v5ue/Gq 7AWuiCP6cAbCR7amNzMEKGmRJ7/Ch+Ocsm0DoEHifnSCLDwBR2Oh9vqVMUDG+T/LEMEs OadiVx3QO4fy9dTvCg7w2DBzqVAb47dsYxohzHCXfnzvqtq+YRwwg1ucrC3+BVWqPU8e JYPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=e3XL4uu/8zRUT3kMySEH+EKr0ciyiwuAqAEdw4QD6CY=; b=ArGJqJ4+glI9XoOg5OAUpIbJoHfG1r3Vf6f/BJ6Ht82Azi9sjq75HQ40NBcflHdv43 qFGjmoDUlK4Q7PB+bK1RvVakEnDutXS8LvkkkeeTP6aSHUuZ5D1y/CubYwNEdzsuc+s4 HVDfRcQByZFS4htqSAOZHYvei98VfeInMRcxW81GbJWcIm9vCoy4zR0TnIavt/6pUm+3 oUrViGkoXI9cvqrw5RaitWXNba27Xz8q/59jfXUYMe4hHxMYUsEI4Q1hnTvv+9iEsS9Q hC3ISfkuNchgTrHE06AxrDq+KJIzI8QNo84IrQ30T9gZrTCmKH9Fh+VNdQ+xsHOSIrcF Rzww== X-Gm-Message-State: APjAAAXvuQU4XaHFDQguWpNZVkGtCTZHqF50BA5mMRgzAyS0BPyPJkdo oDAYVoSmIzRLGTcGyHZoX04eoRp0Dj4nYQ== X-Google-Smtp-Source: APXvYqzctyQ+QsaZCC5gfEhH2QFbzam5/HHNBlp2+lxvCJljHLJoN66rCroMvX4NlYrnAOCf+jJoYQ== X-Received: by 2002:adf:f1d0:: with SMTP id z16mr12716601wro.209.1579724627415; Wed, 22 Jan 2020 12:23:47 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:46 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:37 +0000 Message-Id: <20200122202343.5703-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 1/7] x86: provide executable fixmap facility X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Konrad Rzeszutek Wilk , Michael Kelley , Ross Lagerwall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This allows us to set aside some address space for executable mapping. This fixed map range starts from XEN_VIRT_END so that it is within reach of the .text section. Shift the percpu stub range and livepatch range accordingly. Signed-off-by: Wei Liu --- xen/arch/x86/boot/x86_64.S | 10 +++++++++- xen/arch/x86/livepatch.c | 3 ++- xen/arch/x86/mm.c | 9 +++++++++ xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/xen.lds.S | 3 +++ xen/include/asm-x86/config.h | 2 +- xen/include/asm-x86/fixmap.h | 28 ++++++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index 1cbf5acdfb..605d01f1dd 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -85,7 +85,15 @@ GLOBAL(l2_directmap) * 4k page. */ GLOBAL(l2_xenmap) - .fill L2_PAGETABLE_ENTRIES, 8, 0 + idx = 0 + .rept L2_PAGETABLE_ENTRIES + .if idx == l2_table_offset(FIXADDR_X_TOP - 1) + .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR + .else + .quad 0 + .endif + idx = idx + 1 + .endr .size l2_xenmap, . - l2_xenmap /* L2 mapping the fixmap. Uses 1x 4k page. */ diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 2749cbc5cf..513b0f3841 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -311,7 +312,7 @@ void __init arch_livepatch_init(void) void *start, *end; start = (void *)xen_virt_end; - end = (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE); + end = (void *)(XEN_VIRT_END - FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE); BUG_ON(end <= start); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 654190e9e9..aabe1a4c64 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -157,6 +157,8 @@ /* Mapping of the fixmap space needed early. */ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES]; +l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) + l1_fixmap_x[L1_PAGETABLE_ENTRIES]; paddr_t __read_mostly mem_hotplug; @@ -5763,6 +5765,13 @@ void __set_fixmap( map_pages_to_xen(__fix_to_virt(idx), _mfn(mfn), 1, flags); } +void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags) +{ + BUG_ON(idx >= __end_of_fixed_addresses_x); + map_pages_to_xen(__fix_x_to_virt(idx), _mfn(mfn), 1, flags); +} + void *__init arch_vmap_virt_end(void) { return fix_to_virt(__end_of_fixed_addresses); diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index c9d1ab4423..2da42fb691 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -640,7 +640,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE)); } - stub_va = XEN_VIRT_END - (cpu + 1) * PAGE_SIZE; + stub_va = XEN_VIRT_END - FIXADDR_X_SIZE - (cpu + 1) * PAGE_SIZE; if ( map_pages_to_xen(stub_va, page_to_mfn(pg), 1, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) ) { diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 07c6448dbb..cbc5701214 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -3,6 +3,8 @@ #include #include + +#include #include #undef ENTRY #undef ALIGN @@ -353,6 +355,7 @@ SECTIONS } ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START - + MAX_FIXADDR_X_SIZE - DIV_ROUND_UP(NR_CPUS, STUBS_PER_PAGE) * PAGE_SIZE, "Xen image overlaps stubs area") diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h index d0cfbb70a8..4fa56ea0a9 100644 --- a/xen/include/asm-x86/config.h +++ b/xen/include/asm-x86/config.h @@ -218,7 +218,7 @@ extern unsigned char boot_edid_info[128]; /* Slot 261: high read-only compat machine-to-phys conversion table (1GB). */ #define HIRO_COMPAT_MPT_VIRT_START RDWR_COMPAT_MPT_VIRT_END #define HIRO_COMPAT_MPT_VIRT_END (HIRO_COMPAT_MPT_VIRT_START + GB(1)) -/* Slot 261: xen text, static data and bss (1GB). */ +/* Slot 261: xen text, static data, bss and executable fixmap (1GB). */ #define XEN_VIRT_START (HIRO_COMPAT_MPT_VIRT_END) #define XEN_VIRT_END (XEN_VIRT_START + GB(1)) diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h index 9fb2f47946..c2a9d2b50a 100644 --- a/xen/include/asm-x86/fixmap.h +++ b/xen/include/asm-x86/fixmap.h @@ -15,6 +15,9 @@ #include #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE) +#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +/* This constant is derived from enum fixed_addresses_x below */ +#define MAX_FIXADDR_X_SIZE (2 << PAGE_SHIFT) #ifndef __ASSEMBLY__ @@ -89,6 +92,31 @@ static inline unsigned long virt_to_fix(const unsigned long vaddr) return __virt_to_fix(vaddr); } +enum fixed_addresses_x { + /* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */ + FIX_X_RESERVED, +#ifdef CONFIG_HYPERV_GUEST + FIX_X_HYPERV_HCALL, +#endif + __end_of_fixed_addresses_x +}; + +#define FIXADDR_X_SIZE (__end_of_fixed_addresses_x << PAGE_SHIFT) +#define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE) + +extern void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags); + +#define set_fixmap_x(idx, phys) \ + __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) + +#define clear_fixmap_x(idx) __set_fixmap_x(idx, 0, 0) + +#define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) +#define __virt_to_fix_x(x) ((FIXADDR_X_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) + +#define fix_x_to_virt(x) ((void *)__fix_x_to_virt(x)) + #endif /* __ASSEMBLY__ */ #endif From patchwork Wed Jan 22 20:23:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B59E92A for ; Wed, 22 Jan 2020 20:25:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBC5624655 for ; Wed, 22 Jan 2020 20:25:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ek8LREQW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBC5624655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXf-0006FG-GE; Wed, 22 Jan 2020 20:23:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXd-0006F4-W4 for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:23:58 +0000 X-Inumbo-ID: 18ff56fe-3d55-11ea-9fd7-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 18ff56fe-3d55-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 20:23:49 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id c9so489391wrw.8 for ; Wed, 22 Jan 2020 12:23:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hpuNmbi3NIrtI9XWZDVNmn3N4Ap+/HsCumpfsYCUB1I=; b=ek8LREQWmkE4UZkuzuoFdRiExdWuOvPpFXnb/VaGIGsKeRHaFzssk0985Q0dL7MW1h 29jo8FjCpdspmZTenycoLce5Rs9Y5xaqUNivkmne0tPC4tN3Ai7awP+S//InxVUk8wS4 snPen59LdYtXNbAX44gqs5anvqHIz4ZEDkNePNzyDX8O0yP+jfWn0Sbqd58WfRfl+rF7 JVPrhAeW4ucnXoAExhm3SMS+O9ljvWX39Mn4nUhwYijPtPvTkpopxjaFg6O0W5CnK/uL UrABcI80LQf6vgKf56bHCiLePhNZtLFNp8EirB9vsqUsmQSH8zRpeYqgaR31ywfTiJ5M Q51A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hpuNmbi3NIrtI9XWZDVNmn3N4Ap+/HsCumpfsYCUB1I=; b=Snrf4/hyeQCE2FNs/RMf+eXBfPeCtqVSEdo4nHgHWjZZQCe0crdst8wrWhyqGcZyJ4 9zqI767Epi96Abf/mJfO6PfON5GYz9WjC06Ossb02gnJQfTsX3e+hl7zcymjS5pV3X2q nkp2KRlWE5rY4qTIdySe0Xu7SWY63LizvzCWZ1i/BeyAzVlKKSoBBPNhBAx9S9bzToT1 X6B74FBFjgQow2pWh8cZfttaw0rmNQxv6wyhcCoIPDXlSaBY6wV82emCYE0kxTEfSuOz mQ6Ylt29URAlt+mXdHs99+UETWpJucQEA3JYEOsQ8fRtBp7Bzo8SslVLfTSsIv+Y/rw8 SHbQ== X-Gm-Message-State: APjAAAVHPjcC4mYRDkzIx8uv7Dkb0tcg+kGfRLY9gUZ0obS/uAkl8ehL ZN0eoUJP9OfsuiKlpGY0coI4OoAn8PrTwg== X-Google-Smtp-Source: APXvYqyioxSeD5rpVA3j5CgzuYV6XmhP+dr2avBDbBfm6ov1Sv/aGALiB9fl3Zui9KSiTbHvPy5bdg== X-Received: by 2002:a5d:6048:: with SMTP id j8mr13625476wrt.41.1579724628294; Wed, 22 Jan 2020 12:23:48 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:47 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:38 +0000 Message-Id: <20200122202343.5703-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 2/7] x86/hyperv: setup hypercall page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Paul Durrant , Michael Kelley , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Use the top-most addressable page for that purpose. Adjust e820 code accordingly. We also need to register Xen's guest OS ID to Hyper-V. Use 0x300 as the OS type. Signed-off-by: Wei Liu --- XXX the decision on Xen's vendor ID is pending. v4: 1. Use fixmap 2. Follow routines listed in TLFS --- xen/arch/x86/e820.c | 41 +++++++++++++++---- xen/arch/x86/guest/hyperv/hyperv.c | 53 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index 082f9928a1..5a4ef27a0b 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -36,6 +36,22 @@ boolean_param("e820-verbose", e820_verbose); struct e820map e820; struct e820map __initdata e820_raw; +static unsigned int find_phys_addr_bits(void) +{ + uint32_t eax; + unsigned int phys_bits = 36; + + eax = cpuid_eax(0x80000000); + if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 ) + { + phys_bits = (uint8_t)cpuid_eax(0x80000008); + if ( phys_bits > PADDR_BITS ) + phys_bits = PADDR_BITS; + } + + return phys_bits; +} + /* * This function checks if the entire range is mapped with type. * @@ -357,6 +373,21 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; } +#ifdef CONFIG_HYPERV_GUEST + { + /* + * We reserve the top-most page for hypercall page. Adjust + * max_pfn if necessary. + */ + unsigned int phys_bits = find_phys_addr_bits(); + unsigned long hcall_pfn = + ((1ull << phys_bits) - 1) >> PAGE_SHIFT; + + if ( max_pfn >= hcall_pfn ) + max_pfn = hcall_pfn - 1; + } +#endif + return max_pfn; } @@ -420,7 +451,7 @@ static uint64_t __init mtrr_top_of_ram(void) { uint32_t eax, ebx, ecx, edx; uint64_t mtrr_cap, mtrr_def, addr_mask, base, mask, top; - unsigned int i, phys_bits = 36; + unsigned int i, phys_bits; /* By default we check only Intel systems. */ if ( e820_mtrr_clip == -1 ) @@ -446,13 +477,7 @@ static uint64_t __init mtrr_top_of_ram(void) return 0; /* Find the physical address size for this CPU. */ - eax = cpuid_eax(0x80000000); - if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 ) - { - phys_bits = (uint8_t)cpuid_eax(0x80000008); - if ( phys_bits > PADDR_BITS ) - phys_bits = PADDR_BITS; - } + phys_bits = find_phys_addr_bits(); addr_mask = ((1ull << phys_bits) - 1) & ~((1ull << 12) - 1); rdmsrl(MSR_MTRRcap, mtrr_cap); diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 8d38313d7a..f986c1a805 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -18,17 +18,27 @@ * * Copyright (c) 2019 Microsoft. */ +#include #include +#include #include #include +#include struct ms_hyperv_info __read_mostly ms_hyperv; -static const struct hypervisor_ops ops = { - .name = "Hyper-V", -}; +static uint64_t generate_guest_id(void) +{ + uint64_t id = 0; + + id = (uint64_t)HV_XEN_VENDOR_ID << 48; + id |= (xen_major_version() << 16) | xen_minor_version(); + + return id; +} +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { uint32_t eax, ebx, ecx, edx; @@ -72,6 +82,43 @@ const struct hypervisor_ops *__init hyperv_probe(void) return &ops; } +static void __init setup_hypercall_page(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + union hv_guest_os_id guest_id; + unsigned long mfn; + + rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + if ( !guest_id.raw ) + { + guest_id.raw = generate_guest_id(); + wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + } + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + if ( !hypercall_msr.enable ) + { + mfn = ((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT; + hypercall_msr.enable = 1; + hypercall_msr.guest_physical_address = mfn; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + } else { + mfn = hypercall_msr.guest_physical_address; + } + + set_fixmap_x(FIX_X_HYPERV_HCALL, mfn << PAGE_SHIFT); +} + +static void __init setup(void) +{ + setup_hypercall_page(); +} + +static const struct hypervisor_ops ops = { + .name = "Hyper-V", + .setup = setup, +}; + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/guest/hyperv-tlfs.h b/xen/include/asm-x86/guest/hyperv-tlfs.h index 05c4044976..5d37efd2d2 100644 --- a/xen/include/asm-x86/guest/hyperv-tlfs.h +++ b/xen/include/asm-x86/guest/hyperv-tlfs.h @@ -318,15 +318,16 @@ struct ms_hyperv_tsc_page { * * Bit(s) * 63 - Indicates if the OS is Open Source or not; 1 is Open Source - * 62:56 - Os Type; Linux is 0x100 + * 62:56 - Os Type; Linux 0x100, FreeBSD 0x200, Xen 0x300 * 55:48 - Distro specific identification - * 47:16 - Linux kernel version number + * 47:16 - Guest OS version number * 15:0 - Distro specific identification * * */ #define HV_LINUX_VENDOR_ID 0x8100 +#define HV_XEN_VENDOR_ID 0x8300 union hv_guest_os_id { uint64_t raw; From patchwork Wed Jan 22 20:23:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A74CD1580 for ; Wed, 22 Jan 2020 20:25:04 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83F6524655 for ; Wed, 22 Jan 2020 20:25:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J5O9J+Cg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83F6524655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXj-0006GK-Qw; Wed, 22 Jan 2020 20:24:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXi-0006G6-Va for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:02 +0000 X-Inumbo-ID: 19d23cd6-3d55-11ea-aecd-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 19d23cd6-3d55-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 20:23:50 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id c14so492018wrn.7 for ; Wed, 22 Jan 2020 12:23:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wshk7kIRKYuRU8xqobkC9+OQZAACVFBRhKVgA/3wfFw=; b=J5O9J+CgE4hZYtJENBevnbiBydhRlnUT3xMQPNmYXrqZ+y9OM+j6+WjMqD/68GV4Du n2f+vd5inClc2vv7xFhjaww3Bdb/nKK5cXBWCjSuZZIjAqmtvHq9cuCFFL1V1Irzi7e2 qZHKOOTwa0XbwN2JrdVdyLfjsYJh2FPONDyapiEmSO3UdKZGhngkqaPkrlllMV7/WTig Gk+Lt07h4X8hoCxkta7qtA6PefbhtHM1V8AEzBnXYjr682zwVguPxsWYOaxRJNDhclEW wJbt5TFc39x2Xx1ZbgvTI567nBE/l1PE3qp6gCY+hXDRGJCvaEAJcybIy+nKOSwPpilk qhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Wshk7kIRKYuRU8xqobkC9+OQZAACVFBRhKVgA/3wfFw=; b=ctZ2eGeaLKIoHhqmek9KwtZ3WWhxvyDrvVrrp7E1CAiDyad0jHtBtoIMoNWgCPMihm aBaW4wnDn8BoKSWDJMOGpeqb8bkkiZuRpewXZp7PyTANJnpNzdcSi+yLufMAbSY6J9i5 5LRALpGF7mF5LU+iOSR3Pd+IUslyelhKZUe+21r2Bx8p+BcgkQXU8rlNvURaLoxIMjuK zN6ONsXhFsBK0hidU9Tf1PqCLAaddROLj4zQhgFA+Gie6foWWSrSABYlmskMeZbZiPxS ALcyBSvUqWPAPju6gHbzbB/M4GAGmdDISA6buUso3vkR/OK1Mv4LBM4W+k1DBn9mJRDi RnNg== X-Gm-Message-State: APjAAAVwKQjFy1lEH3g82U385SJhUw8k2Q8wZvP2yoW/uvcp9TvCWDsj qYULjpvKC0L2hMeRom3lHQ2zjlOfURX2AA== X-Google-Smtp-Source: APXvYqycE4F2unuKVNHoENJxRXm3fAuztRCfAPQgiw8xoMEXya576SqK4vk4adWIBQHERmRGHw6DPw== X-Received: by 2002:adf:ed83:: with SMTP id c3mr12699225wro.51.1579724629260; Wed, 22 Jan 2020 12:23:49 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:48 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:39 +0000 Message-Id: <20200122202343.5703-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 3/7] x86/hyperv: provide Hyper-V hypercall functions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" These functions will be used later to make hypercalls to Hyper-V. Signed-off-by: Wei Liu --- v4: 1. Adjust code due to previous patch has changed 2. Address comments --- xen/include/asm-x86/guest/hyperv-hcall.h | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.h diff --git a/xen/include/asm-x86/guest/hyperv-hcall.h b/xen/include/asm-x86/guest/hyperv-hcall.h new file mode 100644 index 0000000000..509e57f481 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hcall.h @@ -0,0 +1,98 @@ +/****************************************************************************** + * asm-x86/guest/hyperv-hcall.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + * + * Copyright (c) 2019 Microsoft. + */ + +#ifndef __X86_HYPERV_HCALL_H__ +#define __X86_HYPERV_HCALL_H__ + +#include +#include + +#include +#include +#include +#include + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input_addr, + paddr_t output_addr) +{ + uint64_t status; + register unsigned long r8 asm("r8") = output_addr; + + asm volatile ("INDIRECT_CALL %P[hcall_page]" + : "=a" (status), "+c" (control), + "+d" (input_addr) ASM_CALL_CONSTRAINT + : "r" (r8), + [hcall_page] "p" (fix_x_to_virt(FIX_X_HYPERV_HCALL)) + : "memory"); + + return status; +} + +static inline uint64_t hv_do_fast_hypercall(uint16_t code, + uint64_t input1, uint64_t input2) +{ + uint64_t status; + uint64_t control = code | HV_HYPERCALL_FAST_BIT; + register unsigned long r8 asm("r8") = input2; + + asm volatile ("INDIRECT_CALL %P[hcall_page]" + : "=a" (status), "+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + : "r" (r8), + [hcall_page] "p" (fix_x_to_virt(FIX_X_HYPERV_HCALL)) + :); + + return status; +} + +static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t rep_count, + uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control = code; + uint64_t status; + uint16_t rep_comp; + + control |= (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; + control |= (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; + + do { + status = hv_do_hypercall(control, input, output); + if ( (status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS ) + break; + + rep_comp = MASK_EXTR(status, HV_HYPERCALL_REP_COMP_MASK); + + control &= ~HV_HYPERCALL_REP_START_MASK; + control |= MASK_INSR(rep_comp, HV_HYPERCALL_REP_COMP_MASK); + } while ( rep_comp < rep_count ); + + return status; +} + +#endif /* __X86_HYPERV_HCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Wed Jan 22 20:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CAF792A for ; Wed, 22 Jan 2020 20:25:01 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 06D5D24655 for ; Wed, 22 Jan 2020 20:25:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N9Q7YDS0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06D5D24655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXp-0006IZ-6X; Wed, 22 Jan 2020 20:24:09 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXo-0006IE-0D for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:08 +0000 X-Inumbo-ID: 1a1ce4a2-3d55-11ea-8e9a-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1a1ce4a2-3d55-11ea-8e9a-bc764e2007e4; Wed, 22 Jan 2020 20:23:51 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id z3so522272wru.3 for ; Wed, 22 Jan 2020 12:23:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z9zRpSrWMsfBPDPq03Nj1xHSfrX+WJI3r1UMf9GF7YQ=; b=N9Q7YDS0x/c/guYVRx2kGbAn/h/Pbo6Jiv0t0FJLdzwLBOi+9CpCC4J/SOzge5vrLc B9mj71yjWd5l2/n9VGkjXuxin5p+cW+4OTWeYOW+wg3GMUot7Fed6CQ9mKx1r77g7Aeb /X/H/RGtPa3KGC/UxG+SDaAbQvnA7lAK3B76EMJCy+XicZfGW1PpKyi8jy3IRDTrJJOv wrPXnxGBj9nJ9HncI2M5xabmJNcLbDOme0lUZXGb96siCCfTjqDLUSsiGUrMYtiont5G CtCXIuEYeVHue0xOhNozmcvr6x9bpi9eG2u3RgqW/+sBkDJAORU8pb8Kk3YzP2rRuqGJ Pt2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=z9zRpSrWMsfBPDPq03Nj1xHSfrX+WJI3r1UMf9GF7YQ=; b=shHTfq/sKLpXnnCIwCqQJ0ZCLtqi++FwRR6BONM7HE0XV6IPmERJbuT7V2baRYQo4F MUP2walT/buQ5iWv7aiVRB5BmIqpkGJOywvd280DowBTojWl6bMSlFtLDk7oynVduRKq sOUG3LWD9/flZY+cG0xgjlbDuLIPUCIlJ4f3mg7agQJ7EJAIob/dPhmKhm40yLQO4z0l ZxHz4seTBGdKZVSOUYpVaEEmftqIl/F6eEdpMdHSkH47qR2V9s1g+FRZuH5kfn34ReFO raonm0iwPTM1RZ8L2uMSuTsF+DF5y78nJX9AFVtd1450TuplYjLJa4WIEpu83SjmwswZ WO4Q== X-Gm-Message-State: APjAAAW6unBPTXqmJY03VH4WmCuQAOx2dQ/zQuYP5/fZfu177C5OKS4C sR7RVVIxLjfIkw4jhqXrNyAfcgoj6rFVgA== X-Google-Smtp-Source: APXvYqyRApyQg39fOlK6nmLBQ8KU1JvzwV787HjUBhXybIlNpcsN9K7+r8WM13eeUyG5E0BaBMeNVw== X-Received: by 2002:adf:f80b:: with SMTP id s11mr13723290wrp.12.1579724630249; Wed, 22 Jan 2020 12:23:50 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:49 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:40 +0000 Message-Id: <20200122202343.5703-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 4/7] DO NOT APPLY: x86/hyperv: issue an hypercall X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Test if the infrastructure works. Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index f986c1a805..536ce0d0dd 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -107,6 +108,15 @@ static void __init setup_hypercall_page(void) } set_fixmap_x(FIX_X_HYPERV_HCALL, mfn << PAGE_SHIFT); + + /* XXX Wei: Issue an hypercall here to make sure things are set up + * correctly. When there is actual use of the hypercall facility, + * this can be removed. + */ + { + uint16_t r = hv_do_hypercall(0xffff, 0, 0); + BUG_ON(r != HV_STATUS_INVALID_HYPERCALL_CODE); + } } static void __init setup(void) From patchwork Wed Jan 22 20:23:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5296792A for ; Wed, 22 Jan 2020 20:25:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2ED4824655 for ; Wed, 22 Jan 2020 20:25:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t7h5F9pi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2ED4824655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXu-0006LW-JN; Wed, 22 Jan 2020 20:24:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXt-0006Kr-0j for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:13 +0000 X-Inumbo-ID: 1ab8b9d6-3d55-11ea-aecd-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1ab8b9d6-3d55-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 20:23:52 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id d16so475116wre.10 for ; Wed, 22 Jan 2020 12:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YBVOWoTwbZt9RyjSkTi/ui/Jx6IMZiyjvsALlSN6nSE=; b=t7h5F9pi2aI+55TSpCLtn2rYRhsgcOeZSKkqceGIwlLZ12DZuXOEWQYuKn0r1Gk1Vi H1iFskjWdIccISsgsS8621EpA3z70oHSPlyy4ZDpHemT/Q9K4I5jknw/V/6cTgpPrFG9 QqxTRW0+ADCG584d/dgjdwI5mRDrGNpR+kDJ+5GT1AtwO4m7HeECHhNQBptN/69t7WnV 3AiQ3suzxDBoAbl3/hGuM2WDsgfpqic8/aLlNejYkTnULhx0F1z3sYftParDWlYffcM7 cNaoAGQ2/tJsmuV1ZreGVDPcabUwzvt+9U8Uy7jBXAKMzOIP8uL4B21JgAC4qqNpkTRN xhKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YBVOWoTwbZt9RyjSkTi/ui/Jx6IMZiyjvsALlSN6nSE=; b=AO0V2UkNUcV2K/UZHisY+LdRoSoPfCACvZ+FIYd8rAD+lA1ZmnM8GafFQS1om9hSkR 0lxCTuk48lMSGYIuidvX73aHVrx/u8N4V5PF20/Ym3pdKsXV4wFOmRSzDG2LMKI/K0yn osRWMaPxIod+RYp9sxql+qo+jj+UbyzX9iLzC80pFI20ZSyOhqGNnyW7pSJpmqW1OyN9 h7lAzWDoRU9U1KYXax0wfGQBcIlZsRrcEUV8cYH8U3ICbERBbiO0PweEVGxzJMb+5d7t Eowaz1e1VPFoAMZJDvHDdgEARZzAUlMUeEq0jMlVlN8aOob7giOuH1wzNLCrO9YaBq1h I1CQ== X-Gm-Message-State: APjAAAUXakRtSQothBTOC++pTC+U5kMpYK76ZfYDv94ITRs/rqzaYlWk Iouo5hS4VJGJvJukBGqP3vOsy4cb/PLu+g== X-Google-Smtp-Source: APXvYqyAuuFKdrMyEvBBl88vXcykiPuUdzNUrlZbFli+SHlAWWXlKZQlqT+j+Zb4nGDz4nikvOW4pg== X-Received: by 2002:a05:6000:160d:: with SMTP id u13mr12590691wrb.22.1579724631245; Wed, 22 Jan 2020 12:23:51 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:50 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:41 +0000 Message-Id: <20200122202343.5703-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 5/7] x86/hyperv: provide percpu hypercall input page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. One way to satisfy those requirements is to use percpu page. For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page. We will also need to provide an ap_setup hook for secondary cpus to setup its own input page. Signed-off-by: Wei Liu --- v4: 1. Change wording in commit message 2. Prevent leak 3. Introduce a private header v3: 1. Use xenheap page instead 2. Drop page tracking structure 3. Drop Paul's review tag --- xen/arch/x86/guest/hyperv/hyperv.c | 25 +++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/private.h diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 536ce0d0dd..c5195af948 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -27,7 +27,10 @@ #include #include +#include "private.h" + struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); static uint64_t generate_guest_id(void) { @@ -119,14 +122,36 @@ static void __init setup_hypercall_page(void) } } +static void setup_hypercall_pcpu_arg(void) +{ + void *mapping; + + if ( this_cpu(hv_pcpu_input_arg) ) + return; + + mapping = alloc_xenheap_page(); + if ( !mapping ) + panic("Failed to allocate hypercall input page for CPU%u\n", + smp_processor_id()); + + this_cpu(hv_pcpu_input_arg) = mapping; +} + static void __init setup(void) { setup_hypercall_page(); + setup_hypercall_pcpu_arg(); +} + +static void ap_setup(void) +{ + setup_hypercall_pcpu_arg(); } static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, }; /* diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h new file mode 100644 index 0000000000..b6902b5639 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/private.h @@ -0,0 +1,29 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/private.h + * + * Definitions / declarations only useful to Hyper-V code. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Copyright (c) 2020 Microsoft. + */ + +#ifndef __XEN_HYPERV_PRIVIATE_H__ +#define __XEN_HYPERV_PRIVIATE_H__ + +#include + +DECLARE_PER_CPU(void *, hv_pcpu_input_arg); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */ From patchwork Wed Jan 22 20:23:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A3A792A for ; Wed, 22 Jan 2020 20:25:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0688424655 for ; Wed, 22 Jan 2020 20:25:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AqG8fBZP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0688424655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXy-0006Ny-Us; Wed, 22 Jan 2020 20:24:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXy-0006NU-0H for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:18 +0000 X-Inumbo-ID: 1b43a186-3d55-11ea-8e9a-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1b43a186-3d55-11ea-8e9a-bc764e2007e4; Wed, 22 Jan 2020 20:23:53 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id g17so528341wro.2 for ; Wed, 22 Jan 2020 12:23:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BC91hdyPWV2hM/+wf0AJs+FRr6HNGJISWFhaN0f9Tb0=; b=AqG8fBZPBYp8jfoKXSZCsN7epFOY5v1w1Sa8ukbc/KRcnw+8Y0iCtlLfPHukMrxsR8 7Tg+g0RTIVCdvr1DyjVAKduyBqGHQC/jGvGM4zLd6trMoUFWGyzu0TDreHCPUz0926c8 MFElRQPtJE4IC9Tn0upJPkm+BOlAoosqpFTiGqexfiUfjYPh6Qv2r85iaE7CKKbieI2T l9mfdBt4a7pKHXYtO5RCV75aTGVxxHaoOaBA4hRMKpDLuTC0qWN2IVDLo5qX0lVe1d2q uGGXwerQKD44cz4+HMOQtnY8lXiUCeB/c3cO76abhRm+UozcFuEZ8WmHIZwtF0OEcs9J LFIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BC91hdyPWV2hM/+wf0AJs+FRr6HNGJISWFhaN0f9Tb0=; b=PQ/zurYpf/Y4nXPhvwxwFD+8Lmf393zZ4cZVfLJtgm3n2KDlvUeM+1wjwbpS6hBTOp RfxUvxcEsLwLkvsdvMc7hXoiS4gsqwJKQCN9yGNGI7z1DqA7NA6YqV+15LLkiy2jWoo8 Lw85nJqKVNKTBD0ePX4ELqxTlneM4Mn5M2CHiR0YEgvjmGKDarE9xSMECxD/dlTDnyUT YH/7zX+MbiwcsAUNj5aIpqWXaxXvfG2AsJlnIjHcEsugsVpHhOC+H5bL+ZjnPmEGNWY9 UxwiursGS6ljiqzXDOOCHIosV9yJ3w9eU8Bks6VsIc2UxAlvidRKhiFwo9ooXL4p8tfA HZDg== X-Gm-Message-State: APjAAAViPLb5oqT/Yo9Fudp2IIdprv4uZBfDsSfthZwE45Wn7OtgK8qA CSy5eLPY7kTk1/Fqn6O4c4+R8dU/j1fJ6w== X-Google-Smtp-Source: APXvYqwk6HQpf+44L7I2MA22dHt5tir2BvnV1QjBKthOuxwqexeCAGNnBdYOsvYCBn4ao7WqLwa2ag== X-Received: by 2002:a5d:46c1:: with SMTP id g1mr12965981wrs.200.1579724632194; Wed, 22 Jan 2020 12:23:52 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:51 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:42 +0000 Message-Id: <20200122202343.5703-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 6/7] x86/hyperv: retrieve vp_index from Hyper-V X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This will be useful when invoking hypercall that targets specific vcpu(s). Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- v4: 1. Use private.h 2. Add Paul's review tag v2: 1. Fold into setup_pcpu_arg function --- xen/arch/x86/guest/hyperv/hyperv.c | 5 +++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 6 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index c5195af948..085e646dc6 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -31,6 +31,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static uint64_t generate_guest_id(void) { @@ -125,6 +126,7 @@ static void __init setup_hypercall_page(void) static void setup_hypercall_pcpu_arg(void) { void *mapping; + uint64_t vp_index_msr; if ( this_cpu(hv_pcpu_input_arg) ) return; @@ -135,6 +137,9 @@ static void setup_hypercall_pcpu_arg(void) smp_processor_id()); this_cpu(hv_pcpu_input_arg) = mapping; + + rdmsrl(HV_X64_MSR_VP_INDEX, vp_index_msr); + this_cpu(hv_vp_index) = vp_index_msr; } static void __init setup(void) diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index b6902b5639..da70990401 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -25,5 +25,6 @@ #include DECLARE_PER_CPU(void *, hv_pcpu_input_arg); +DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */ From patchwork Wed Jan 22 20:23:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 083601580 for ; Wed, 22 Jan 2020 20:25:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D505A24655 for ; Wed, 22 Jan 2020 20:25:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gtWqCrbH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D505A24655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMY4-0006RO-I7; Wed, 22 Jan 2020 20:24:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMY3-0006Ql-1G for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:23 +0000 X-Inumbo-ID: 1bd0d312-3d55-11ea-8e9a-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1bd0d312-3d55-11ea-8e9a-bc764e2007e4; Wed, 22 Jan 2020 20:23:54 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id w15so517542wru.4 for ; Wed, 22 Jan 2020 12:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ljuvtGQ8FLfUz4xqMnHKyZjGxy69y+jnVAsAFm6RVds=; b=gtWqCrbHnArBT6pIE/e3Y59E1lIcOgMjtNLGL1C7YC42YtP68AF5M4BX6OCuElrzDZ Hrf/QYX18PFyL/bWd8GgoXfky6CXRkPqGZbmXgJ8kx7K5FH0i3aXpi3BYSAwW6+QdqDB eRQhsk/PYzUzkbEEV/TLKOHi10fDaCrESQDdJncT5TgyMIX4Ke2ZcV9gIZ5oLb5FUfYv yBtK0iMqxC10cyTQu8CsBulBx4JtLodzGHUJE20mN6iWDAUYzb7U9mk+LAZJqLZWXdWU Ba71w9stZVz5OJ5HtYKNqF16AoJIWLkgADxtW92ZoDBA70lFwfNkX6RIVv0PLJswqF1H OHIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ljuvtGQ8FLfUz4xqMnHKyZjGxy69y+jnVAsAFm6RVds=; b=EcaGVcGtkZWB8BA2wyKtOIQ7ancTGx8X+nSTNiE32ASY17EUFYG4esB0gWjIPL31ax CwbjlYM6WibuQGpPf/hQ0GW1gSDZe5DxetjnIWtdGR3OyHhHd9qT/YeJqB87GZpugmUW NVkmgZTPJT9c2S+161ilGZLvx7s/E+weXGZZrVQgi3nGUdCF+vjjIDtBB9oO1dTS+TOd 6o8ZUItXmK9MqQ6KjW/pjd/9kYinX36fH8Ykkrpw7h1olc8QcgShc0qIwyGwYZHMezdM QA3x8FrjsSKgZb22BAtu7ziEuUX3R2hDffyr4QhCV8LZHtA5BRZvpiFkDPQy/OBF5G96 tdHQ== X-Gm-Message-State: APjAAAX3xPia5PziEnOksEpIvn3Fa+/0TFaSwfKUE7gg3M/yWr2qqvzX cFFMVRCAQTaL0kI4YLs54futBWWn7MPifQ== X-Google-Smtp-Source: APXvYqxPFih+zc1HHE4XDSBA6Wgr59+EAa8ucv5Qi9jgZF14d9ZZt7xwP2/sOF8TCZ+dbKmIGZUe2w== X-Received: by 2002:adf:ea05:: with SMTP id q5mr12536429wrm.48.1579724633088; Wed, 22 Jan 2020 12:23:53 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:52 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:43 +0000 Message-Id: <20200122202343.5703-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 7/7] x86/hyperv: setup VP assist page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation. Signed-off-by: Wei Liu --- v4: 1. Use private.h 2. Prevent leak v3: 1. Use xenheap page 2. Drop set_vp_assist v2: 1. Use HV_HYP_PAGE_SHIFT instead --- xen/arch/x86/guest/hyperv/hyperv.c | 26 ++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 27 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 085e646dc6..89a8f316b2 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -32,6 +32,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); static uint64_t generate_guest_id(void) { @@ -142,15 +143,40 @@ static void setup_hypercall_pcpu_arg(void) this_cpu(hv_vp_index) = vp_index_msr; } +static void setup_vp_assist(void) +{ + void *mapping; + uint64_t val; + + mapping = this_cpu(hv_vp_assist); + + if ( !mapping ) + { + mapping = alloc_xenheap_page(); + if ( !mapping ) + panic("Failed to allocate vp_assist page for CPU%u\n", + smp_processor_id()); + + clear_page(mapping); + this_cpu(hv_vp_assist) = mapping; + } + + val = (virt_to_mfn(mapping) << HV_HYP_PAGE_SHIFT) + | HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); +} + static void __init setup(void) { setup_hypercall_page(); setup_hypercall_pcpu_arg(); + setup_vp_assist(); } static void ap_setup(void) { setup_hypercall_pcpu_arg(); + setup_vp_assist(); } static const struct hypervisor_ops ops = { diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index da70990401..af419e9d4b 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -26,5 +26,6 @@ DECLARE_PER_CPU(void *, hv_pcpu_input_arg); DECLARE_PER_CPU(unsigned int, hv_vp_index); +DECLARE_PER_CPU(void *, hv_vp_assist); #endif /* __XEN_HYPERV_PRIVIATE_H__ */