Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1344899ybl; Sun, 19 Jan 2020 01:01:35 -0800 (PST) X-Google-Smtp-Source: APXvYqwMVgg8ICmsXY5B4qVeSvnOP9CYt+9fKfWfE1729vgf2Z7ri2f4TKnW6ASbeNUrl3j+yuJB X-Received: by 2002:a9d:6acd:: with SMTP id m13mr12161258otq.313.1579424495626; Sun, 19 Jan 2020 01:01:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579424495; cv=none; d=google.com; s=arc-20160816; b=mHipZJK91nhQ+FQvkkIwL3n9QRLst8BE43T6qi6aRdJezK6gwWA/jrQnukMqe4PKgB nj/8dw9ZtVZFAXG8+Ccy1a7X2HYfCxZqCVntrQixMr3RkhBwmUwRNjDETy0FuAcdpJSH kRFjh5f0WczOLVhgBJk3ix4EgiiV2uxXf2B81bSazLoPdR+C4QBTDzKqfl5qA0y+jwHO ST3wN0KS91IXSUbSOghKI4KSa1WB0uSjPL6su9GzCpKk5tXzORAVXvdQYu1IRT6OPG52 pqGoEwJCxWnXRMx/TJutw/5Ae55E8vKkrCnDuYs1eHQXJrA0YENzHrVGDU3FYpBS/d86 iqIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=f9cBCNFLdYb5b5nntvKG/XFjJpBa8yu/J2hg4sweBzU=; b=tpPRxUPt7kzXHRiGhaX5eMckvWsFjb0p5fAcn15irU/KFScaBOs2NVicdLycseKH8M B0++zlRydsr5fl+dKBOfrjm8bZanW42ZnLWnz6O6C+0aJK6yq4j6LgM4mIUSYcBvLPKL 4qLNRlQQeiC4c2cjR/FK0EmJzzM42LFcUTevG/y342uDEo6gS8Z/LpZQA3+Id0XeoBi9 xwZrCGrW4avFF8sJtsKNZL+VTG9ahMlF7z5WxCzM3EwMlPIkzbufnjXHA9SueMo5MlmB oq52XQ/BHXX9X6U+IC9SLS0wuhTy36bnnNwZ54w+o3+3enPYW/jzkLr4tPtIdcDTkOuX H0TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SYQicjQp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id n9si17766218ota.103.2020.01.19.01.01.22; Sun, 19 Jan 2020 01:01:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SYQicjQp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726867AbgASI5b (ORCPT + 99 others); Sun, 19 Jan 2020 03:57:31 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:52178 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726587AbgASI5a (ORCPT ); Sun, 19 Jan 2020 03:57:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579424250; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f9cBCNFLdYb5b5nntvKG/XFjJpBa8yu/J2hg4sweBzU=; b=SYQicjQppZVOiGKTutpLYJFW0amd91DTiAziqlMt6LfV/si0hFXwQsb/TnL6rtgTcUuA+o qnjal+GS6YW0LOsyeEwOif9IUy0RzDbhwF3MVh/VPQfUq7hqCllMpaqln6lgnqsPfG/gQD pTNDfXnP6HYTtTvYtFbUq+z3UppCNyU= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-nKpIfxFJOOSGLKIDNbW1nw-1; Sun, 19 Jan 2020 03:57:28 -0500 X-MC-Unique: nKpIfxFJOOSGLKIDNbW1nw-1 Received: by mail-wm1-f71.google.com with SMTP id n17so1699835wmk.1 for ; Sun, 19 Jan 2020 00:57:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=f9cBCNFLdYb5b5nntvKG/XFjJpBa8yu/J2hg4sweBzU=; b=EcQ8noQBY8nZkZ2Ce/P/Gb0PAG9AOI+QO0y/L2zU9lNA/Jodntk3GHMliGVJ5pRUEe SQXWVFJh1MMRlcfPuLRXv7MAuktdM854WBkrdFAc3p+b5PiKKVFnQ0aVbxDwS5Q5nhQ5 6taFCg2qSPaBWlJHtQWsO21LMcGpm9DQrroOoE7/8F/m/XwN9c3L1dMKbrfKCW1WIbQx T21U7W6GGnQ1s50hTIlGQbBQb1PoK9Ob9rsR60XL9bKxaxXlL0WcfufjeWEaMg/vFD6P eSTa6o7im1uto/QHigKlE/YgOzDyY5zzg669wsjZh6rusSiojH775Q27f8pzXQjVXp4x H++w== X-Gm-Message-State: APjAAAX7VChpisBK544o/cFRm7WGtHwLTOr00vmYnog39aSRgX6TeiHI b/W2RJIbUf54rHzmHtRTYSwYygkNEW8+sPF0fsS1lqbb7UKoWIguh9/+Io8SuM3bEVvAOoRqhWK vp6s71I8wcqaNvh/RiIJatvaS X-Received: by 2002:adf:df0e:: with SMTP id y14mr11984359wrl.377.1579424247707; Sun, 19 Jan 2020 00:57:27 -0800 (PST) X-Received: by 2002:adf:df0e:: with SMTP id y14mr11984342wrl.377.1579424247449; Sun, 19 Jan 2020 00:57:27 -0800 (PST) Received: from [192.168.10.150] ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id n3sm39994970wrs.8.2020.01.19.00.57.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Jan 2020 00:57:26 -0800 (PST) Subject: Re: [PATCH RFC 3/3] x86/kvm/hyper-v: don't allow to turn on unsupported VMX controls for nested guests To: Sean Christopherson , Vitaly Kuznetsov Cc: Liran Alon , kvm@vger.kernel.org, Jim Mattson , linux-kernel@vger.kernel.org, Roman Kagan References: <20200115171014.56405-1-vkuznets@redhat.com> <20200115171014.56405-4-vkuznets@redhat.com> <874kwvixuq.fsf@vitty.brq.redhat.com> <20200116162101.GD20561@linux.intel.com> From: Paolo Bonzini Message-ID: Date: Sun, 19 Jan 2020 09:57:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <20200116162101.GD20561@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/01/20 17:21, Sean Christopherson wrote: > On Thu, Jan 16, 2020 at 09:55:57AM +0100, Vitaly Kuznetsov wrote: >> Liran Alon writes: >> >>>> On 15 Jan 2020, at 19:10, Vitaly Kuznetsov wrote: >>>> >>>> Sane L1 hypervisors are not supposed to turn any of the unsupported VMX >>>> controls on for its guests and nested_vmx_check_controls() checks for >>>> that. This is, however, not the case for the controls which are supported >>>> on the host but are missing in enlightened VMCS and when eVMCS is in use. >>>> >>>> It would certainly be possible to add these missing checks to >>>> nested_check_vm_execution_controls()/_vm_exit_controls()/.. but it seems >>>> preferable to keep eVMCS-specific stuff in eVMCS and reduce the impact on >>>> non-eVMCS guests by doing less unrelated checks. Create a separate >>>> nested_evmcs_check_controls() for this purpose. >>>> >>>> Signed-off-by: Vitaly Kuznetsov >>>> --- >>>> arch/x86/kvm/vmx/evmcs.c | 56 ++++++++++++++++++++++++++++++++++++++- >>>> arch/x86/kvm/vmx/evmcs.h | 1 + >>>> arch/x86/kvm/vmx/nested.c | 3 +++ >>>> 3 files changed, 59 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c >>>> index b5d6582ba589..88f462866396 100644 >>>> --- a/arch/x86/kvm/vmx/evmcs.c >>>> +++ b/arch/x86/kvm/vmx/evmcs.c >>>> @@ -4,9 +4,11 @@ >>>> #include >>>> >>>> #include "../hyperv.h" >>>> -#include "evmcs.h" >>>> #include "vmcs.h" >>>> +#include "vmcs12.h" >>>> +#include "evmcs.h" >>>> #include "vmx.h" >>>> +#include "trace.h" >>>> >>>> DEFINE_STATIC_KEY_FALSE(enable_evmcs); >>>> >>>> @@ -378,6 +380,58 @@ void nested_evmcs_filter_control_msr(u32 msr_index, u64 *pdata) >>>> *pdata = ctl_low | ((u64)ctl_high << 32); >>>> } >>>> >>>> +int nested_evmcs_check_controls(struct vmcs12 *vmcs12) >>>> +{ >>>> + int ret = 0; >>>> + u32 unsupp_ctl; >>>> + >>>> + unsupp_ctl = vmcs12->pin_based_vm_exec_control & >>>> + EVMCS1_UNSUPPORTED_PINCTRL; >>>> + if (unsupp_ctl) { >>>> + trace_kvm_nested_vmenter_failed( >>>> + "eVMCS: unsupported pin-based VM-execution controls", >>>> + unsupp_ctl); >>> >>> Why not move "CC” macro from nested.c to nested.h and use it here as-well instead of replicating it’s logic? >>> >> >> Because error messages I add are both human readable and conform to SDM! >> :-) >> >> On a more serious not yes, we should probably do that. We may even want >> to use it in non-nesting (and non VMX) code in KVM. > > No, the CC() macro is short for Consistency Check, i.e. specific to nVMX. > Even if KVM ends up adding nested_evmcs_check_controls(), which I'm hoping > can be avoided, I'd still be hesitant to expose CC() in nested.h. > For now let's keep Vitaly's patch as is. It's definitely a good one as it would catch Hyper-V's issue immediately even without patch 2 (which is the only really contentious change). Paolo