[tip:x86/platform] x86/hyper-v: Make hv_do_hypercall() inline

2017-08-10 Thread tip-bot for Vitaly Kuznetsov
Commit-ID:  fc53662f13b889a5a1c069e79ee1e3d4534df132
Gitweb: http://git.kernel.org/tip/fc53662f13b889a5a1c069e79ee1e3d4534df132
Author: Vitaly Kuznetsov 
AuthorDate: Wed, 2 Aug 2017 18:09:14 +0200
Committer:  Ingo Molnar 
CommitDate: Thu, 10 Aug 2017 16:50:22 +0200

x86/hyper-v: Make hv_do_hypercall() inline

We have only three call sites for hv_do_hypercall() and we're going to
change HVCALL_SIGNAL_EVENT to doing fast hypercall so we can inline this
function for optimization.

Hyper-V top level functional specification states that r9-r11 registers
and flags may be clobbered by the hypervisor during hypercall and with
inlining this is somewhat important, add the clobbers.

Signed-off-by: Vitaly Kuznetsov 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Stephen Hemminger 
Cc: Andy Lutomirski 
Cc: Haiyang Zhang 
Cc: Jork Loeser 
Cc: K. Y. Srinivasan 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Simon Xiao 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: de...@linuxdriverproject.org
Link: http://lkml.kernel.org/r/20170802160921.21791-3-vkuzn...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/hyperv/hv_init.c   | 54 -
 arch/x86/include/asm/mshyperv.h | 40 ++
 drivers/hv/connection.c |  2 ++
 include/linux/hyperv.h  |  1 -
 4 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 5b882cc..691603e 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -75,7 +75,8 @@ static struct clocksource hyperv_cs_msr = {
.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void *hypercall_pg;
+void *hv_hypercall_pg;
+EXPORT_SYMBOL_GPL(hv_hypercall_pg);
 struct clocksource *hyperv_cs;
 EXPORT_SYMBOL_GPL(hyperv_cs);
 
@@ -102,15 +103,15 @@ void hyperv_init(void)
guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
 
-   hypercall_pg  = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
-   if (hypercall_pg == NULL) {
+   hv_hypercall_pg  = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
+   if (hv_hypercall_pg == NULL) {
wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
return;
}
 
rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
hypercall_msr.enable = 1;
-   hypercall_msr.guest_physical_address = vmalloc_to_pfn(hypercall_pg);
+   hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
 
/*
@@ -170,51 +171,6 @@ void hyperv_cleanup(void)
 }
 EXPORT_SYMBOL_GPL(hyperv_cleanup);
 
-/*
- * hv_do_hypercall- Invoke the specified hypercall
- */
-u64 hv_do_hypercall(u64 control, void *input, void *output)
-{
-   u64 input_address = (input) ? virt_to_phys(input) : 0;
-   u64 output_address = (output) ? virt_to_phys(output) : 0;
-#ifdef CONFIG_X86_64
-   u64 hv_status = 0;
-
-   if (!hypercall_pg)
-   return (u64)ULLONG_MAX;
-
-   __asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8");
-   __asm__ __volatile__("call *%3" : "=a" (hv_status) :
-"c" (control), "d" (input_address),
-"m" (hypercall_pg));
-
-   return hv_status;
-
-#else
-
-   u32 control_hi = control >> 32;
-   u32 control_lo = control & 0x;
-   u32 hv_status_hi = 1;
-   u32 hv_status_lo = 1;
-   u32 input_address_hi = input_address >> 32;
-   u32 input_address_lo = input_address & 0x;
-   u32 output_address_hi = output_address >> 32;
-   u32 output_address_lo = output_address & 0x;
-
-   if (!hypercall_pg)
-   return (u64)ULLONG_MAX;
-
-   __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
- "=a"(hv_status_lo) : "d" (control_hi),
- "a" (control_lo), "b" (input_address_hi),
- "c" (input_address_lo), "D"(output_address_hi),
- "S"(output_address_lo), "m" (hypercall_pg));
-
-   return hv_status_lo | ((u64)hv_status_hi << 32);
-#endif /* !x86_64 */
-}
-EXPORT_SYMBOL_GPL(hv_do_hypercall);
-
 void hyperv_report_panic(struct pt_regs *regs)
 {
static bool panic_reported;
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index baea267..6fa5e34 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -168,6 +169,45 @@ 

[tip:x86/platform] x86/hyper-v: Make hv_do_hypercall() inline

2017-08-10 Thread tip-bot for Vitaly Kuznetsov
Commit-ID:  fc53662f13b889a5a1c069e79ee1e3d4534df132
Gitweb: http://git.kernel.org/tip/fc53662f13b889a5a1c069e79ee1e3d4534df132
Author: Vitaly Kuznetsov 
AuthorDate: Wed, 2 Aug 2017 18:09:14 +0200
Committer:  Ingo Molnar 
CommitDate: Thu, 10 Aug 2017 16:50:22 +0200

x86/hyper-v: Make hv_do_hypercall() inline

We have only three call sites for hv_do_hypercall() and we're going to
change HVCALL_SIGNAL_EVENT to doing fast hypercall so we can inline this
function for optimization.

Hyper-V top level functional specification states that r9-r11 registers
and flags may be clobbered by the hypervisor during hypercall and with
inlining this is somewhat important, add the clobbers.

Signed-off-by: Vitaly Kuznetsov 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Stephen Hemminger 
Cc: Andy Lutomirski 
Cc: Haiyang Zhang 
Cc: Jork Loeser 
Cc: K. Y. Srinivasan 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Simon Xiao 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: de...@linuxdriverproject.org
Link: http://lkml.kernel.org/r/20170802160921.21791-3-vkuzn...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/hyperv/hv_init.c   | 54 -
 arch/x86/include/asm/mshyperv.h | 40 ++
 drivers/hv/connection.c |  2 ++
 include/linux/hyperv.h  |  1 -
 4 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 5b882cc..691603e 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -75,7 +75,8 @@ static struct clocksource hyperv_cs_msr = {
.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void *hypercall_pg;
+void *hv_hypercall_pg;
+EXPORT_SYMBOL_GPL(hv_hypercall_pg);
 struct clocksource *hyperv_cs;
 EXPORT_SYMBOL_GPL(hyperv_cs);
 
@@ -102,15 +103,15 @@ void hyperv_init(void)
guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
 
-   hypercall_pg  = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
-   if (hypercall_pg == NULL) {
+   hv_hypercall_pg  = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
+   if (hv_hypercall_pg == NULL) {
wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
return;
}
 
rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
hypercall_msr.enable = 1;
-   hypercall_msr.guest_physical_address = vmalloc_to_pfn(hypercall_pg);
+   hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
 
/*
@@ -170,51 +171,6 @@ void hyperv_cleanup(void)
 }
 EXPORT_SYMBOL_GPL(hyperv_cleanup);
 
-/*
- * hv_do_hypercall- Invoke the specified hypercall
- */
-u64 hv_do_hypercall(u64 control, void *input, void *output)
-{
-   u64 input_address = (input) ? virt_to_phys(input) : 0;
-   u64 output_address = (output) ? virt_to_phys(output) : 0;
-#ifdef CONFIG_X86_64
-   u64 hv_status = 0;
-
-   if (!hypercall_pg)
-   return (u64)ULLONG_MAX;
-
-   __asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8");
-   __asm__ __volatile__("call *%3" : "=a" (hv_status) :
-"c" (control), "d" (input_address),
-"m" (hypercall_pg));
-
-   return hv_status;
-
-#else
-
-   u32 control_hi = control >> 32;
-   u32 control_lo = control & 0x;
-   u32 hv_status_hi = 1;
-   u32 hv_status_lo = 1;
-   u32 input_address_hi = input_address >> 32;
-   u32 input_address_lo = input_address & 0x;
-   u32 output_address_hi = output_address >> 32;
-   u32 output_address_lo = output_address & 0x;
-
-   if (!hypercall_pg)
-   return (u64)ULLONG_MAX;
-
-   __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
- "=a"(hv_status_lo) : "d" (control_hi),
- "a" (control_lo), "b" (input_address_hi),
- "c" (input_address_lo), "D"(output_address_hi),
- "S"(output_address_lo), "m" (hypercall_pg));
-
-   return hv_status_lo | ((u64)hv_status_hi << 32);
-#endif /* !x86_64 */
-}
-EXPORT_SYMBOL_GPL(hv_do_hypercall);
-
 void hyperv_report_panic(struct pt_regs *regs)
 {
static bool panic_reported;
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index baea267..6fa5e34 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -168,6 +169,45 @@ void hv_remove_crash_handler(void);
 
 #if IS_ENABLED(CONFIG_HYPERV)
 extern struct clocksource *hyperv_cs;
+extern void *hv_hypercall_pg;
+
+static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
+{
+   u64 input_address = input ? virt_to_phys(input) : 0;
+   u64 output_address = output ?