Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3883121pxb; Tue, 26 Jan 2021 07:09:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnu27ChRnE+HaopESuteY2Fe9L0HU35AUgvcEfYFuyWbZbx0uxQIR4lquHTETDo6vs5khB X-Received: by 2002:a05:6402:c92:: with SMTP id cm18mr5241700edb.367.1611673788517; Tue, 26 Jan 2021 07:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611673788; cv=none; d=google.com; s=arc-20160816; b=rlhO3LxJaxCEGRnfNc0QFJd9N41tPpWjXXDtEngtK1GfSkouhIIbX+fkzZwYbz8pMr yLi25Q43FbJqQm3XUEyWW6AYVnz7PwJUL9KsopNKqSfo9wr8Fx9aoSZurGk3mESmpX4d DGmq5g21/8Q5t2yQQIgTrt7Dko/jB0s9MHutZHoj1NpprePkfnhkPiFpmB9ak3t89G8Z t/2LDrYAPr3lSCmmEYRP3dHtC1oBn+UmbGEhv5ZNot0y9lnzSDi6FLRWUOM8MuB2mOCT QqkesfTKtKu76LAj1Osog8sKNm6TUfJiYh2XhL9GRLIEjFA99Lw9J7DkAi6k3//Foe+S rSrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=1zxAP5nWOub6Bvc04Q0nYCpX745bg4gnoQMttyKcbDA=; b=gugbzahk1Ub6BPaYqvHo0k9Rs6xIwmNCmzqRiQkN8ztsE54cIuCuCT+RzZEoCiQBEQ jaEUy8oFSisBD2EmaqVBst3D1OTUNx6EVNaAgyw+TcaYvsFWNQW7qkVEO0nckW/KqVn7 pziEMMMn7AndYSuLycOxYoor3NiavptruGlu/lorXaemS9QAmfpD7NsXe6bqRx8RCjly nfuQyug6hGeAWFa8Ph+++MLK9npIvkMD9DCdmqbkfoLrthUbWNhmHa4/FwGnwzxZJqCI imgp7sD5A3URv8ATBYjK/xb3LVuRrG/oKpuW57FXBHttRQEMq871iQjrdpU8JpBNhqZN VbGg== 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 la11si3481036ejc.399.2021.01.26.07.09.22; Tue, 26 Jan 2021 07:09:48 -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 S2391644AbhAZPHQ (ORCPT + 99 others); Tue, 26 Jan 2021 10:07:16 -0500 Received: from mail-wr1-f52.google.com ([209.85.221.52]:47015 "EHLO mail-wr1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406117AbhAZPG5 (ORCPT ); Tue, 26 Jan 2021 10:06:57 -0500 Received: by mail-wr1-f52.google.com with SMTP id q7so16802572wre.13; Tue, 26 Jan 2021 07:06:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1zxAP5nWOub6Bvc04Q0nYCpX745bg4gnoQMttyKcbDA=; b=cLyO/H40Qe5XBacyvxPrEls2PLQpH229f1gtEJhXThmPVRs0jqLeLFJ66FS4BNao6X Ik0zRQmTfxZCZ10g5dBtUebX1+ISJoiGEgv2ZQsZerr0AKmDwtgV/Aa1mCNaUeEJCvWl /0DiVwEW4v9bOW9d/AIrtJOm8239T3DrIgQ6Xgy8SlO1RAOS50Atmhuem8VKJfdPVsek w3oFXqk/G/5zW73vgu+UZDQVBn2frbgn/DHaAcprKr+ToZMN136S3rcoQH8GkhPCV/IZ 7W6Hl5r9yH4qj6PloJk6n0hg/Pd4W4p7zLOhwRzNpMRr1LDRGEb9H2pMoFrACCdj+wCy ZJug== X-Gm-Message-State: AOAM533xm0AKkD+0quXUwxs04rKwWMZZTGXqhRULzOTnXhHORbiucVUq 6OfoHdGLRGtga92sP0CLaAw= X-Received: by 2002:a5d:640c:: with SMTP id z12mr6619568wru.342.1611673575016; Tue, 26 Jan 2021 07:06:15 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id i131sm3814078wmi.25.2021.01.26.07.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 07:06:14 -0800 (PST) Date: Tue, 26 Jan 2021 15:06:13 +0000 From: Wei Liu To: Pavel Tatashin Cc: Wei Liu , Linux on Hyper-V List , virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" Subject: Re: [PATCH v5 02/16] x86/hyperv: detect if Linux is the root partition Message-ID: <20210126150613.6fg5f5ouqicq4job@liuwe-devbox-debian-v2> References: <20210120120058.29138-1-wei.liu@kernel.org> <20210120120058.29138-3-wei.liu@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 11:03:18AM -0500, Pavel Tatashin wrote: > On Wed, Jan 20, 2021 at 7:01 AM Wei Liu wrote: > > > > For now we can use the privilege flag to check. Stash the value to be > > used later. > > > > Put in a bunch of defines for future use when we want to have more > > fine-grained detection. > > > > Signed-off-by: Wei Liu > > --- > > v3: move hv_root_partition to mshyperv.c > > --- > > arch/x86/include/asm/hyperv-tlfs.h | 10 ++++++++++ > > arch/x86/include/asm/mshyperv.h | 2 ++ > > arch/x86/kernel/cpu/mshyperv.c | 20 ++++++++++++++++++++ > > 3 files changed, 32 insertions(+) > > > > diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h > > index 6bf42aed387e..204010350604 100644 > > --- a/arch/x86/include/asm/hyperv-tlfs.h > > +++ b/arch/x86/include/asm/hyperv-tlfs.h > > @@ -21,6 +21,7 @@ > > #define HYPERV_CPUID_FEATURES 0x40000003 > > #define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004 > > #define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005 > > +#define HYPERV_CPUID_CPU_MANAGEMENT_FEATURES 0x40000007 > > #define HYPERV_CPUID_NESTED_FEATURES 0x4000000A > > > > #define HYPERV_CPUID_VIRT_STACK_INTERFACE 0x40000081 > > @@ -110,6 +111,15 @@ > > /* Recommend using enlightened VMCS */ > > #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14) > > > > +/* > > + * CPU management features identification. > > + * These are HYPERV_CPUID_CPU_MANAGEMENT_FEATURES.EAX bits. > > + */ > > +#define HV_X64_START_LOGICAL_PROCESSOR BIT(0) > > +#define HV_X64_CREATE_ROOT_VIRTUAL_PROCESSOR BIT(1) > > +#define HV_X64_PERFORMANCE_COUNTER_SYNC BIT(2) > > +#define HV_X64_RESERVED_IDENTITY_BIT BIT(31) > > + > > /* > > * Virtual processor will never share a physical core with another virtual > > * processor, except for virtual processors that are reported as sibling SMT > > diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h > > index ffc289992d1b..ac2b0d110f03 100644 > > --- a/arch/x86/include/asm/mshyperv.h > > +++ b/arch/x86/include/asm/mshyperv.h > > @@ -237,6 +237,8 @@ int hyperv_fill_flush_guest_mapping_list( > > struct hv_guest_mapping_flush_list *flush, > > u64 start_gfn, u64 end_gfn); > > > > +extern bool hv_root_partition; > > + > > #ifdef CONFIG_X86_64 > > void hv_apic_init(void); > > void __init hv_init_spinlocks(void); > > diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c > > index f628e3dc150f..c376d191a260 100644 > > --- a/arch/x86/kernel/cpu/mshyperv.c > > +++ b/arch/x86/kernel/cpu/mshyperv.c > > @@ -32,6 +32,10 @@ > > #include > > #include > > > > +/* Is Linux running as the root partition? */ > > +bool hv_root_partition; > > +EXPORT_SYMBOL_GPL(hv_root_partition); > > + > > struct ms_hyperv_info ms_hyperv; > > EXPORT_SYMBOL_GPL(ms_hyperv); > > > > @@ -237,6 +241,22 @@ static void __init ms_hyperv_init_platform(void) > > pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n", > > ms_hyperv.max_vp_index, ms_hyperv.max_lp_index); > > > > + /* > > + * Check CPU management privilege. > > + * > > + * To mirror what Windows does we should extract CPU management > > + * features and use the ReservedIdentityBit to detect if Linux is the > > + * root partition. But that requires negotiating CPU management > > + * interface (a process to be finalized). > > Is this comment relevant? Do we have to mirror what Windows does? > We should do that in the future when the process for negotiating CPU management features is stabilized / finalized. > > + * > > + * For now, use the privilege flag as the indicator for running as > > + * root. > > + */ > > + if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_CPU_MANAGEMENT) { > > + hv_root_partition = true; > > + pr_info("Hyper-V: running as root partition\n"); > > + } > > + > > Reviewed-by: Pavel Tatashin Thanks for reviewing these patches. Wei.