Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1800147pxu; Tue, 24 Nov 2020 09:11:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDTHGww2SBfu5l0DRnzNbrefParaSURZ66lQ56ibyci47aZzMrknTVb3gCnap2FJOoFwPC X-Received: by 2002:a17:906:3687:: with SMTP id a7mr4992426ejc.210.1606237895417; Tue, 24 Nov 2020 09:11:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606237895; cv=none; d=google.com; s=arc-20160816; b=awWQtrjx6qLTWMoVQVyV8q4IlbcBefIY069kDmWsmd8oKm0ai63UEO0IbWjpeICr0v SMfHXr2oXrYNA89pwYsOrOlcKBk25nrKAlqgQhA1x3A5PFDCbL4QNSyt0IOM4cmPuwQp /aV1BFTmgtOtYQgEFFkyRUzrhu/87Da0YCNBbXqdKD/t3D0OYs08m2S/KQ2qbzv2faTK uwbrUhUmgEMxSzZ1lawWtpjZOpzZ5dAFLSiJgmeN/sp30UZ3b6PL+1oE4QMUyPvdIbKd kVOxeI72z9u7OUD6Dudbfljpe1TGYr3z+oO+7hQsVrtzu8Tgp/BR7yHCPQE4kcgkEqNr zBcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ECNX1WrK2HKJq0miQELnifiiUacgKjt/44MKsDI+NUo=; b=gjJhbiUM/vNIgq/SAOHJSEqDGxNWKmYPYTB2bVef91nY2BpiIkMHU1ao6JZ4sSOlWC HfvKfQABWz4l1lkO6V/ZVVaYrK7D1rqe3U3S0rwPvXaQGLA/CKOeuXzi/OVZYhkrkv9e fFNypTFYWDryyVfV/T4qC4TMq073tkl7/eYP7vED65rl+HCZxC2TZpUb+jgSonSmUhI4 KclYcjlV9UWz4iPTorgf7rX2TWmiw7k8i1OGmu7m2XLZq5JIIFgzLr1/lgeeLmHgq0TU iogvPGhj9d3dc5rdsyloJVzqI58mN0+JFP6R5dwwNeEEr6EmUy2c11OkaHShfpNwDvQh Thug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si8539597eja.38.2020.11.24.09.11.09; Tue, 24 Nov 2020 09:11:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390725AbgKXRID (ORCPT + 99 others); Tue, 24 Nov 2020 12:08:03 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36812 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390675AbgKXRH6 (ORCPT ); Tue, 24 Nov 2020 12:07:58 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so7269914wrn.3; Tue, 24 Nov 2020 09:07:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ECNX1WrK2HKJq0miQELnifiiUacgKjt/44MKsDI+NUo=; b=YdH2P2jXsMQKNU9xkFMWlu2viHMYEldIkP1flHsGvQgxvARjUHepHmR3S5JLM/f5SA CJ/enz3KKwztrz+uQiDjbYdiU+3q26GuRf0BUdUKkxkiumYmMW1dlzkeqOF7qfhUqB0e ePHBfQlAy/7atbJLj/GR0zZsDngCzyRqgn6phzHR3pvg5iyxGqMHB8qHfT6vskEB+qCP B1NrajZGvJz1n7LIMd1/nCWuzJ2NGwZ+jirBVUgF9Cqj0gvwsDpvnkGQiQmNKEbsZdNH dEyn9n1ACVg/h13mHduWoUz60kIvMJHM7XA4+2kQHvJlbarirW14xoBPh9iqr2gdcf+w f/eQ== X-Gm-Message-State: AOAM533UMMiYRPI5RpeiGlmqlLUGLRmMJlMUmDdzfG65t8xtfWKl9qZL E7mPr6uCIb+ggMm7opXnJIOTOW/PwrI= X-Received: by 2002:adf:f944:: with SMTP id q4mr6298016wrr.120.1606237676092; Tue, 24 Nov 2020 09:07:56 -0800 (PST) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id v20sm6419874wmh.44.2020.11.24.09.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 09:07:55 -0800 (PST) From: Wei Liu To: Linux on Hyper-V List Cc: virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , Wei Liu , Lillian Grassin-Drake , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" Subject: [PATCH v3 08/17] x86/hyperv: handling hypercall page setup for root Date: Tue, 24 Nov 2020 17:07:35 +0000 Message-Id: <20201124170744.112180-9-wei.liu@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201124170744.112180-1-wei.liu@kernel.org> References: <20201124170744.112180-1-wei.liu@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When Linux is running as the root partition, the hypercall page will have already been setup by Hyper-V. Copy the content over to the allocated page. Add checks to hv_suspend & co to bail early because they are not supported in this setup yet. Signed-off-by: Lillian Grassin-Drake Signed-off-by: Sunil Muthuswamy Signed-off-by: Nuno Das Neves Co-Developed-by: Lillian Grassin-Drake Co-Developed-by: Sunil Muthuswamy Co-Developed-by: Nuno Das Neves Signed-off-by: Wei Liu --- v3: 1. Use HV_HYP_PAGE_SIZE. 2. Add checks to hv_suspend & co. --- arch/x86/hyperv/hv_init.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index fc9941bd8653..ad8e77859b32 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -25,6 +25,7 @@ #include #include #include +#include u64 hv_current_partition_id = ~0ull; EXPORT_SYMBOL_GPL(hv_current_partition_id); @@ -283,6 +284,9 @@ static int hv_suspend(void) union hv_x64_msr_hypercall_contents hypercall_msr; int ret; + if (hv_root_partition) + return -EPERM; + /* * Reset the hypercall page as it is going to be invalidated * accross hibernation. Setting hv_hypercall_pg to NULL ensures @@ -433,8 +437,35 @@ void __init hyperv_init(void) rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); hypercall_msr.enable = 1; - hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); - wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + + if (hv_root_partition) { + struct page *pg; + void *src, *dst; + + /* + * For the root partition, the hypervisor will set up its + * hypercall page. The hypervisor guarantees it will not show + * up in the root's address space. The root can't change the + * location of the hypercall page. + * + * Order is important here. We must enable the hypercall page + * so it is populated with code, then copy the code to an + * executable page. + */ + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + + pg = vmalloc_to_page(hv_hypercall_pg); + dst = kmap(pg); + src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE, + MEMREMAP_WB); + BUG_ON(!(src && dst)); + memcpy(dst, src, HV_HYP_PAGE_SIZE); + memunmap(src); + kunmap(pg); + } else { + hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + } /* * Ignore any errors in setting up stimer clockevents @@ -577,6 +608,6 @@ EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized); bool hv_is_hibernation_supported(void) { - return acpi_sleep_state_supported(ACPI_STATE_S4); + return !hv_root_partition && acpi_sleep_state_supported(ACPI_STATE_S4); } EXPORT_SYMBOL_GPL(hv_is_hibernation_supported); -- 2.20.1