From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1B6B4C433DB for ; Tue, 26 Jan 2021 00:48:45 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.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 90A8222482 for ; Tue, 26 Jan 2021 00:48:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90A8222482 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lists.linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 45E7387124; Tue, 26 Jan 2021 00:48:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TW2l40bvfoZI; Tue, 26 Jan 2021 00:48:43 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 64A9D87036; Tue, 26 Jan 2021 00:48:43 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3968FC08A1; Tue, 26 Jan 2021 00:48:43 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1B79DC013A for ; Tue, 26 Jan 2021 00:48:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 01632870C4 for ; Tue, 26 Jan 2021 00:48:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V2OnnElyhmH1 for ; Tue, 26 Jan 2021 00:48:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2133.outbound.protection.outlook.com [40.107.223.133]) by hemlock.osuosl.org (Postfix) with ESMTPS id B859D87036 for ; Tue, 26 Jan 2021 00:48:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mnmAYfFWqcVOZFJwuqMQjscP2eDuuZ00qX0lKv2hBvWXUBNZlIk240naGEiVSHtE9KKbLlXLkE98D/ciQPj7q6CT8tQxdFPC4c0MRffcF+FHSaAkTPH6rodA6EnjRzU9LSOEMCkF+hthrGDtephy1519hRVZgAuK1E+473ZxYae6SX3oz3PnsOxC2TnRKK40ChDU6HmAKtMHXD249EIZ0DoERLEcqVvBhupADJrNNHUZwHm3LN+sHpjWnlF7y78yGmjmxZfOVsDwZlNSeWsQs1DtCZnUbKDON8GdlVhXy7BH69sGrtFHWwF0YTsSUcnsLs6/csv7OEuh1KJwsOuNuw== 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=7XZz7m6AYFIvk6s1FDceHRrbp2rFOeOko9//G+INEAA=; b=LnY84S7ns1zUu11mczozPn/ScLcX1FpPanS59fyWdYMysReRMJb5y/F7KFYQmEO1qt9s2UvlLlZHrxEvCuJcneBrNi2UxX6a8Jnr75lyymFAWnzQQNxFdJIDbbVtnwH9ZKMI5wwBEN6DYQxOmYelI8Fd0BhraYQWscOjObGOYHmLlKZ+/Nyu1xMgirQOX5tcMSOv3kLF2sBy9JihJtbVje3l74x/IqVE+YlvA2YH7g24difQFhCRQA5UPBbtZkQmNp4VRe9h6PUHN0S8gCUa1d2arPtPK3hNsZN9EIC9qvkAav2cBEsV5khV5HNpXjawZRogU9GNyYKmX3zuxCFKDA== 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=7XZz7m6AYFIvk6s1FDceHRrbp2rFOeOko9//G+INEAA=; b=RY6JBW9Q2Ki9KaKMuEGOjPoSCi13okXJb7v2CBsdzw10vOYyan4qHsLlurr6p6gsl/N5/Py6950Vq9CSb0uLJppT6Aa6abABWeqcwLBLSiVgkwDKblBeMNwO4Y8vB2MDPyhyzOcxaBg2+zH7Zs6oFa2vNxPoX7/hb+zEC/iZzyE= Received: from (2603:10b6:301:7c::11) by MW4PR21MB1873.namprd21.prod.outlook.com (2603:10b6:303:77::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.3; Tue, 26 Jan 2021 00:48:37 +0000 Received: from MWHPR21MB1593.namprd21.prod.outlook.com ([fe80::9c8:94c9:faf1:17c2]) by MWHPR21MB1593.namprd21.prod.outlook.com ([fe80::9c8:94c9:faf1:17c2%9]) with mapi id 15.20.3825.003; Tue, 26 Jan 2021 00:48:37 +0000 To: Wei Liu , Linux on Hyper-V List Subject: RE: [PATCH v5 07/16] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary Thread-Topic: [PATCH v5 07/16] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary Thread-Index: AQHW7yPz+GhbbxilDEuVBBNQAujR/ao5GZ8Q Date: Tue, 26 Jan 2021 00:48:37 +0000 Message-ID: References: <20210120120058.29138-1-wei.liu@kernel.org> <20210120120058.29138-8-wei.liu@kernel.org> In-Reply-To: <20210120120058.29138-8-wei.liu@kernel.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2021-01-26T00:48:35Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=3d8f1d5b-0f6a-4b85-9f60-759f5ad61fb4; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0 authentication-results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [66.75.126.197] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 9f9902b9-dcc3-4872-7622-08d8c1941dfe x-ms-traffictypediagnostic: MW4PR21MB1873: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: x/woAQi604xGOSsAPA7ZKTfS5PM7JsvA9pkG/axOM9N3ImboNZ+JWOfg8sfovl+vdzCM8DJpW6SgyQ+dKGbDwz+1anGn+Ruwb+7S5UGJAjtlLpYRSZQD1DesUUbRtnBgWsRUHaxlcCYbrwnRjA1sIYx4ZAYeW+b5TehS0Toww/XvY9np/QUFMQ0yGwEJ2hhNqelP8Wqx3UHzlSmBIMYPUyFk3bxNwm3r9Bw1l8tWSkmu9Q3dzfxNuWgKQf9tbLTqyLQzD9sXwUCVPkExgkd5fEdQhcOsxv4s2mdDZBa3vsAc5ZpkHxKzDDOJe1XoV/V7zEKC+Z14ePpf9zSuTzI1/8QDjvHgFzUD31BaGxlRpcge7FHafX/qxxTM8HbW/bIR+IWQOTtjIUbdU4lFJ104wKFFioHSKrDvCCDzcz9J6AmtUV2KJhwFM2OrdGFMHwiUuuP2PklQuQdOEz+y3mxsb/eubSL98yVtie+H8R1LJLminHlf4s2EctaOM3dyazY/DxFetryjL5ijqqf5hKpzFA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR21MB1593.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(136003)(396003)(366004)(39860400002)(47530400004)(26005)(82950400001)(8990500004)(7416002)(83380400001)(82960400001)(7696005)(55016002)(9686003)(76116006)(6506007)(186003)(54906003)(316002)(71200400001)(478600001)(64756008)(110136005)(2906002)(66556008)(33656002)(52536014)(10290500003)(8676002)(66446008)(86362001)(66476007)(8936002)(4326008)(5660300002)(66946007); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?cSQYJ+V1NAQzC+WFKRWZPhXO/3BNPwLxtGrtK4EhN/OSSmPFi28l/tYnnLwT?= =?us-ascii?Q?TZmXYCYz7fvh0Zz4gpKXlWePF23Yc77/bPIErhOOHnmWABCN3F9+fj22GqUA?= =?us-ascii?Q?JAtkMs4cD9qz5ztBL5hgoVUa9rJPR9HLZE+ktHsx6AlEhdWWeA6kWp+BVYS0?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KkL7/wVhNvbyY1mVOWXluvxPb?= =?us-ascii?Q?BzDYOB1w?= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR21MB1593.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f9902b9-dcc3-4872-7622-08d8c1941dfe X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jan 2021 00:48:37.4082 (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: GczV6INy1lt5jlPTEHh1Q/dM+Qda1FnQEXoQFGtjA1ke39itLHzwCHVaSkvvQvZqBNSBDAkEfcjx/Y0HxJ00I73M7Hk6Ddx2GYLvZ73o9LQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1873 Cc: "open list:GENERIC INCLUDE/ASM HEADER FILES" , Stephen Hemminger , "pasha.tatashin@soleen.com" , Arnd Bergmann , Lillian Grassin-Drake , "maintainer:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)" , Linux Kernel List , "virtualization@lists.linux-foundation.org" , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Nuno Das Neves , Borislav Petkov , Sunil Muthuswamy , Vineeth Pillai , Haiyang Zhang X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Michael Kelley via Virtualization Reply-To: Michael Kelley Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" From: Wei Liu Sent: Wednesday, January 20, 2021 4:01 AM > > 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 > --- > v3: > 1. Make hv_get_partition_id static. > 2. Change code structure a bit. > --- > arch/x86/hyperv/hv_init.c | 27 +++++++++++++++++++++++++++ > arch/x86/include/asm/mshyperv.h | 2 ++ > include/asm-generic/hyperv-tlfs.h | 6 ++++++ > 3 files changed, 35 insertions(+) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index 6f4cb40e53fe..fc9941bd8653 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -26,6 +26,9 @@ > #include > #include > > +u64 hv_current_partition_id = ~0ull; > +EXPORT_SYMBOL_GPL(hv_current_partition_id); > + > void *hv_hypercall_pg; > EXPORT_SYMBOL_GPL(hv_hypercall_pg); > > @@ -331,6 +334,25 @@ static struct syscore_ops hv_syscore_ops = { > .resume = hv_resume, > }; > > +static 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) { Across the Hyper-V code in Linux, the way we check the hypercall result is very inconsistent. IMHO, the and'ing of hv_do_hypercall() with HV_HYPERCALL_RESULT_MASK so that status can be a u16 is stylistically a bit unusual. I'd like to see the hypercall result being stored into a u64 local variable. Then the subsequent test for the status should 'and' the u64 with HV_HYPERCALL_RESULT_MASK to determine the result code. I've made a note to go fix the places that aren't doing it that way. > + /* No point in proceeding if this failed */ > + pr_err("Failed to get partition ID: %d\n", status); > + BUG(); > + } > + hv_current_partition_id = output_page->partition_id; > + local_irq_restore(flags); > +} > + > /* > * This function is to be invoked early in the boot sequence after the > * hypervisor has been detected. > @@ -426,6 +448,11 @@ void __init hyperv_init(void) > > register_syscore_ops(&hv_syscore_ops); > > + if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID) > + hv_get_partition_id(); Another place where the EBX value saved into the ms_hyperv structure could be used. > + > + BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull); > + > 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 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization