Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp195555pxb; Wed, 20 Jan 2021 04:57:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbUeE4N7Sqj6YQ6Kdwf/2RCoOydNQtmvFGB81qLCRUywtgBtDzubOsCt3sMmKNQdOSCG9k X-Received: by 2002:a17:906:fa9a:: with SMTP id lt26mr6203416ejb.439.1611147473877; Wed, 20 Jan 2021 04:57:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611147473; cv=none; d=google.com; s=arc-20160816; b=ToBqljuiVbMzQpaPeI/+R7N4/mQoowJVoy3tepb4/G4AEgLxXGSls95BLfVWwMGxob BmeioCErUdCVaKaMBRlyUxA2U+Lx87/OIlsGODh40P9WOV3UiovVLLaeCbr4h3TaYpwh sUJy9dSYVmQJekQak8GI1atwLcaoHIb/wcQOd3Q2IfzN0/+lPGb5yi9lbEKvKRdMmkL6 S1iHkyTx1Wo59cllSM09v5sSF0+IufxGwIwth53ymS6iMGFRcPGjov+Oh5C+Y0AtzFUx EMPR/J3MNKWThGuuVdh/PF5ZtlY2SSHck2z/Z7Tag0iyTP+2K0FQJqI+nHQTgVTJTD/4 9hzw== 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=H4jfN+vhUy3GHthrw6ENA5M++jGLDMtFmgSdmVqSuzre20SrLkG8DVEoxplWCRE35I lqH7O7w5JK5TMkkFKrG1sqNsCGHrvpMWB3SvWw3g8LgZdwHrBpfkQ0LnCaiqRaxiIFb1 AlkGuyVO8qt9oFUscbETkaEwz3CPORdLZskwAULqCRNd6FOMftcIRP4jDfBIVdnfYcYp Bj6oH3RcnhDgY1OoHbPb4HfcBqPwwAmHwlDifBARFEJF0QRH9d+YKZogohP6+Y3DHOmJ kpKFZ/e0hvd9USrXesCA2zoh3DSOoZSoti1COUwRACLTTZn1s+g8uo2kXrcxVYWCEOI/ /TnA== 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 d11si833843eds.408.2021.01.20.04.57.28; Wed, 20 Jan 2021 04:57:53 -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 S2388432AbhATM42 (ORCPT + 99 others); Wed, 20 Jan 2021 07:56:28 -0500 Received: from mail-wm1-f52.google.com ([209.85.128.52]:37977 "EHLO mail-wm1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389049AbhATMJ5 (ORCPT ); Wed, 20 Jan 2021 07:09:57 -0500 Received: by mail-wm1-f52.google.com with SMTP id y187so2630348wmd.3; Wed, 20 Jan 2021 04:09:41 -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=s4/mQIOnEZQBHD5J7JAaXCaGXXQby96qga/+uRllt5gUkG2Bqu2/gRky5CypgLbz4H NhQDdlGqcIZgCslpnccK5Ii+CMyj/DobwKFCEEqThmQW8hCAP68p3q/5GGIntjeeQYAs 6AXBU8UFl/hVkaFF5u3mqyWspCdG3X6d9cQ38utWVrFgl7KWmEuaOfqi6zB7eL0Rya4g qqcNgC8HFKVIpgvQgFEUxrqBeg+Blk6fk9wYCNrFMp6TOyVL8ojIJBGTdWSiQBwPQpMz aT7gQ25Wput5QsnjA16SSeBzmUbH9XDJxcHGcJTOBFbyn4flqkwqTxksZA5QAF6vWScx IVbA== X-Gm-Message-State: AOAM531CQ++UQweZs/+D7oVwcxqTprRw+qV6B0GytR1QdIr4UWtViVc+ Gnr/MGXRsH44TmLqCBQrdhLOaDjlrH4= X-Received: by 2002:a1c:bb07:: with SMTP id l7mr2030170wmf.102.1611144069419; Wed, 20 Jan 2021 04:01:09 -0800 (PST) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id x17sm3747671wro.40.2021.01.20.04.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 04:01:08 -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 , pasha.tatashin@soleen.com, 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 v5 08/16] x86/hyperv: handling hypercall page setup for root Date: Wed, 20 Jan 2021 12:00:50 +0000 Message-Id: <20210120120058.29138-9-wei.liu@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210120120058.29138-1-wei.liu@kernel.org> References: <20210120120058.29138-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