From patchwork Thu Nov 4 12:54:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1550917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=dv6WdjLs; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HlNv43p45z9sP7 for ; Thu, 4 Nov 2021 23:56:48 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1micIJ-0006fx-1P; Thu, 04 Nov 2021 12:56:39 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1micHH-0004hm-VQ for kernel-team@lists.ubuntu.com; Thu, 04 Nov 2021 12:55:36 +0000 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 63DB63F1C0 for ; Thu, 4 Nov 2021 12:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1636030533; bh=gqQ9H42/ZKce1TSmS4tEB09vygNmT74H+j33C1ToFmg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dv6WdjLsh0TfxOnm7rClwTj0BL8TL2ijiCXHZq8rbAYeyQuz8A976zGEcqyzjCYs9 B4KPwaYHyyWavfQbtA8zMsZOxusf0uPrS1pQQZ1wmHSlYZoTtaMMsuCsmNf1dLvcnK raL6nADT1+Nf/KJF45PNAP2fXpaoUdAde3oAx8gjHNYWtrIHqNEM2hYRQI86xRSUvM 0sp88o2oLvQw8uAH76iD3c3o9iP1828LAL2gMDBE5BLu5WNrRlCIk53AGQWxkCSVat 8tO+XjqaeH9qopU5RbAoFA4qsYqhLYAoZsOHlZMBpLvaT8Fm794dOV5Iptr10iNBnL OkGssFaVuJ5iQ== Received: by mail-pl1-f199.google.com with SMTP id u10-20020a170902e80a00b001421d86afc4so2762579plg.9 for ; Thu, 04 Nov 2021 05:55:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gqQ9H42/ZKce1TSmS4tEB09vygNmT74H+j33C1ToFmg=; b=ZU8Rac9zREdLXmpv7ypRoNuqN3+yFvFOqh7P/088A+0dQhC7LNLRV9eoLV82ZpA6Kl 2GxWg6BD0hVNyD7lEJkWrSrjJnuIQGFinR6g8JLltjOGqIZgTovJ4YeXyqwIa1dcmFor vsnZORs2y8qCIKs8hNBarvt4Nr/CQOK06ToJZbitWo/prsHdn13vJvV4AKoabIieqEjY VlvQAOlH0m3Q+foOmrlM3WGNgiB1LWLp8cPh3n7ox+xDMpcZT6pfOr39UJEEmMtZYQoZ bqZ5IWVySetVRN41S768FWfneUlhAxwRZAgvRI5w09FBDOyKOLA49JYvSJR+J7cKaZMf aSNw== X-Gm-Message-State: AOAM533Jrr2kD4syW/XKZfcSIRyXN/1Na0HBghGFnd14/oCd3i1SeHmr uxYutM/m6oTobqlgnrwckvxwP2yFXq6HcO0T5SFWG7a5Zl44I5DP4tKdVqyfj6iZ33GnMafhCpJ qYByhND/btkiVWQcxQ0M4WGu8E8UrLbiO1uT/6GR/zQ== X-Received: by 2002:a05:6a00:244e:b0:47b:7dbf:e23d with SMTP id d14-20020a056a00244e00b0047b7dbfe23dmr52254495pfj.34.1636030531488; Thu, 04 Nov 2021 05:55:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2IcWR/0l5YRS+qEHKe/tknxwKpYt5ZdAgEiEfqWtJT9D5MOJSL2zKpFvNmy8oeL3QSIhUvw== X-Received: by 2002:a05:6a00:244e:b0:47b:7dbf:e23d with SMTP id d14-20020a056a00244e00b0047b7dbfe23dmr52254464pfj.34.1636030531164; Thu, 04 Nov 2021 05:55:31 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id y4sm5283859pfi.178.2021.11.04.05.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 05:55:30 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 24/41] UBUNTU: SAUCE: arm64: hyperv: Initialize hypervisor on boot Date: Thu, 4 Nov 2021 06:54:32 -0600 Message-Id: <20211104125449.16540-25-tim.gardner@canonical.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211104125449.16540-1-tim.gardner@canonical.com> References: <20211104125449.16540-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Michael Kelley BugLink: https://bugs.launchpad.net/bugs/1949770 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 [marcelo.cerri@canonical.com: back ported from https://lore.kernel.org/linux-hyperv/1620841067-46606-6-git-send-email-mikelley@microsoft.com/] Signed-off-by: Marcelo Henrique Cerri --- arch/arm64/hyperv/mshyperv.c | 152 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/mshyperv.h | 6 ++ arch/arm64/kernel/setup.c | 4 + 3 files changed, 162 insertions(+) diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index d202b4c78ffc..95f7e4ef3033 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -14,6 +14,158 @@ #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); + +bool hv_root_partition; +EXPORT_SYMBOL_GPL(hv_root_partition); + +u32 *hv_vp_index; +EXPORT_SYMBOL_GPL(hv_vp_index); + +u32 hv_max_vp_index; +EXPORT_SYMBOL_GPL(hv_max_vp_index); + +void __percpu **hyperv_pcpu_input_arg; +EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); + +static int hv_cpu_init(unsigned int cpu) +{ + void **input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); + + hv_vp_index[cpu] = hv_get_vpreg(HV_REGISTER_VP_INDEX); + + *input_arg = kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); + if (!(*input_arg)) + return -ENOMEM; + + return 0; +} + +void __init hyperv_early_init(void) +{ + struct hv_get_vp_registers_output result; + u32 a, b, c, d; + u64 guest_id; + + /* + * 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; + + /* 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); + + /* + * 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); + + hyperv_initialized = true; +} + +static int __init hyperv_init(void) +{ + int i, ret; + + hyperv_pcpu_input_arg = alloc_percpu(void *); + if (!hyperv_pcpu_input_arg) + return -ENOMEM; + + /* Allocate and initialize percpu VP index array */ + hv_max_vp_index = num_possible_cpus(); + hv_vp_index = kmalloc_array(hv_max_vp_index, sizeof(*hv_vp_index), + GFP_KERNEL); + if (!hv_vp_index) { + ret = -ENOMEM; + goto free_input_arg; + } + + for (i = 0; i < hv_max_vp_index; i++) + hv_vp_index[i] = VP_INVAL; + + if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "arm64/hyperv_init:online", + hv_cpu_init, NULL) < 0) { + ret = -EINVAL; + goto free_vp_index; + } + + return 0; + +free_vp_index: + kfree(hv_vp_index); + hv_vp_index = NULL; + +free_input_arg: + hv_max_vp_index = 0; + free_percpu(hyperv_pcpu_input_arg); + hyperv_pcpu_input_arg = NULL; + return ret; +} + +early_initcall(hyperv_init); + +/* This routine is called before kexec/kdump. It does required cleanup. */ +void hyperv_cleanup(void) +{ + hv_set_vpreg(HV_REGISTER_GUEST_OSID, 0); + +} +EXPORT_SYMBOL_GPL(hyperv_cleanup); + +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); + +bool hv_is_isolation_supported(void) +{ + return false; +} +EXPORT_SYMBOL_GPL(hv_is_isolation_supported); /* * The VMbus handler functions are no-ops on ARM64 because diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h index e1486bf02599..8f1de3124fc9 100644 --- a/arch/arm64/include/asm/mshyperv.h +++ b/arch/arm64/include/asm/mshyperv.h @@ -23,6 +23,12 @@ #include #include +#if IS_ENABLED(CONFIG_HYPERV) +void __init hyperv_early_init(void); +#else +static inline void hyperv_early_init(void) {}; +#endif + /* * Declare calls to get and set Hyper-V VP register values on ARM64, which * requires a hypercall. diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index c6bbc03f4527..96c397ea622d 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -49,6 +49,7 @@ #include #include #include +#include #include static int num_standard_resources; @@ -340,6 +341,9 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) if (acpi_disabled) unflatten_device_tree(); + /* Do after acpi_boot_table_init() so local FADT is available */ + hyperv_early_init(); + bootmem_init(); kasan_init();