From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752050AbdDHPSd (ORCPT ); Sat, 8 Apr 2017 11:18:33 -0400 Received: from mail-co1nam03on0093.outbound.protection.outlook.com ([104.47.40.93]:20766 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751466AbdDHPS1 (ORCPT ); Sat, 8 Apr 2017 11:18:27 -0400 From: KY Srinivasan To: Vitaly Kuznetsov , "devel@linuxdriverproject.org" , "x86@kernel.org" CC: "linux-kernel@vger.kernel.org" , "Haiyang Zhang" , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Steven Rostedt , "Jork Loeser" Subject: RE: [PATCH 2/7] x86/hyper-v: fast hypercall implementation Thread-Topic: [PATCH 2/7] x86/hyper-v: fast hypercall implementation Thread-Index: AQHSr5HnDkq6xMXYXUiph734o9KEJKG7k79g Date: Sat, 8 Apr 2017 15:18:20 +0000 Message-ID: References: <20170407112701.17157-1-vkuznets@redhat.com> <20170407112701.17157-3-vkuznets@redhat.com> In-Reply-To: <20170407112701.17157-3-vkuznets@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [2601:600:8c00:1040:bdd6:d020:3aef:2c08] x-microsoft-exchange-diagnostics: 1;BY1PR03MB1419;7:8UvrX1L05ZAo9mmU3hZt8pejDs6O49MFnZP1sGGvuB1FazOWsOveN43twhdgkx4KJfw9ad9avurlDE+aPJHHL1z+yxpENeV7y8gZW55wFQkYtc6tu+ShzdY5PuHqeG7PXdCNnoo+VoGMJOe2O7gBs45UexSiRo+2trWrNzf21KZ4dikl6J6+7WwPZRmZzbpWx4VTKs9iYQGwp3NuTEXkuL+rXaJTUGf1oiawwR0RydeAqglUg4M0TrKg+ftkzI58p19oBzfImWIYDDl0PVV9WKhYT9o8lS/ZRLOCdwZbJXZVyfKe8Z9nWSKfDq2G6pJSNogbO0CJtRMXWYUaMvVjLs7A1ddUxPB2W5rc5fPRykY= x-ms-office365-filtering-correlation-id: 64c62a3e-2504-46e1-d104-08d47e927d8e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081)(201702281549075);SRVR:BY1PR03MB1419; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123564025)(20161123562025)(20161123555025)(6072148);SRVR:BY1PR03MB1419;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1419; x-forefront-prvs: 0271483E06 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39450400003)(39860400002)(39840400002)(39850400002)(39400400002)(39410400002)(13464003)(377454003)(53936002)(189998001)(6246003)(2906002)(7736002)(5005710100001)(74316002)(77096006)(107886003)(9686003)(4326008)(3280700002)(3660700001)(2950100002)(6436002)(55016002)(99286003)(2501003)(7696004)(25786009)(6506006)(38730400002)(76176999)(305945005)(10290500002)(33656002)(54356999)(122556002)(10090500001)(2900100001)(5660300001)(8990500004)(8936002)(86612001)(81166006)(86362001)(2201001)(6116002)(102836003)(8676002)(50986999);DIR:OUT;SFP:1102;SCL:1;SRVR:BY1PR03MB1419;H:BN6PR03MB2481.namprd03.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Apr 2017 15:18:20.1638 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR03MB1419 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id v38FIbEp001952 > -----Original Message----- > From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com] > Sent: Friday, April 7, 2017 4:27 AM > To: devel@linuxdriverproject.org; x86@kernel.org > Cc: linux-kernel@vger.kernel.org; KY Srinivasan ; > Haiyang Zhang ; Stephen Hemminger > ; Thomas Gleixner ; Ingo > Molnar ; H. Peter Anvin ; Steven > Rostedt ; Jork Loeser > Subject: [PATCH 2/7] x86/hyper-v: fast hypercall implementation > > Hyper-V supports 'fast' hypercalls when all parameters are passed through > registers. Implement an inline version of a simpliest of these calls: > hypercall with one 8-byte input and no output. > > Proper hypercall input interface (struct hv_hypercall_input) definition is > added as well. > > Signed-off-by: Vitaly Kuznetsov > --- > arch/x86/include/asm/mshyperv.h | 37 > +++++++++++++++++++++++++++++++++++++ > arch/x86/include/uapi/asm/hyperv.h | 19 +++++++++++++++++++ > 2 files changed, 56 insertions(+) > > diff --git a/arch/x86/include/asm/mshyperv.h > b/arch/x86/include/asm/mshyperv.h > index 331e834..9a5f58b 100644 > --- a/arch/x86/include/asm/mshyperv.h > +++ b/arch/x86/include/asm/mshyperv.h > @@ -216,6 +216,43 @@ static inline u64 hv_do_hypercall(u64 control, void > *input, void *output) > #endif /* !x86_64 */ > } > > +/* Fast hypercall with 8 bytes of input and no output */ > +static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) > +{ > + union hv_hypercall_input control = {0}; Defining the hyper-call arguments on the stack can be problematic if CONFIG_VMAP_STACK is defined - since we are passing the guest physical address to the hypervisor, we cannot have the arguments straddle a page boundary. We have dealt with this issue currently by making sure the arguments are never on the stack via different means. Perhaps, we can allocate memory on a per-cpu basis that can be used for this purpose. In fact, this is what I have done for the hv_post_message hypercall. We can just rename that page and use it in all hypercalls - we can just allocate two pages on a per-CPU basis for this purpose (for input and output parameters). > + > + control.code = code; > + control.fast = 1; > +#ifdef CONFIG_X86_64 > + { > + u64 hv_status; > + > + __asm__ __volatile__("call *%3" > + : "=a" (hv_status) > + : "c" (control.as_uint64), "d" (input1), > + "m" (hv_hypercall_pg) > + : "cc", "r8", "%r9", "%r10", "%r11"); > + return hv_status; > + } > +#else > + { > + u32 hv_status_hi, hv_status_lo; > + > + __asm__ __volatile__ ("call *%6" > + : "=d"(hv_status_hi), > + "=a"(hv_status_lo) : > + "d" (control.as_uint32_hi), > + "a" (control.as_uint32_lo), > + "c" ((u32)input1), > + "b" ((u32)(input1 >> 32)), > + "m" (hv_hypercall_pg) > + : "cc"); > + > + return hv_status_lo | ((u64)hv_status_hi << 32); > + } > +#endif > +} > + > void hyperv_init(void); > void hyperv_report_panic(struct pt_regs *regs); > bool hv_is_hypercall_page_setup(void); > diff --git a/arch/x86/include/uapi/asm/hyperv.h > b/arch/x86/include/uapi/asm/hyperv.h > index 432df4b..c87e900 100644 > --- a/arch/x86/include/uapi/asm/hyperv.h > +++ b/arch/x86/include/uapi/asm/hyperv.h > @@ -256,6 +256,25 @@ > #define HV_PROCESSOR_POWER_STATE_C2 2 > #define HV_PROCESSOR_POWER_STATE_C3 3 > > +/* Hypercall interface */ > +union hv_hypercall_input { > + u64 as_uint64; > + struct { > + __u32 as_uint32_lo; > + __u32 as_uint32_hi; > + }; > + struct { > + __u64 code:16; > + __u64 fast:1; > + __u64 varhead_size:10; > + __u64 reserved1:5; > + __u64 rep_count:12; > + __u64 reserved2:4; > + __u64 rep_start:12; > + __u64 reserved3:4; > + }; > +}; > + > /* hypercall status code */ > #define HV_STATUS_SUCCESS 0 > #define HV_STATUS_INVALID_HYPERCALL_CODE 2 > -- > 2.9.3