From patchwork Tue Jul 20 14:57:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 12388481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00B84C636C8 for ; Tue, 20 Jul 2021 15:01:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C5546610CC for ; Tue, 20 Jul 2021 15:01:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5546610CC 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+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5FXhlKwSPcWYyqPoNO1cZqr8SXPXtQpYGgVfwRhVIFw=; b=nbMdtIj3gVszxf 7ghYhY4nWaZO2p0kx9tcJjxEMmyKGtEbyNgc1eyzuFmKTdBuarChQ+wNGxq9oGe1JaH2BsmDI/5Q9 SE38+wG2FyNhprVJ62LygK+EfoiUvyJ6bKTgfqKRatc+4XoulMa3gAzA0PzLdws6+iyc0oWdB7hmU BBq4qaCCcldyBABI111r0bT4LfOWngOFH3Vi2WAY2RD1L/E9odhq1zmZz5Te4PraXHPkK+c4MuAum JmyBPecFhJrJF140uGg2me3zLp47Mrz5tvsxa1VINVHY4IjSE368EvDSTblm7wj4RDfC2vANEwcfV Wfhm2axNgiahhjUAmBUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5rCN-00DImW-4r; Tue, 20 Jul 2021 14:58:19 +0000 Received: from mail-dm3nam07on2129.outbound.protection.outlook.com ([40.107.95.129] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5rBc-00DIXK-9I for linux-arm-kernel@lists.infradead.org; Tue, 20 Jul 2021 14:57:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VSl9huDf7d7b+aGy1glw+2cnTR+o4MGjpZsh2Jl3RkWzSTB67u4XTM5NMECwmAwxsL0ginEjzGn4chMOGkMhMF45bO+0wr24fObyLVJnXXtY/PYGR7EGj/hHwF3ewAVgzet9x369Dovu5jIjb4pqhJyg2aFwBG7cNJCf9cOQg7EWAtt2O5wL959d4bMaiIKjJySn3WWVs21MVP9jMLde776RoUC3I6HlK8XBJaGnKaRm+KZKuFCHUX3ARMPlmgLKDOy/DV2sEygD32LFCl9fRPrgFNwfulmyW13WviwmWnopNA8ge4ZaYKcX/gt9CW4sm/4lAkx2314SUY9vuy2hLw== 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=1HiU6XS82HAdj4fww7xmvbixCsaas4zL7arlWJnpwmY=; b=lRHF18iHm+8ranSkqKRgH+pzs2yWroI4FR475CVR5UwvYJyfpkQbEph+sNDaowREx54V07sSf2+9BizS8la+SlTtc2y9NleJAjU6JxP9AFBGOZMI5YjFElatHgLx50SNf7X0Ccf+398rQ4ce3qzef5eIb+IJDS5THkDxtxQey+TwKsEEpCc6K7q8PMyMSt7/rrguDOrrcPKQIavoxxjs8PgOKAkwkFgaKlhMEkLBm8UmUhzkTvkqG3cWXUndw68u869llChunakp4XHZqxGndPhS1gVW5vesgJy6RU/x+Hol2dDL3NONDI8jpeK3DH3FJRUktTHPPxeDSQjejRJu9g== 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=1HiU6XS82HAdj4fww7xmvbixCsaas4zL7arlWJnpwmY=; b=K0B5wtsLNTB6J9yj6CywetJu/CQj7ir7zVnNQW9qkUl+X2b3nh4IVBlz6iDWeY4azCam0XyCYFwA/pK37NkisyB//Rzw0xZT51o/jWIZ1s3Eu7STd7XrSVkKl0e2ttkkBenNdtWeQYZ9jjVww1Z/xkmFtBInwwDcZNLmL99RMUA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1514.namprd21.prod.outlook.com (2603:10b6:5:22d::11) by DM5PR2101MB0981.namprd21.prod.outlook.com (2603:10b6:4:a8::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.4; Tue, 20 Jul 2021 14:57:25 +0000 Received: from DM6PR21MB1514.namprd21.prod.outlook.com ([fe80::3505:fa47:39d0:6dc5]) by DM6PR21MB1514.namprd21.prod.outlook.com ([fe80::3505:fa47:39d0:6dc5%9]) with mapi id 15.20.4373.005; Tue, 20 Jul 2021 14:57:25 +0000 From: Michael Kelley To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-efi@vger.kernel.org, wei.liu@kernel.org, kys@microsoft.com, sthemmin@microsoft.com, ardb@kernel.org Cc: mikelley@microsoft.com Subject: [PATCH v11 3/5] arm64: hyperv: Initialize hypervisor on boot Date: Tue, 20 Jul 2021 07:57:01 -0700 Message-Id: <1626793023-13830-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1626793023-13830-1-git-send-email-mikelley@microsoft.com> References: <1626793023-13830-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MWHPR07CA0023.namprd07.prod.outlook.com (2603:10b6:300:116::33) To DM6PR21MB1514.namprd21.prod.outlook.com (2603:10b6:5:22d::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mhkdev.corp.microsoft.com (167.220.2.16) by MWHPR07CA0023.namprd07.prod.outlook.com (2603:10b6:300:116::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 14:57:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b8d6978-8505-4a94-db7d-08d94b8eaf8a X-MS-TrafficTypeDiagnostic: DM5PR2101MB0981: 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:2449; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cjZR65UjztKnY11MuSdKui8os7jbL3rtIq8I6OSqPjuIHuPpBsRK2HlHsNMYOba8wVCSty/+rq77oAJMhg6rtcugEg6RAuHvB3hOrwn0/jf5rUh968lagsEJ4tV9wDTboFgwobKPzwgBVuL80foRxsWzk9NHaT9clFGkivJv5OrcjWm28fvrRks+5KiIN6O0qjhP2ePvGaDC2qNuIYcc4FQ3BVTjDPm1JG1r8HDCHBfaGTN8kIWFBiqXnfM+kP52JIARHr+Wa0ZLpRsTs50aF9zzfrCFFXMICC62QkYhIEHS2gvFqWqNeyP2AWVclfYdoRd0flIpFGslvZxDj1SjRuUdFTxAPQensiomL45xgTTJADSBL2Yr3qyA09hMxgkLVsj2ljjqdV+Vhmugd8QzVKtVXaMKUcw6N0F5ydOSbxfivlE4Hc/oQkyzRkoMGahxDV58VpgIVNZyHS/MsMaZ9Q9Ygvd84vHse8oOP8EfGYE9QitCzMik9syl9vWJ6JQJBZPC3B1dliyvDKHrBZlr4BA4L1sY5+W9VCfmVmtxk+ILCe3S6c4ZuNHP6AngglkQku2LiOk14E0Th2rA2O7RjdPxM0oeapy9BADzI3E2f35x3ieccRTxjJ38rN82SyTqhmhRZfQmixqpE0WXYMXFT5SEOVmDJhAPGuHum1aZgRddz4M4L2ZXO1TFLvOFd3sT9HB7yYqZc1x+PeG/vRBIQMmhkohlAcfq6TdmNoYuXjY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR21MB1514.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(83380400001)(26005)(6666004)(36756003)(508600001)(956004)(10290500003)(66476007)(5660300002)(38350700002)(4326008)(8676002)(38100700002)(66946007)(2616005)(82950400001)(186003)(52116002)(7696005)(107886003)(6486002)(8936002)(82960400001)(316002)(921005)(66556008)(86362001)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZwBzX8mTmywXKH5p4rsThRTUXDaNxcJn44cwfrPSCfy0MBbX/sA0XVHLRl2A4XmnIqAeYdgtMclJ+0tf6h0ICkzFuDxKNe1ZMqDSH9fjEx0UP4TpxEi8gre/WBOPrC104k1Plj29cgdrB709k+jYAuGTlXnfze1PEfuopYqf8GfirX6pASnVlM9Tcktz9cTUvpSb4Ag3c/jXezKVhTRiBpNKu+/0jZHgJAf92G7BeGKFDJrqfr+UMFAhkhTf/WT6bvGbx8kmGU/VDaXKmRVWgO+nzuNfhbmivpwSPNPvoUuQUWtQL6G9Pnf86Q0mi3U5mz8wvRyclOmeEjM3zkXkfzHVldNFez5DUtWMHY4scjhED4zFVy/lpkf7ISwEoTKdLQTGidxPpkc6BNm5epZboWhmfjqrqkf7xsqHyyJJyxT9UU10AKHKxo1LWxMd/V4cHXceLvEv9CUEfoLDJdOMPDuquXjc2gEmkt0srBOQXt5ABlR1+qTAXY2rjQqsY+X/IjA6vTaQdoelkooQAY/Nrz+yiMggcfF+AUnzYgHHizHSwq1CNPo+KsgOu+cUKxLDf5jmb6XDKv6AgbW0t2/48EBuEccIprDL/yGheVvWWr9FiqyS4hikx8SYln9UoWZH2onbewWhUPChkx0Rc9bcylxBPCRdtUSupAIKVVQ8OkZBL2GFzMdS9gVxVMVfqKg6uERP8GXjZy+arn0Ocz7gcYw5v91Qm+z+EF3vgJ75z/GZniL81zD32oVKaxJ9ia48JJaK/acQ8yRMzihw/eW5JM2tBpKmEsDPCRNQFdMA33o2FOhgs2yrTZ/Yf6875BISh/EYvRZ3X+vyU7VqWAzvHrOz/VoMFYMS3EKfWgEIyRuhVK9ecZlirmDX82tza2mUdZMuPKKqlv5hVhm2yrrsQOj9M7Y/+ZCZ1zSYjw7p4EpJ5oH4Gyy5fypAr8CbUIdCHH25voto4sJHw/i18F3C96edsISu0yWoQdwaLZzCYMJATc8iSClUplKn4Tv1Oh8ysJuHSsNelgi3A74tM7ua7uZSF/fV+EW4cRyzrAYRcINuEd20E45Uj6eoN1+TeDDgrdK3L4Y/iwYjNOrf48ylkjtyniecOW1Ze6rQHkRmXA5fMvqG61KeHjvAsj4f5bIemK1F4YYHDfqnXdoDJlSx5AycHcq62DWjc7UPDvdzpyDrnc3viVj+uL/5jMyRpApAnGPa7h35Wpawl0SkNI6IPm1e3kbDKaB/CB44GQ41r6cUXNvhK8VAx1taCo8hCTa1Gsh1WJmD7zFEox6o/oUjYv6VVrjvYrX1+lEmpqa0uPMU1sUSm83ICgPZjum34djr X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b8d6978-8505-4a94-db7d-08d94b8eaf8a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1514.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 14:57:25.3661 (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: d8PkzWOjLzrsRrsYK1ZYyGfJH3P5O0Ka1GosjTZBi5ZalUR6m0Vba844ANLENLHyNX3rhMKwJ2pPwfsCo/CVww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0981 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_075732_393207_71FAB510 X-CRM114-Status: GOOD ( 17.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add ARM64-specific code to initialize the Hyper-V hypervisor when booting as a guest VM. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley Reviewed-by: Boqun Feng Reviewed-by: Sunil Muthuswamy --- arch/arm64/hyperv/Makefile | 2 +- arch/arm64/hyperv/mshyperv.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/hyperv/mshyperv.c diff --git a/arch/arm64/hyperv/Makefile b/arch/arm64/hyperv/Makefile index 1697d30..87c31c0 100644 --- a/arch/arm64/hyperv/Makefile +++ b/arch/arm64/hyperv/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y := hv_core.o +obj-y := hv_core.o mshyperv.o diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c new file mode 100644 index 0000000..2811fd0 --- /dev/null +++ b/arch/arm64/hyperv/mshyperv.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Core routines for interacting with Microsoft's Hyper-V hypervisor, + * including hypervisor initialization. + * + * Copyright (C) 2021, Microsoft, Inc. + * + * Author : Michael Kelley + */ + +#include +#include +#include +#include +#include +#include +#include + +static bool hyperv_initialized; + +static int __init hyperv_init(void) +{ + struct hv_get_vp_registers_output result; + u32 a, b, c, d; + u64 guest_id; + int ret; + + /* + * 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.priv_high = result.as32.b; + 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: privilege flags low 0x%x, high 0x%x, hints 0x%x, misc 0x%x\n", + ms_hyperv.features, ms_hyperv.priv_high, ms_hyperv.hints, + ms_hyperv.misc_features); + + /* 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); + + ret = hv_common_init(); + if (ret) + return ret; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "arm64/hyperv_init:online", + hv_common_cpu_init, hv_common_cpu_die); + if (ret < 0) { + hv_common_free(); + return ret; + } + + hyperv_initialized = true; + return 0; +} + +early_initcall(hyperv_init); + +bool hv_is_hyperv_initialized(void) +{ + return hyperv_initialized; +} +EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);