Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3361234imm; Mon, 4 Jun 2018 02:11:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKa3PuKKeeRtFuMgGKZWOvVnL0Fnhch9IIeIwAxu5uCTeA0JPMrdQH7A4vc31mn1mlpQN+M X-Received: by 2002:a17:902:22cc:: with SMTP id o12-v6mr21735986plg.38.1528103467559; Mon, 04 Jun 2018 02:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528103467; cv=none; d=google.com; s=arc-20160816; b=VJ7Ir6UecKgET857kYFOwC9D/m5aLbUbMxFAZV7ZtDgZEY25QWnci6x5tSbG1ZIuOt GNSKwvEKLvKOQ48i3cZ5+Rovpp6UocbrBRw7/dyJzuEwNHbK+3/y3dL8i0tr+mselV5d s5jeT65UzrmOmSE/1ocjJ33uQiV4ip2JBMwryDm9/lGQg75C4RajQO7m67g7vc/mdFtD 1093Qf6sAphMZNVdRAzeusasJx+HlQ5fD/tmGPZlcPlDoYVCrT5vnETdS3aWEPZajg0T QWjHNhpLS+u41syfwAFHxoR/U+hAzd9O0aZEnbaKmKznBQup63sFybIuiwHOea31RfIx DrIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:mime-version:content-transfer-encoding :spamdiagnosticoutput:content-language:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:subject:cc :from:dkim-signature:arc-authentication-results; bh=T8ZtXFrUWGQOLoSLKxZoj/tFsGm0wLtOE/3wbnVwT6A=; b=W0cdqfJEbWkeDQJjNqnneZ+cRHEzCSXvwoIchMWDaQTNIThgRor427OclILjyom2By g0waLDOh6ee0l9T1RqIt7FE6EBgZV0IUmDabOxTW5DDRx716gba8NTxP0EKZXe4uspDd AsK8evsw0DZgvfJDTK2JP8fcYBop1Ut/3HYTZOibYUadBTXReAhiIR7mASBy67wezpXJ 5rhIsh7VZi98fIK0k/mC/reUKYNInetltt6YJTvKP6HkC3j+OaEhlbrlxHraZlWUb4wq 2yGfzbjUFGXIZkDy+XGrXDO7gQh9vO+wJnQA0XJEyUqUizP7nTujPXBPnJNmqky+WES7 AF5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=cvEGtiAM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 127-v6si46562268pfe.49.2018.06.04.02.10.53; Mon, 04 Jun 2018 02:11:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=cvEGtiAM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752142AbeFDJIf (ORCPT + 99 others); Mon, 4 Jun 2018 05:08:35 -0400 Received: from mail-pu1apc01hn0229.outbound.protection.outlook.com ([104.47.126.229]:61441 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751933AbeFDJId (ORCPT ); Mon, 4 Jun 2018 05:08:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T8ZtXFrUWGQOLoSLKxZoj/tFsGm0wLtOE/3wbnVwT6A=; b=cvEGtiAMBsd4W9rHCDOAJe/H761KciR23/1OK/5+hoypkvNRjPWh7ZufA0yS4JOJDDP5DeYgqLYSUD2Mjb4996BUAGHEV4Gw3fu1AXM1ALPhVGhBpdcrFx7TY5UQUsd6EZbTgzVuuN2+Edzkegt8ClWsO2Jnj2iCzAPf1DE9tAQ= Received: from SG2P15301MB0062.APCP153.PROD.OUTLOOK.COM (10.170.136.18) by SG2P15301MB0014.APCP153.PROD.OUTLOOK.COM (10.170.135.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.841.11; Mon, 4 Jun 2018 09:08:24 +0000 Received: from SG2P15301MB0062.APCP153.PROD.OUTLOOK.COM ([fe80::1cae:4bd:cf5d:6e8d]) by SG2P15301MB0062.APCP153.PROD.OUTLOOK.COM ([fe80::1cae:4bd:cf5d:6e8d%5]) with mapi id 15.20.0841.011; Mon, 4 Jun 2018 09:08:23 +0000 From: Tianyu Lan CC: Tianyu Lan , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "pbonzini@redhat.com" , "rkrcmar@redhat.com" , "devel@linuxdriverproject.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "vkuznets@redhat.com" Subject: [RFC Patch 1/3] X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall support Thread-Topic: [RFC Patch 1/3] X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall support Thread-Index: AQHT++OW1TQj7xYFtUGQsOkMiGidAQ== Date: Mon, 4 Jun 2018 09:08:23 +0000 Message-ID: <20180604090749.489-2-Tianyu.Lan@microsoft.com> References: <20180604090749.489-1-Tianyu.Lan@microsoft.com> In-Reply-To: <20180604090749.489-1-Tianyu.Lan@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Tianyu.Lan@microsoft.com; x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;SG2P15301MB0014;7:b+aeClZjUUn3HkGsK7Nm55O2zCdggmdv742iipGboN62rwBCZKngnnX4aVgSPAVH/Vc9D9Yqq+aJC4t5qOwWHCFqVQzIJf+1j/Dr9fBUQZ+vwL2IepRetPcvb2URGPJGvTcugYpBI3iJ9v0/rTTr2djukTpNyAb7u8XbW5DWP6CLjtPSXebF9VNT7bPFHJaEgFJ/1tIYWYNRV93nTNEtUrFxTIE3kdX/fApAE+/8iZ0P8LgZ6PtStY4ZLtsi4Gws;20:kPAcNStUzupo2g33bwEPUlcOPnAcKguVMSqjSAiGPM3kILEHpQ0l/Aqs/Bf9rueFFnL/WHj/g7mrZtuRggTtclIRCQ04jYsBAvrGQ1TTVbBTQGgHOYhagVMFtyNrNavJ75SAUg++Ppl0tF/tfMCJ8KvL/MEC+DSuGIfHshRffTg= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(2017052603328)(7193020);SRVR:SG2P15301MB0014; x-ms-traffictypediagnostic: SG2P15301MB0014: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:SG2P15301MB0014;BCL:0;PCL:0;RULEID:;SRVR:SG2P15301MB0014; x-forefront-prvs: 069373DFB6 x-forefront-antispam-report: SFV:SPM;SFS:(10019020)(6029001)(39380400002)(39860400002)(346002)(396003)(366004)(376002)(199004)(189003)(36756003)(305945005)(5660300001)(10090500001)(97736004)(6436002)(7416002)(2900100001)(68736007)(3846002)(11346002)(446003)(6116002)(7736002)(25786009)(1076002)(476003)(486006)(5250100002)(2616005)(1671002)(478600001)(72206003)(26005)(105586002)(106356001)(86612001)(575784001)(86362001)(2906002)(99286004)(22452003)(316002)(54906003)(3280700002)(102836004)(6512007)(3660700001)(59246006)(59450400001)(76176011)(14454004)(6506007)(53936002)(8936002)(6486002)(66066001)(81166006)(81156014)(8676002)(10290500003)(4326008)(109986005)(22906009)(49343001)(2004002);DIR:OUT;SFP:1501;SCL:5;SRVR:SG2P15301MB0014;H:SG2P15301MB0062.APCP153.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: kctgbLtskJw+NEdAN7MVTOs4xMxPCkm5oxrWGPH4SKRm/dyTCKjBXX6rM5eJe2D5VdDAVOpYbbLCSvQxbF+FCobqF0PNd9R48mNAygp7cc3HF1Gk0CZkR/rtB7Th3GoFuMe6izcqRKSKvAn/HU6+S7YOPesj/DIl38kCoZ0erFnxtjokXnsTtqrwyaFBVGzq0N0XmAGCN1yiOe1pLqXKNOfaTocLPl/6VfcS5mKlJDR8IuOCDqV5RucMNz5y/mX8Fv7zUNQsiQt3JhiOQGeIO5Kxa0bffnxT6ZP5gPaPmzv5ZrU/NXRdaYZQCJQPW53WMynp2kPA/qWYz2nBXYT4awYQCUyuPPuxp85vtpOqCKd9EpSxE919JXH8FsVwexBVkKFYID3j24cd6qxJ7nJaTG+4TZQ1oYx2Y/leKASk9xU= spamdiagnosticoutput: 1:22 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: aac85dd3-1493-4301-9b0a-08d5c9fab9db X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: aac85dd3-1493-4301-9b0a-08d5c9fab9db X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Jun 2018 09:08:23.4977 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2P15301MB0014 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hyper-V provides a pv hypercall HvFlushGuestPhysicalAddressSpace to flush nested VM address space mapping in l1 hypervisor and it's to reduce overhea= d of flushing ept tlb among vcpus. This patch is to implement it. Signed-off-by: Lan Tianyu --- arch/x86/hyperv/Makefile | 2 +- arch/x86/hyperv/nested.c | 64 ++++++++++++++++++++++++++++++++++= ++++ arch/x86/include/asm/hyperv-tlfs.h | 8 +++++ arch/x86/include/asm/mshyperv.h | 2 ++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 arch/x86/hyperv/nested.c diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile index b173d404e3df..b21ee65c4101 100644 --- a/arch/x86/hyperv/Makefile +++ b/arch/x86/hyperv/Makefile @@ -1,2 +1,2 @@ -obj-y :=3D hv_init.o mmu.o +obj-y :=3D hv_init.o mmu.o nested.o obj-$(CONFIG_X86_64) +=3D hv_apic.o diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c new file mode 100644 index 000000000000..17f7c288eccc --- /dev/null +++ b/arch/x86/hyperv/nested.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Hyper-V nested virtualization code. + * + * Copyright (C) 2018, Microsoft, Inc. + * + * Author : Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as publishe= d + * 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, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + * + */ + + +#include +#include +#include +#include + +int hyperv_flush_guest_mapping(u64 as) +{ + struct hv_guest_mapping_flush **flush_pcpu; + struct hv_guest_mapping_flush *flush; + u64 status =3D U64_MAX; + unsigned long flags; + int ret =3D -EFAULT; + + if (!hv_hypercall_pg) + goto fault; + + local_irq_save(flags); + + flush_pcpu =3D (struct hv_guest_mapping_flush **) + this_cpu_ptr(hyperv_pcpu_input_arg); + + flush =3D *flush_pcpu; + + if (unlikely(!flush)) { + local_irq_restore(flags); + goto fault; + } + + flush->address_space =3D as; + flush->flags =3D 0; + + status =3D hv_do_hypercall(HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE, + flush, NULL); + local_irq_restore(flags); + + if (!(status & HV_HYPERCALL_RESULT_MASK)) + ret =3D 0; + +fault: + return ret; +} +EXPORT_SYMBOL_GPL(hyperv_flush_guest_mapping); diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hype= rv-tlfs.h index b8c89265baf0..53bbeb08faea 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -309,6 +309,7 @@ struct ms_hyperv_tsc_page { #define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106 =20 /* Nested features (CPUID 0x4000000A) EAX */ +#define HV_X64_NESTED_GUSET_MAPPING_FLUSH BIT(18) #define HV_X64_NESTED_MSR_BITMAP BIT(19) =20 struct hv_reenlightenment_control { @@ -350,6 +351,7 @@ struct hv_tsc_emulation_status { #define HVCALL_SEND_IPI_EX 0x0015 #define HVCALL_POST_MESSAGE 0x005c #define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af =20 #define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001 #define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12 @@ -741,6 +743,12 @@ struct ipi_arg_ex { struct hv_vpset vp_set; }; =20 +/* HvFlushGuestPhysicalAddressSpace hypercalls */ +struct hv_guest_mapping_flush { + u64 address_space; + u64 flags; +}; + /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */ struct hv_tlb_flush { u64 address_space; diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyper= v.h index 3cd14311edfa..a6a615b49876 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -302,6 +302,7 @@ void hyperv_reenlightenment_intr(struct pt_regs *regs); void set_hv_tscchange_cb(void (*cb)(void)); void clear_hv_tscchange_cb(void); void hyperv_stop_tsc_emulation(void); +int hyperv_flush_guest_mapping(u64 as); =20 #ifdef CONFIG_X86_64 void hv_apic_init(void); @@ -321,6 +322,7 @@ static inline struct hv_vp_assist_page *hv_get_vp_assis= t_page(unsigned int cpu) { return NULL; } +static inline int hyperv_flush_guest_mapping(u64 as) { return -1; } #endif /* CONFIG_HYPERV */ =20 #ifdef CONFIG_HYPERV_TSCPAGE --=20 2.14.3