From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x225k5Nx+eIhzsFGG9W7Acr02WwankH+9+jjjm+qMXkdLNpEb0YUAypd7XHIJS6YTLtkHfqcy ARC-Seal: i=1; a=rsa-sha256; t=1517355182; cv=none; d=google.com; s=arc-20160816; b=ygfmvg7xNgpiuR/MFnlQdFwvRHU2aLJQD/jJHLiMoGZ/xk4jLeRGy6c2hjgU5vH2RK P8uvPt54K8tHWwyrmXaE7I52dAY4JJuYP9giFPL+W0VIOsz/pBjes5z1fB0a8NM2CHJZ bbDJADJf4rfKmK9feUoUAm2mqVLalBuXJYnbixWyAv4Zjfba4xD/zjBBKLMNR2mQ4MQK 8uvD5utrzwA8Koy+7YLgo+S+r5sFpic+3LhtCES7YgF7PN98D4kMKRWF8ThfY2YYC6wn z1GnL3Vki7ywCTAYvHiXMCtpMZprsV/STQ+xVIojvGu7kNis1dfRTOoPWZ6IcUuYYQMh /r+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :arc-authentication-results; bh=OI85Nk+/N8G0DwDykJS9dL9klpoorF2zyuUPfAImy/k=; b=uQk8zk3aWNfNEX3npQd6RYONVPJDCmH9Q7rI2DBG4jpp7d6+/KUM7fmLSnDG/LycOH I188nuqeGtFOi/Mbffdjfh9bFDuLKVgdnSgPZXAFBetqU+ylc/SwDUcCLdnJpxiB5CUQ wqt6ZXT/uTYDLskfsHkrPzYTQXcFNIYAfE2K3mMs8gXCF5vAgvhiM2VeMhJby1l6aP6Y 0dfXjKri7LWvE2W64N7FiSEqBrS6/uyTIOa+JhlvJqraZUdsjmO6zYAsdtxObECAkG0f ohhiQvBnTobnWZJNUbZsQRooYadEdyqsv2pn0XxNtwSMgXctA6GIVMuZOIdHeAWAYOaK B9Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of pbonzini@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Authentication-Results: mx.google.com; spf=pass (google.com: domain of pbonzini@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Subject: Re: [PATCH v3 4/4] 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: <1517271028-15916-1-git-send-email-karahmed@amazon.de> <1517271028-15916-5-git-send-email-karahmed@amazon.de> <43859417-ae76-ed1f-eb4f-8a84a35998fc@amazon.com> From: Paolo Bonzini Message-ID: <059c3802-9336-80bd-2e6a-36663ed099ab@redhat.com> Date: Tue, 30 Jan 2018 18:32:52 -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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590974131114135545?= X-GMAIL-MSGID: =?utf-8?q?1591062227912217045?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On 30/01/2018 17:49, Jim Mattson wrote: > On Tue, Jan 30, 2018 at 1:00 PM, KarimAllah Ahmed wrote: >> Ooops! I did not think at all about nested :) >> >> This should be addressed now, I hope: >> >> http://git.infradead.org/linux-retpoline.git/commitdiff/f7f0cbba3e0cffcee050a8a5a9597a162d57e572 > > + if (cpu_has_vmx_msr_bitmap() && data && > + !vmx->save_spec_ctrl_on_exit) { > + vmx->save_spec_ctrl_on_exit = true; > + > + msr_bitmap = is_guest_mode(vcpu) ? > vmx->nested.vmcs02.msr_bitmap : > + > vmx->vmcs01.msr_bitmap; > + vmx_disable_intercept_for_msr(msr_bitmap, > + MSR_IA32_SPEC_CTRL, > + MSR_TYPE_RW); > + } > > There are two ways to get to this point in vmx_set_msr while > is_guest_mode(vcpu) is true: > 1) L0 is processing vmcs12's VM-entry MSR load list on emulated > VM-entry (see enter_vmx_non_root_mode). > 2) L2 tried to execute WRMSR, writes to the MSR are intercepted in > vmcs02's MSR permission bitmap, and writes to the MSR are not > intercepted in vmcs12's MSR permission bitmap. > > In the first case, disabling the intercepts for the MSR in > vmx->nested.vmcs02.msr_bitmap is incorrect, because we haven't yet > determined that the intercepts are clear in vmcs12's MSR permission > bitmap. > In the second case, disabling *both* of the intercepts for the MSR in > vmx->nested.vmcs02.msr_bitmap is incorrect, because we don't know that > the read intercept is clear in vmcs12's MSR permission bitmap. > Furthermore, disabling the write intercept for the MSR in > vmx->nested.vmcs02.msr_bitmap is somewhat fruitless, because > nested_vmx_merge_msr_bitmap is just going to undo that change on the > next emulated VM-entry. > Let's keep the original code from David, touching the L0->L1 MSR bitmap unconditionally, and possibly add an "&& !is_guest_mode (vcpu)" to the condition. Paolo