Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp634607pxb; Thu, 5 Nov 2020 09:02:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJygt2ybeeyfNqORiAtNYuX1laxSwlTyeQws1VD6GaZrmVQjHPiAin9R1Tg6M6IAgdUD2/Jn X-Received: by 2002:a19:504:: with SMTP id 4mr1195666lff.12.1604595756646; Thu, 05 Nov 2020 09:02:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604595756; cv=none; d=google.com; s=arc-20160816; b=s4ceNl/t4HhdaxC3p4KBLabnwKFsOw2g03h6YI1yGWS802ePCfDV2Y9m4SOs58aZxI rxkhwkU1t99Vk5YfTf56f6wX1AnXeY1GWdoSsyZoMuJP6mZog2ffin33hHRxzduhj+Db s0aCQyBjGb8YDGbUmN9gvYDp9bGjKQdfy8Bz3TWVbDxQf+TvIqGN3SLP/GRPzjmDuls9 1u0206kB4134k4ZtzpuTu+40/iKYi9vkqgQvDn/jlvLyYu2JEdhJjUET8WpYOU9TSfqW C7Fp1lKZb9M3+JU1C4JOM60E4PX1v1GVSyrkD4FM1cn1fbx29QhG16VeZFYvGN00KSlp s+pQ== 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=Lc9Ih+aBOUIcyg/pc4PzDWU6F5HLqSVXvBtWicqQZLQ=; b=u30ogvKLVJNK7Tzijn6PaFPZboNFAQxLL2gulqp/ckUtNsReATMatJj0QkgCZyckCw /iVsfjTzqG5x+AwXX1bcnki9rsBt1ZcmZpIdJvrKVRtGVs0wkqZCEU8cMWgjmrmd3kJ5 apeK3ump03CRO4WRcbj2TBPajNfWm+e0EtQ3JKjI47RUDF3M36k7ujSc+Z0pmy9aLSmM NU7nC3bShOgkGPqNoASDSShrRgh6X6oJOu+nCoszjoF6+DuuRkIZLy7li3ShyCB5eYfq xcqbWRmD7Q7RXM+AZRnkpPYoqTMn369ZQ12vpHdVgkJbrvhzl0eFnzqKJu4M6lF1GL/R HBbw== 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 d22si1613227ejy.208.2020.11.05.09.02.13; Thu, 05 Nov 2020 09:02:36 -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 S1731788AbgKEQ6d (ORCPT + 99 others); Thu, 5 Nov 2020 11:58:33 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45980 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730174AbgKEQ60 (ORCPT ); Thu, 5 Nov 2020 11:58:26 -0500 Received: by mail-wr1-f66.google.com with SMTP id p1so2576341wrf.12; Thu, 05 Nov 2020 08:58:25 -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=Lc9Ih+aBOUIcyg/pc4PzDWU6F5HLqSVXvBtWicqQZLQ=; b=AxJIgaj8zcOC1XPNXQ5lLcbVTO4mMH8EsJ0dyCr4Ie3ndV4RDCr1dox+rXHhpCpwfW kXurxPH5SrGv0p/m8rRsIlLlRDb5xcV54ZjFlwUcKeKDuQp5fw2Oxlw8uzhkzW8aRjgj jEY9LaTo+ABXVlKfgmdL75N5mymCr6W+qYwiPexyoFkw5476oJiVOpQY/+XaHQraLTju KodNutYtanxfRg9M1s7/iHOHKecL1rBug5xZlhVqyXd8OvtbitbPL2fI/NjZV6sF9Qk3 FYEmuX4QjEziTxWhIDFKkgfIfZMhZ0ZVSsgNE1AHu6zxCXFGL9cbFIY0Rnpcz08h7mHe qUXw== X-Gm-Message-State: AOAM531a0apTP3kera/DBGt7q4/C5z1bs3NSo6nVrKKpIUN06YdIqVhA 6yzJtu1E879kBiUJp7l9HUqw5cZXC0k= X-Received: by 2002:adf:c847:: with SMTP id e7mr4091644wrh.346.1604595504429; Thu, 05 Nov 2020 08:58:24 -0800 (PST) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id z5sm3350729wrw.87.2020.11.05.08.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 08:58:24 -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" , Arnd Bergmann , linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES) Subject: [PATCH v2 07/17] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary Date: Thu, 5 Nov 2020 16:58:04 +0000 Message-Id: <20201105165814.29233-8-wei.liu@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201105165814.29233-1-wei.liu@kernel.org> References: <20201105165814.29233-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 We will need the partition ID for executing some hypercalls later. Signed-off-by: Lillian Grassin-Drake Co-Developed-by: Sunil Muthuswamy Signed-off-by: Wei Liu --- arch/x86/hyperv/hv_init.c | 26 ++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 2 ++ include/asm-generic/hyperv-tlfs.h | 6 ++++++ 3 files changed, 34 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 7a2e37f025b0..73b0fb851f76 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -30,6 +30,9 @@ bool hv_root_partition; EXPORT_SYMBOL_GPL(hv_root_partition); +u64 hv_current_partition_id; +EXPORT_SYMBOL_GPL(hv_current_partition_id); + void *hv_hypercall_pg; EXPORT_SYMBOL_GPL(hv_hypercall_pg); @@ -335,6 +338,26 @@ static struct syscore_ops hv_syscore_ops = { .resume = hv_resume, }; +void __init hv_get_partition_id(void) +{ + struct hv_get_partition_id *output_page; + u16 status; + unsigned long flags; + + local_irq_save(flags); + output_page = *this_cpu_ptr(hyperv_pcpu_output_arg); + status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page) & + HV_HYPERCALL_RESULT_MASK; + if (status != HV_STATUS_SUCCESS) + pr_err("Failed to get partition ID: %d\n", status); + else + hv_current_partition_id = output_page->partition_id; + local_irq_restore(flags); + + /* No point in proceeding if this failed */ + BUG_ON(status != HV_STATUS_SUCCESS); +} + /* * This function is to be invoked early in the boot sequence after the * hypervisor has been detected. @@ -430,6 +453,9 @@ void __init hyperv_init(void) register_syscore_ops(&hv_syscore_ops); + if (hv_root_partition) + hv_get_partition_id(); + return; remove_cpuhp_state: diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 62d9390f1ddf..67f5d35a73d3 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -78,6 +78,8 @@ extern void *hv_hypercall_pg; extern void __percpu **hyperv_pcpu_input_arg; extern void __percpu **hyperv_pcpu_output_arg; +extern u64 hv_current_partition_id; + static inline u64 hv_do_hypercall(u64 control, void *input, void *output) { u64 input_address = input ? virt_to_phys(input) : 0; diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index e6903589a82a..87b1a79b19eb 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -141,6 +141,7 @@ struct ms_hyperv_tsc_page { #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014 #define HVCALL_SEND_IPI_EX 0x0015 +#define HVCALL_GET_PARTITION_ID 0x0046 #define HVCALL_GET_VP_REGISTERS 0x0050 #define HVCALL_SET_VP_REGISTERS 0x0051 #define HVCALL_POST_MESSAGE 0x005c @@ -407,6 +408,11 @@ struct hv_tlb_flush_ex { u64 gva_list[]; } __packed; +/* HvGetPartitionId hypercall (output only) */ +struct hv_get_partition_id { + u64 partition_id; +} __packed; + /* HvRetargetDeviceInterrupt hypercall */ union hv_msi_entry { u64 as_uint64; -- 2.20.1