Received: by 10.223.176.5 with SMTP id f5csp1850842wra; Wed, 31 Jan 2018 12:35:38 -0800 (PST) X-Google-Smtp-Source: AH8x227sfP9mzFS55ZmCAlNSR28aDUA0LbjaVJNjx8gP+g4r4zwf3a+GJ9owvQ6DeHzw/BvH/THD X-Received: by 10.99.120.8 with SMTP id t8mr18586580pgc.371.1517430938267; Wed, 31 Jan 2018 12:35:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517430938; cv=none; d=google.com; s=arc-20160816; b=daB42ks6eUaHJJNvgiJfz8VaMDxE2a4FZvyV0/PF8ZiwW0GDXuYhCDSRBaDbKeUdb2 MhpJHXMRfGUXQl7ZCgAGVciL0eNbcmsnoBUpGvXpKqKkiCWH3Dv0Lh82OqprkixyPP4X uzSeG7bxRgCEwLOB4T9KsP4ilwDZ0XEV7nglmpTYxH74qHRGK7tAPV+k8Y3Vncj/9YeI Gi4NMuqqWDP+JwNrQrW5Ponv3hEzgmBhKo+l30miCLatjyY3KNcD/n3Nh2y/jrKvfalD n2Y6GtfeO7vYdjvh/GJPCkImn4Q54I/2K9quRZIFCU6ALSbh7IR93hRV+1dgrsoqFvp/ 6I0A== 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:arc-authentication-results; bh=73J7V4icWxHhWi3bsLgRW88Ac7AAqi6WK62O+NoSjrQ=; b=JlH1dr0qJRXW/7zmrdPNN1GCvOuYHgxzKuH9lZJTp8GuXk7YAYaLShWF10zbW6p3l5 P68fpbWsgKpyOk5zTsNyschWsbkYxpWWsnqgQdEI7H/6y92O2l0X65SCUyF/VcdtB6Sy 814OliGpSwnhk2hXtsdmCCoSZVXVYJIXeesDyHbgbEJr5E7M6T7L4Zct2dVtR/tmV+cU 2K6BGLp4lZkt2M2m7tgaUHeIQIgzRokz1vz7o0nQDMEzayZzXmLXjEX0z3LaOwjJ/hak 2rB698jUf1vSGD1XCTcUryFTQyA/wKaKKhX+PWX9pd/MB/nNKH+b0BihDlmhaazlXKNj FCFA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 o12-v6si14420731plg.133.2018.01.31.12.35.23; Wed, 31 Jan 2018 12:35:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751760AbeAaUe6 (ORCPT + 99 others); Wed, 31 Jan 2018 15:34:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54204 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751190AbeAaUe5 (ORCPT ); Wed, 31 Jan 2018 15:34:57 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0919B28237; Wed, 31 Jan 2018 20:34:57 +0000 (UTC) Received: from [10.36.116.69] (ovpn-116-69.ams2.redhat.com [10.36.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E87660BE3; Wed, 31 Jan 2018 20:34:50 +0000 (UTC) Subject: Re: [PATCH v5 4/5] KVM: VMX: Allow direct access to MSR_IA32_SPEC_CTRL To: Jim Mattson , KarimAllah Ahmed Cc: KarimAllah Ahmed , kvm list , LKML , the arch/x86 maintainers , Asit Mallick , Arjan Van De Ven , Dave Hansen , Andi Kleen , Andrea Arcangeli , Linus Torvalds , Tim Chen , Thomas Gleixner , Dan Williams , Jun Nakajima , David Woodhouse , Greg KH , Andy Lutomirski , Ashok Raj References: <1517427467-28567-1-git-send-email-karahmed@amazon.de> <1517427467-28567-5-git-send-email-karahmed@amazon.de> <06cb88da-f355-41ed-380f-7daa8ddf6159@amazon.com> From: Paolo Bonzini Message-ID: <67dca2bb-1298-c7fa-f681-018e4edc6725@redhat.com> Date: Wed, 31 Jan 2018 15:34:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 31 Jan 2018 20:34:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31/01/2018 15:18, Jim Mattson wrote: >> but save_spec_ctrl_on_exit is also set for L2 write. So once L2 writes >> to it, this condition will be true and then the bitmap will be updated. > So if L1 or any L2 writes to the MSR, then save_spec_ctrl_on_exit is > set to true, even if the MSR permission bitmap for a particular VMCS > *doesn't* allow the MSR to be written without an intercept. That's > functionally correct, but inefficient. It seems to me that > save_spec_ctrl_on_exit should indicate whether or not the *current* > MSR permission bitmap allows unintercepted writes to IA32_SPEC_CTRL. > To that end, perhaps save_spec_ctrl_on_exit rightfully belongs in the > loaded_vmcs structure, alongside the msr_bitmap pointer that it is > associated with. For vmcs02, nested_vmx_merge_msr_bitmap() should set > the vmcs02 save_spec_ctrl_on_exit based on (a) whether L0 is willing > to yield the MSR to L1, and (b) whether L1 is willing to yield the MSR > to L2. On the first nested write, (b) must be true for L0 to see the MSR write. If L1 doesn't yield the MSR to L2, the MSR write results in an L2->L1 vmexit and save_spec_ctrl_on_exit is not set to true. So save_spec_ctrl_on_exit is set if all of the following are true: (a) L0 is willing to yield the MSR to L1, (b) and the write happens in L1, or all of the following are true: (a) L0 is willing to yield the MSR to L1, (b) L1 is willing to yield the MSR to L2, (c) and the write happens in L2, It doesn't need to be placed in loaded_vmcs, because in the end if L1 is willing to yield the MSR to L2, it will have to do reads and writes of the MSR too, and both loaded_vmcs structs will have save_spec_ctrl_on_exit=1. Paolo