Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp175513pxb; Fri, 16 Apr 2021 02:46:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznBWB9H9JzlHpSlF+lfogrkGMMGUph6tz9SKymb/jbGpurVL+PPGgpUPWXaNSO8r+JoqrD X-Received: by 2002:aa7:d9cf:: with SMTP id v15mr8933060eds.358.1618566419558; Fri, 16 Apr 2021 02:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618566419; cv=none; d=google.com; s=arc-20160816; b=okmRmwZtGfpn+5KajOWM2wQV6lGRCgeST8s4fB7Fd9OL6qThzT9ZYkh1sxTNTUsLBG iJYfjKsGFSCfkUeQD5sljACt5UFk3ZFEBrPvPNZAIh0zGrGNwvBksHLGjGuvyHp7IA/+ 7lC75lE+Fk01/O4uUyAkoDzoFsc1YgYQ1TXI3hq73s91/lJ8DupX6ZSdwrAg1ErAp6ZU 9t7vbiTjsBzhYkQT0ld288HseU/2tRz0evkZtnmIQmFI//wGVEKK7W74JL+sY+Ak9LHe 2KuU7GyEKyf1i/T3HHqi4Qe+ZqjEMR8JN47Bo188HVC5j6ISNGV9b2Eby9uwHruiz5wj 9WVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=GDfR8iVh8XSN4o8S9XIZ+vsfxmtqUP1R7YuCLZyLUbM=; b=lbtDutIeIQYivBp/5pFwsXiIThh+FMtfkjD5OqPuizzF7gAcIiMm8J70TrnF3CcztI 3ZHrIcf21tsRkrH2evtfSmMJEvwYN60peMW/LNs2iyhGyN5MhSes+PpnbH0Ia8aE61mZ 7X/jpv2jrOuF7xy/CzYG1J5+bEopN9r8pPvYqGzo0562F0U5yrC4vquyifSR8ppP8qW0 YsdueA4zr1pASCE+ejyltd0zMMgnlQDtdohQbCnMTtKzGxkt2RNiOFkliP2JZ5zREUjp JbLa7BIdnz0nniUpYS8hfgRS/I0V0GNEMJ4CiO9u62n3qkSfbDz+z69haXT5EJMlvkrz ZBQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f5BpE1EO; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si4217306ejg.243.2021.04.16.02.46.36; Fri, 16 Apr 2021 02:46:59 -0700 (PDT) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f5BpE1EO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240291AbhDPI1K (ORCPT + 99 others); Fri, 16 Apr 2021 04:27:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30654 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240290AbhDPI1J (ORCPT ); Fri, 16 Apr 2021 04:27:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618561605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GDfR8iVh8XSN4o8S9XIZ+vsfxmtqUP1R7YuCLZyLUbM=; b=f5BpE1EO5amrg6SW2ld+EhkrDGaL64c0ZBhoTLkIsE/2ZeYgEhLVOvpsWCxRBRdr7sBEmc jl5J/tWELPrrwwxBStvtQD++ea8pXiMoZU3tbevJmeov0BV/qGjK8+Ef9HdFJg9G9EEcl7 79Ir+1++gGOtczPzBOMuTxx1MXTKUjw= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-401-KjgiykoAM2e-4yYM2mBPyg-1; Fri, 16 Apr 2021 04:26:43 -0400 X-MC-Unique: KjgiykoAM2e-4yYM2mBPyg-1 Received: by mail-ej1-f70.google.com with SMTP id g7-20020a1709065d07b029037c872d9cdcso1782847ejt.11 for ; Fri, 16 Apr 2021 01:26:43 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=GDfR8iVh8XSN4o8S9XIZ+vsfxmtqUP1R7YuCLZyLUbM=; b=osXsWQV/YnUxa9PFYefPs+DCBx16unWfJPH+WJ0XWRwFt0gVZg8u+NJwWAwizpdc26 FCSB+FMX2mHx7xJ4DFZCJSobeqx/Bo+z/kqsX/+B0ZAdi3n8W1KkupKm6EfrzJbFRm90 qTQ3dlqJWFNVi4D63M1diKDjJNzoyzX1jzesPOqakMoerDsy0P3lp4vnMVPvXbW94BPG oBLeFHtiQ+9CJmj2V5y5ecIqj+/T2OgrFiOM1Lh1rqNPYqqElwFInoW4s1rtc+TDFYzA mFHFYBshSuGZPNxDfjm4bjizwhjlKqCc15EWKpPeEWMFUlae6GyoH7NEyElbM7vT+Tnx su0A== X-Gm-Message-State: AOAM530xT/fbtvGMRKYQl5LR04/ajVM21ORkA+NKWfzhpSh8UZDEpKXR RGbPthp8zbtG51v0zzc7PzwVIPsZBNB7y20Pv0cyejtSL1kxRMZ+hNS4tftjwFBy9qmQWmIOiQb X19OoVb4bxGLOzcCQcU9+j7ut X-Received: by 2002:a05:6402:7cf:: with SMTP id u15mr2496391edy.297.1618561602411; Fri, 16 Apr 2021 01:26:42 -0700 (PDT) X-Received: by 2002:a05:6402:7cf:: with SMTP id u15mr2496382edy.297.1618561602274; Fri, 16 Apr 2021 01:26:42 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id w13sm4585188edc.81.2021.04.16.01.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 01:26:41 -0700 (PDT) From: Vitaly Kuznetsov To: Vineeth Pillai Cc: "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "K. Y. Srinivasan" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, Lan Tianyu , Michael Kelley , Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel , Wei Liu , Stephen Hemminger , Haiyang Zhang Subject: Re: [PATCH v2 1/7] hyperv: Detect Nested virtualization support for SVM In-Reply-To: <9d12558549bc0c6f179b26f5b16c751bdfab3f74.1618492553.git.viremana@linux.microsoft.com> References: <9d12558549bc0c6f179b26f5b16c751bdfab3f74.1618492553.git.viremana@linux.microsoft.com> Date: Fri, 16 Apr 2021 10:26:40 +0200 Message-ID: <871rba8wjj.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vineeth Pillai writes: > Detect nested features exposed by Hyper-V if SVM is enabled. > It may make sense to expand this a bit as it is probably unclear how the change is related to SVM. Something like: HYPERV_CPUID_NESTED_FEATURES CPUID leaf can be present on both Intel and AMD Hyper-V guests. Previously, the code was using HV_X64_ENLIGHTENED_VMCS_RECOMMENDED feature bit to determine the availability of nested features leaf and this complies to TLFS: "Recommend a nested hypervisor using the enlightened VMCS interface. Also indicates that additional nested enlightenments may be available (see leaf 0x4000000A)". Enlightened VMCS, however, is an Intel only feature so the detection method doesn't work for AMD. Use HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS.EAX CPUID information ("The maximum input value for hypervisor CPUID information.") instead, this works for both AMD and Intel. > Signed-off-by: Vineeth Pillai > --- > arch/x86/kernel/cpu/mshyperv.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c > index 3546d3e21787..c6f812851e37 100644 > --- a/arch/x86/kernel/cpu/mshyperv.c > +++ b/arch/x86/kernel/cpu/mshyperv.c > @@ -252,6 +252,7 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus) > > static void __init ms_hyperv_init_platform(void) > { > + int hv_max_functions_eax; > int hv_host_info_eax; > int hv_host_info_ebx; > int hv_host_info_ecx; > @@ -269,6 +270,8 @@ static void __init ms_hyperv_init_platform(void) > ms_hyperv.misc_features = cpuid_edx(HYPERV_CPUID_FEATURES); > ms_hyperv.hints = cpuid_eax(HYPERV_CPUID_ENLIGHTMENT_INFO); > > + hv_max_functions_eax = cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS); > + > pr_info("Hyper-V: privilege flags low 0x%x, high 0x%x, hints 0x%x, misc 0x%x\n", > ms_hyperv.features, ms_hyperv.priv_high, ms_hyperv.hints, > ms_hyperv.misc_features); > @@ -298,8 +301,7 @@ static void __init ms_hyperv_init_platform(void) > /* > * Extract host information. > */ > - if (cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS) >= > - HYPERV_CPUID_VERSION) { > + if (hv_max_functions_eax >= HYPERV_CPUID_VERSION) { > hv_host_info_eax = cpuid_eax(HYPERV_CPUID_VERSION); > hv_host_info_ebx = cpuid_ebx(HYPERV_CPUID_VERSION); > hv_host_info_ecx = cpuid_ecx(HYPERV_CPUID_VERSION); > @@ -325,9 +327,11 @@ static void __init ms_hyperv_init_platform(void) > ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); > } > > - if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) { > + if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { > ms_hyperv.nested_features = > cpuid_eax(HYPERV_CPUID_NESTED_FEATURES); > + pr_info("Hyper-V: Nested features: 0x%x\n", > + ms_hyperv.nested_features); > } > > /* With the commit message expanded, Reviewed-by: Vitaly Kuznetsov -- Vitaly