Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp578762pxk; Wed, 23 Sep 2020 10:22:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBNspPxjN39+qkfopLn3KYFxXyvf/1Hd0uGgtY+MXpIarNq8dta6YvOQp59j8yJUus0iW7 X-Received: by 2002:a17:906:2cd2:: with SMTP id r18mr687080ejr.371.1600881770773; Wed, 23 Sep 2020 10:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600881770; cv=none; d=google.com; s=arc-20160816; b=hwaojaxWZghgNdZbkQU2TFEkjsCF1gFUo1uBLrSUWif/fFxDIkUNpZzkPQfeppfKzn +ctUNfkOs6PKhBopcT11cQjZ9EhiXC4LMxfR5bqJHljAzigKEDkKxKVygSTix6vsXRWC vgjINtmzX4ySpchOSY29MafDdAF4uXdiTEDqqle+MwcHb6Dq5+OetH0UjAyuZJgzdCVm WBEFPfsUuNq9dF9NXgVyHN1DljkWlugsq3uJBdG0EQu6DkAiECBcU9gfCqYHocx+SDA5 Y0ZYkoM7DZStfaRSgJvnS8pNIuaNphmwNF+XKexig9P/Ob4AQI5/N2B7mKKYWMVVqSy4 I2qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=qZFvXxnOLhEH+5dxb25balw/PWjti1ehR7buvEyRBXk=; b=WBbk3TydFy3z7j3JW1ygbWT6f87SSCHYjVUO3+FHU/gT502z16l1y3EsHKEEBWc4iq TcXRRs8gKtczOIrQjIoe8CGA9Tp1hH2Sl/Hjdl8Enr4GgFKWEm7R5ZMby0/LxerGqJCR SQE3DUPyawZVIR/MDp/l3eIsegyEKUa3oVye45rEI+NJi+Tl0pjBLYI1FgG5l5iO9FDg Sb0sQFslOauY9TYLI/fkZTyVpOyG2G3YzhsLp1rtbhB0jrUeh0XKo3Td9ErCRuUf/tQA L7/W7nN1Toi7SEDE/9DfY5kSBcpJIX5RMJwgiW/hLxkcyGEkpARNLEg7GZthu7pUjmKE iCGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bVDCRf/A"; 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 j5si294490eds.503.2020.09.23.10.22.26; Wed, 23 Sep 2020 10:22:50 -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="bVDCRf/A"; 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 S1726714AbgIWRUZ (ORCPT + 99 others); Wed, 23 Sep 2020 13:20:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59143 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726498AbgIWRUY (ORCPT ); Wed, 23 Sep 2020 13:20:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600881622; 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=qZFvXxnOLhEH+5dxb25balw/PWjti1ehR7buvEyRBXk=; b=bVDCRf/ATx0vbQgQ173qoB6NfOvKPiAlH5dXT53JaheHDw1pgjHKhphX0XK9Aw8NRq49sx mmnfVxfxX6/sO9ZmiXWaRYqVJ3KU09a5F5igLE8BcakB7N1dKGizpY3ePPG4S3u+UI47iZ /xpD9UZmhfOeMrllL5pEU9i9b2Ev0XM= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-BO6e4stLMQGWYzCIBG_9YQ-1; Wed, 23 Sep 2020 13:20:20 -0400 X-MC-Unique: BO6e4stLMQGWYzCIBG_9YQ-1 Received: by mail-wm1-f70.google.com with SMTP id c200so180714wmd.5 for ; Wed, 23 Sep 2020 10:20:20 -0700 (PDT) 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=qZFvXxnOLhEH+5dxb25balw/PWjti1ehR7buvEyRBXk=; b=dHGXFv+oQUGwZyqlSHd00j1jiosGhpwkGZjw56eC0k5joxssasPFWN05f54nny7G3X yw1VSnyhTcnqbdkr1oX5rwbDxdnoVmKazDGI5/wdf/3omM6lLsu/r0j8GiV0iDoEsI3T V32YnVEV5K8h/2NMT1I44v1FR+jQ37bZIh09kaqaWQoTKRvidy+nan6BaCRe5JeKSt03 0/ZBMS1Rl+6Ay/wW9t3/vEicVUCdfY4LGxpxDskC+fTYb5tj4spijL/EKG7Asr2ahT0X j+Ugzv+JSjqQ4tQKabvYsbSu+bLImRwz+iAVzrJ7MSNJ2e/36rKXY007VZeSAWAOjs4E /kGA== X-Gm-Message-State: AOAM5328hFONCo8K44t121uf7rc8sBAv8py0rD3rxBSwq8DR/oXB4KTL c07JNlQYIevEQZFLxitGh+75ijQwdI8rF03A1HE+3Qq2jahk7OaIOkYgV6qYU4OQ6z/RTuZ4ik1 CrLAWwz6N8zmFvjvnMdNppJAW X-Received: by 2002:a1c:3d44:: with SMTP id k65mr584139wma.132.1600881619295; Wed, 23 Sep 2020 10:20:19 -0700 (PDT) X-Received: by 2002:a1c:3d44:: with SMTP id k65mr584116wma.132.1600881618990; Wed, 23 Sep 2020 10:20:18 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:15f1:648d:7de6:bad9? ([2001:b07:6468:f312:15f1:648d:7de6:bad9]) by smtp.gmail.com with ESMTPSA id 97sm538185wrm.15.2020.09.23.10.20.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Sep 2020 10:20:17 -0700 (PDT) Subject: Re: [PATCH 4/4] KVM: VMX: Add a helper and macros to reduce boilerplate for sec exec ctls To: Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200923165048.20486-1-sean.j.christopherson@intel.com> <20200923165048.20486-5-sean.j.christopherson@intel.com> From: Paolo Bonzini Message-ID: <784480fd-3aeb-6c08-30f9-ac474bb23b6c@redhat.com> Date: Wed, 23 Sep 2020 19:20:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200923165048.20486-5-sean.j.christopherson@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/09/20 18:50, Sean Christopherson wrote: > Add a helper function and several wrapping macros to consolidate the > copy-paste code in vmx_compute_secondary_exec_control() for adjusting > controls that are dependent on guest CPUID bits. > > No functional change intended. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/vmx.c | 128 +++++++++++++---------------------------- > 1 file changed, 41 insertions(+), 87 deletions(-) The diffstat is enticing but the code a little less so... Can you just add documentation above vmx_adjust_secondary_exec_control that explains the how/why? Paolo > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 5180529f6531..b786cfb74f4f 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -4073,6 +4073,38 @@ u32 vmx_exec_control(struct vcpu_vmx *vmx) > } > > > +static inline void > +vmx_adjust_secondary_exec_control(struct vcpu_vmx *vmx, u32 *exec_control, > + u32 control, bool enabled, bool exiting) > +{ > + if (enabled == exiting) > + *exec_control &= ~control; > + if (nested) { > + if (enabled) > + vmx->nested.msrs.secondary_ctls_high |= control; > + else > + vmx->nested.msrs.secondary_ctls_high &= ~control; > + } > +} > + > +#define vmx_adjust_sec_exec_control(vmx, exec_control, name, feat_name, ctrl_name, exiting) \ > +({ \ > + bool __enabled; \ > + \ > + if (cpu_has_vmx_##name()) { \ > + __enabled = guest_cpuid_has(&(vmx)->vcpu, \ > + X86_FEATURE_##feat_name); \ > + vmx_adjust_secondary_exec_control(vmx, exec_control, \ > + SECONDARY_EXEC_##ctrl_name, __enabled, exiting); \ > + } \ > +}) > + > +#define vmx_adjust_sec_exec_feature(vmx, exec_control, lname, uname) \ > + vmx_adjust_sec_exec_control(vmx, exec_control, lname, uname, ENABLE_##uname, false) > + > +#define vmx_adjust_sec_exec_exiting(vmx, exec_control, lname, uname) \ > + vmx_adjust_sec_exec_control(vmx, exec_control, lname, uname, uname##_EXITING, true) > + > static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) > {