From patchwork Mon Aug 24 16:46:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 11733807 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 EFB69722 for ; Mon, 24 Aug 2020 17:13:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 B78FD2063A for ; Mon, 24 Aug 2020 17:13:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="a0U3lbAm"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PQXS/PX4"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="QBwwG7IA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B78FD2063A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/okv3p59V0X7cuqMIuVpaTXUvZEP+uw9qePAK+liLiQ=; b=a0U3lbAmXzdiZfXB4IeVy59J3 Wq4mI6YsgezgKwa74lQ64ILcCg4OkCYveYWK9VCMn4jjkxMjasr78VopYegnrC7axGlap8q1ppXZe daoRp4wc09ZP7+HlRw5iMbxecvc8R04N0vbR+BH3FLfwUX/FNFPbNyxJFn+k+8rJPgFsRSQFgWDO8 5RjNMWJgbqTbg1GPq5f+KC5dVJk7Y7hW58FUkgypA9ndf/EzPKN605zmTvh6RevrLv1TaHYSySivC Anpal6TOcB+czTfv6L4lyIKpdwlIVFVxEl1qy/dJuG/IUGORmQBGU2p6y+2VnheQdd5KBOonM043W GjnEz/Q7A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAFzk-0003iK-Ae; Mon, 24 Aug 2020 17:10:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAFze-0003ex-1A for linux-arm-kernel@merlin.infradead.org; Mon, 24 Aug 2020 17:10:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LHgTfSh2/H9zYVYFD/dOYfqhNAkUx8fqSOk4VlRqeqA=; b=PQXS/PX4IKN5JWS5dNSEJVf2ZK hJPOaVMs/hlzh32dA2jARrf18IlZOfkLNB5UGJ8PheoxCWoTRznJvWQGoKURswI5qU8JZpanxJiMc EngH75832di/GWSyQy/UkUAM6Ps57cswtiEqmTLK973dm/GTAZ4u+Xcbn5IIOVkOe1a9BZRQ0oeRI 35lpUy4vOk55ACss8TyE+IZKOeTo7X379BaCmcLS4G8wPpOgECOUHfcj0qtsCFtGHyGyqMumOqRrA 2LUDoYTtKI/eCH0fNKKDgRCGbqEJZ0V4VqSabYjM246E59VSh8MW+TvzIBKE7V8IckfM8pyt2wSH+ /XhLDVkg==; Received: from mail-dm6nam12on2128.outbound.protection.outlook.com ([40.107.243.128] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAFe2-0001wk-0j for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 16:48:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gdv8x8/WPQTVu+yOQylZtAbV7qsUmK8SHBUbdNioy2kQ7SWyNIlvmNJn7xwDw9g9g1UyxeP0PMQlkFLuYDmyPI3TaxyzJEgw7UPQcOOXf9uFI1OtiSHerpS/F5gU5lsExChDHWiN/xSpwNTmGnkEDgTdwr8tK/A3aJ67bD1dZHHgR0BNMsyKAl522i2IW+RuchL38Ys7lPoP3vsL/JB9nI4CkxkMBWtJyaMK5ux74ubiynJ3AEKkW13ERe0Cw8xCH+QhYWVvCUzI6rmiQGdGr3MFwt72NKDEVOcnPL7r2Rii13ktpAdDz+NdJyVchwHfPjGh12ey3fFNcXwLbYE8PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LHgTfSh2/H9zYVYFD/dOYfqhNAkUx8fqSOk4VlRqeqA=; b=lC+vIEMdh8UkxMcASBNuT56M0tQY9c86vbK/+XrfnbSyXok2uvNa9y8d/dPSK30iZqbOPKiRRM3ZsVrOjYY01ZNv6iYfAkkIfMxe4r8HTnv2LpTgGHvxYGzCaohcaZb7hUSdE4EKzqdgUUwpm+VMhxBsPsoxYz3D1NoABTLdDrlFKPLtbg7YiU/HdrNAOOzVK5VfWqAlubqoQuFKUDhSCnU8eN+KyNlFB1XPYLdLh1g3Mblb2Ng29uzBXcq2N8nTqrTU+r3kh1Ie+SkqKjoVEVV5lMX1jLSFXFkM7UdkxRechDjjwN319hLybX4LFXitjuOXOw7NKIiDPlZii7Qy8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LHgTfSh2/H9zYVYFD/dOYfqhNAkUx8fqSOk4VlRqeqA=; b=QBwwG7IA9giO4yspRudx2yRMLucV2myBefxCypFrs8j8/tykpimNxUHW4RAYQIFlwEWhPlfTHpIB6VPvg0g3qK6zNoE0CF4OoknNJ20pt5UiiDLU00AvvjNe5ADdG0/YDAW+ja2yVAMt5EBMxvoS7FlLzra4K76aGqj9UwI4hjc= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=microsoft.com; Received: from BN8PR21MB1281.namprd21.prod.outlook.com (2603:10b6:408:a2::19) by BN6PR21MB0753.namprd21.prod.outlook.com (2603:10b6:404:9c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.4; Mon, 24 Aug 2020 16:48:02 +0000 Received: from BN8PR21MB1281.namprd21.prod.outlook.com ([fe80::e0c9:2634:6fb1:5615]) by BN8PR21MB1281.namprd21.prod.outlook.com ([fe80::e0c9:2634:6fb1:5615%3]) with mapi id 15.20.3326.012; Mon, 24 Aug 2020 16:48:02 +0000 From: Michael Kelley To: will@kernel.org, ardb@kernel.org, arnd@arndb.de, catalin.marinas@arm.com, mark.rutland@arm.com, maz@kernel.org, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, wei.liu@kernel.org, vkuznets@redhat.com, kys@microsoft.com Subject: [PATCH v7 07/10] arm64: hyperv: Initialize hypervisor on boot Date: Mon, 24 Aug 2020 09:46:20 -0700 Message-Id: <1598287583-71762-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598287583-71762-1-git-send-email-mikelley@microsoft.com> References: <1598287583-71762-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: CO2PR04CA0145.namprd04.prod.outlook.com (2603:10b6:104::23) To BN8PR21MB1281.namprd21.prod.outlook.com (2603:10b6:408:a2::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by CO2PR04CA0145.namprd04.prod.outlook.com (2603:10b6:104::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.25 via Frontend Transport; Mon, 24 Aug 2020 16:47:52 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [131.107.159.16] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9294b233-cdce-4fe6-afe5-08d8484d7275 X-MS-TrafficTypeDiagnostic: BN6PR21MB0753: X-MS-Exchange-Transport-Forked: True X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nrQPtAK7Jsu8sCnVc4NSVYPNXjIsGjwUWeG2l4gznLVHH6Tj6vv+lf9WYN2jRsIdb2eQjOKuMwXVt8VNUY4a3NZFPFjKy6Mntc9+HD/v+STXe8u1tIMjiDB7vXSJh31oFAVkyGpOHxy5HToT5BghxNtI6vRAWMFnQHQi2S87rUXi6fc/YtPIIeHbGAz7+s3ExxJ9gIY7Zj0ndunbZJq+aldrfxskwb3rscIs2ubVnt1Dv7re7xzKi0Cx0/Ky1woiv1/xaqpNoPp3cvN8pPJvcYbrEOOMg/KhY3Ft0A8YWjw0VV48Wqpm/pDlTW6HLOKfaR+7bWwZ50xA5xZmSXXZlgKREQrhP4FJRN0DWC4GPW6RvjYv6OR3YkFv/XOHsQ5h X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN8PR21MB1281.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(366004)(376002)(396003)(346002)(8676002)(86362001)(2616005)(956004)(2906002)(6486002)(8936002)(52116002)(10290500003)(5660300002)(66946007)(16576012)(66556008)(4326008)(6636002)(316002)(36756003)(186003)(82950400001)(478600001)(26005)(6666004)(66476007)(82960400001)(83380400001)(7416002)(921003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: p4lJb7dkjAc8d0RMuPlTCwKQzCLM3zmHvyPzgCZFgYg/UWaW/6trianOYiOMePHrCl1pFjMI+Bu4/K0nJPmTHsMP8Cp0LWj6xHyJv74haahVQ9qkNXGW+dGeGfCdPJeR91QSaAFmVBJ/E6ScdoGNDSszxNQEcRz9yDX8Z+OhVFOqkFq5ftmyDxCojG7gm82VJMV0BRa8/e67w9EV6mDv7MZQR5SoAxYAlqyhAArWT+Vmq0TKijSbqecdxawiRJcr24yXc1FIF+Kik3xRNomAw+y5n+ZQy5JBoUZrObnXNnSDiGMJPTWmTsNQ/43QWbt934q1My6JEBkhShesr4L8DKccydgF/92sRm/e6qvnPWOYA2MUdEC9/kk2srdvyYaFp9ovA9He+TcL71w6Oc7pm5a+nHYVzBuoLdRfoVhLYDz+Psf8Uq0+ZzGwwqJoZpUSBTbhjwER44kiznUsxqTuQKB6/oo+pQkKUX6MFAyJrLlVMw58Lw4/K1aqH/CfmQkq0gjwDajaI17vwGy5sBXpKLaaOpepYtSjI/khSXmrCe8a2ynpYNPUKYO04doPBbN2Rz/1xr197uXSamFNwcbwcYArrcrkAHuF/y8rMswirNX7mnXgMF2S8jarbU/rMzdV5CBsIU9KGwm19hS+9Sl15A== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9294b233-cdce-4fe6-afe5-08d8484d7275 X-MS-Exchange-CrossTenant-AuthSource: BN8PR21MB1281.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2020 16:47:54.8169 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: N7mH9/PkUYdE8WBambmUTI3VJrllwwXNgyce+55+MmYeByFgbhbRNYl4SuUPrf6BihQP69qZ2+KpUl1nHn0TQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR21MB0753 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_174830_161250_96579D02 X-CRM114-Status: GOOD ( 21.09 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.243.128 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [40.107.243.128 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 1.3 RCVD_ILLEGAL_IP Received: contains illegal IP address -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay -1.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sunilmut@microsoft.com, boqun.feng@gmail.com, mikelley@microsoft.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add ARM64-specific code to initialize the Hyper-V hypervisor when booting as a guest VM. Provide functions and data structures indicating hypervisor status that are needed by VMbus driver. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley --- arch/arm64/hyperv/hv_core.c | 144 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/arch/arm64/hyperv/hv_core.c b/arch/arm64/hyperv/hv_core.c index 966d815..831a69c 100644 --- a/arch/arm64/hyperv/hv_core.c +++ b/arch/arm64/hyperv/hv_core.c @@ -18,10 +18,41 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include +#include +#include +static bool hyperv_initialized; + +struct ms_hyperv_info ms_hyperv __ro_after_init; +EXPORT_SYMBOL_GPL(ms_hyperv); + +u32 *hv_vp_index; +EXPORT_SYMBOL_GPL(hv_vp_index); + +u32 hv_max_vp_index; +EXPORT_SYMBOL_GPL(hv_max_vp_index); + +static int hv_cpu_init(unsigned int cpu) +{ + u64 msr_vp_index; + + msr_vp_index = hv_get_vpreg(HV_REGISTER_VPINDEX); + + hv_vp_index[smp_processor_id()] = msr_vp_index; + + if (msr_vp_index > hv_max_vp_index) + hv_max_vp_index = msr_vp_index; + + return 0; +} /* * Functions for allocating and freeing memory with size and @@ -67,6 +98,107 @@ void hv_free_hyperv_page(unsigned long addr) /* + * This function is invoked via the ACPI clocksource probe mechanism. We + * don't actually use any values from the ACPI GTDT table, but we set up + * the Hyper-V synthetic clocksource and do other initialization for + * interacting with Hyper-V the first time. Using early_initcall to invoke + * this function is too late because interrupts are already enabled at that + * point, and hv_init_clocksource() must run before interrupts are enabled. + * + * 1. Setup the guest ID. + * 2. Get features and hints info from Hyper-V + * 3. Setup per-cpu VP indices. + * 4. Initialize the Hyper-V clocksource. + */ + +static int __init hyperv_init(struct acpi_table_header *table) +{ + struct hv_get_vp_registers_output result; + u32 a, b, c, d; + u64 guest_id; + int i, cpuhp; + + /* + * If we're in a VM on Hyper-V, the ACPI hypervisor_id field will + * have the string "MsHyperV". + */ + if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8)) + return -EINVAL; + + /* Setup the guest ID */ + guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0); + hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id); + + /* Get the features and hints from Hyper-V */ + hv_get_vpreg_128(HV_REGISTER_FEATURES, &result); + ms_hyperv.features = result.as32.a; + ms_hyperv.misc_features = result.as32.c; + + hv_get_vpreg_128(HV_REGISTER_ENLIGHTENMENTS, &result); + ms_hyperv.hints = result.as32.a; + + pr_info("Hyper-V: Features 0x%x, hints 0x%x, misc 0x%x\n", + ms_hyperv.features, ms_hyperv.hints, ms_hyperv.misc_features); + + /* + * If Hyper-V has crash notifications, set crash_kexec_post_notifiers + * so that we will report the panic to Hyper-V before running kdump. + */ + if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) + crash_kexec_post_notifiers = true; + + /* Get information about the Hyper-V host version */ + hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION, &result); + a = result.as32.a; + b = result.as32.b; + c = result.as32.c; + d = result.as32.d; + pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n", + b >> 16, b & 0xFFFF, a, d & 0xFFFFFF, c, d >> 24); + + /* Allocate and initialize percpu VP index array */ + hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), + GFP_KERNEL); + if (!hv_vp_index) + return -ENOMEM; + + for (i = 0; i < num_possible_cpus(); i++) + hv_vp_index[i] = VP_INVAL; + + cpuhp = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, + "arm64/hyperv_init:online", hv_cpu_init, NULL); + if (cpuhp < 0) + goto free_vp_index; + + hv_init_clocksource(); + if (hv_stimer_alloc()) + goto remove_cpuhp_state; + + hyperv_initialized = true; + return 0; + +remove_cpuhp_state: + cpuhp_remove_state(cpuhp); +free_vp_index: + kfree(hv_vp_index); + hv_vp_index = NULL; + return -EINVAL; +} +TIMER_ACPI_DECLARE(hyperv, ACPI_SIG_GTDT, hyperv_init); + +/* + * This routine is called before kexec/kdump, it does the required cleanup. + */ +void hyperv_cleanup(void) +{ + /* Reset our OS id */ + hv_set_vpreg(HV_REGISTER_GUEST_OSID, 0); + +} +EXPORT_SYMBOL_GPL(hyperv_cleanup); + + +/* * hv_do_hypercall- Invoke the specified hypercall */ u64 hv_do_hypercall(u64 control, void *input, void *output) @@ -291,3 +423,15 @@ void hyperv_report_panic_msg(phys_addr_t pa, size_t size) (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG)); } EXPORT_SYMBOL_GPL(hyperv_report_panic_msg); + +bool hv_is_hyperv_initialized(void) +{ + return hyperv_initialized; +} +EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized); + +bool hv_is_hibernation_supported(void) +{ + return false; +} +EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);