Re: [PATCH] KVM: nVMX: Fix CR4 after VMLAUNCH/VMRESUME failure

2018-02-05 Thread Jim Mattson
[Resending as plain text] On Mon, Feb 5, 2018 at 10:21 AM Jim Mattson wrote: > This is incorrect. In the event of an early VM-entry failure (e.g. a > VM-entry failure for "VM entry with invalid control field(s)"), no host > state should be loaded from the VMCS12. Of cou

Re: [RFC 02/12] KVM/VMX: Use the new host mapping API for apic_access_page

2018-02-05 Thread Jim Mattson
Perhaps this is a good time to address the long-standing issues with kvm's treatment of the "APIC-access address" in the VMCS. This address is simply a token that the hypervisor puts into the PFN of a 4K EPTE (or PTE if using shadow paging) that triggers APIC virtualization whenever a page walk ter

Re: [PATCH 7/9] KVM/VMX: Emulate MSR_IA32_ARCH_CAPABILITIES

2018-02-16 Thread Jim Mattson
On Fri, Feb 16, 2018 at 6:18 AM, Paolo Bonzini wrote: > Uhm, taking contents from the hardware is wrong (guess why---live > migration). I'll send a revert of those two lines. Hardware seems like a reasonable place to get the default value (cf. the VMX capability MSRs). Should these two lines ju

Re: [PATCH] KVM: nVMX: Fix CR4 after VMLAUNCH/VMRESUME failure

2018-02-12 Thread Jim Mattson
On Sun, Feb 11, 2018 at 3:56 AM, Wanpeng Li wrote: > Writes 0 to cr3 can't be detected during vmentry checks by hardware. I never suggested otherwise. I was just trying to explain why you can't assume that the host CR3 field in the VMCS matches the host CR3 at the time of VMLAUNCH. KVM is set u

Re: [PATCH] KVM: nVMX: remove unnecessary vmwrite from L2->L1 vmexit

2018-01-01 Thread Jim Mattson
Reviewed-by: Jim Mattson On Mon, Jan 1, 2018 at 2:58 PM, Paolo Bonzini wrote: > The POSTED_INTR_NV field is constant (though it differs between the vmcs01 and > vmcs02), there is no need to reload it on vmexit to L1. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/

Re: [RFC 05/12] KVM/VMX: Use the new host mapping API for mapping nested vmptr

2018-02-05 Thread Jim Mattson
On Mon, Feb 5, 2018 at 10:49 AM KarimAllah Ahmed wrote: > @@ -7410,19 +7410,17 @@ static int handle_vmon(struct kvm_vcpu *vcpu) > return kvm_skip_emulated_instruction(vcpu); > } > - page = kvm_vcpu_gpa_to_page(vcpu, vmptr); > - if (is_error_page(page)) { >

Re: [RFC 03/12] KVM/VMX: Use the new host mapping API for virtual_apic_page

2018-02-05 Thread Jim Mattson
On Mon, Feb 5, 2018 at 10:48 AM KarimAllah Ahmed wrote: > @@ -5264,9 +5264,8 @@ static void vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu) > max_irr = find_last_bit((unsigned long *)vmx->nested.pi_desc->pir, 256); > if (max_irr != 256) { > - vapic_pag

Re: [PATCH] KVM: nVMX: Fix CR4 after VMLAUNCH/VMRESUME failure

2018-02-06 Thread Jim Mattson
On Mon, Feb 5, 2018 at 4:57 PM, Wanpeng Li wrote: > This is effective one, what I restore in this patch is > achitectural/guest visible. This patch doesn't "restore" the guest visible CR4 to its value at the time of VMLAUNCH/VMRESUME. It loads a new CR4 value from the vmcs12. That behavior is in

Re: [PATCH] KVM: nVMX: Fix CR4 after VMLAUNCH/VMRESUME failure

2018-02-07 Thread Jim Mattson
is no VM-exit from L2 to L1, and these fields are not loaded. Instead, execution just falls through to the next instruction with VMFailValid semantics. On Wed, Feb 7, 2018 at 12:31 AM, Wanpeng Li wrote: > 2018-02-07 0:58 GMT+08:00 Jim Mattson : >> On Mon, Feb 5, 2018 at 4:57 PM, Wanpen

Re: [PATCH 3/3] KVM: VMX: introduce X2APIC_MSR macro

2017-12-20 Thread Jim Mattson
Reviewed-by: Jim Mattson On Wed, Dec 20, 2017 at 4:05 AM, Paolo Bonzini wrote: > Remove duplicate expression in nested_vmx_prepare_msr_bitmap, and make > the register names clearer in hardware_setup. > > Suggested-by: Jim Mattson > Signed-off-by: Paolo Bonzini > --- > ar

Re: [PATCH 1/3] KVM: vmx: speed up MSR bitmap merge

2017-12-20 Thread Jim Mattson
Reviewed-by: Jim Mattson On Wed, Dec 20, 2017 at 4:05 AM, Paolo Bonzini wrote: > The bulk of the MSR bitmap is either immutable, or can be copied from > the L1 bitmap. By initializing it at VMXON time, and copying the mutable > parts one long at a time on vmentry (rather than one bi

Re: [PATCH 2/3] KVM: vmx: simplify MSR bitmap setup

2017-12-20 Thread Jim Mattson
This doesn't look right to me. Without APIC-register virtualization, the only X2APIC MSR intercept that should be disabled is TPR. On Wed, Dec 20, 2017 at 4:05 AM, Paolo Bonzini wrote: > The APICv-enabled MSR bitmap is a superset of the APICv-disabled bitmap. > Make that obvious in vmx_disable_in

Re: [PATCH 2/3] KVM: vmx: simplify MSR bitmap setup

2017-12-21 Thread Jim Mattson
Reviewed-by: Jim Mattson On Thu, Dec 21, 2017 at 3:51 AM, Paolo Bonzini wrote: > The APICv-enabled MSR bitmap passes through all MSRs in the > APICv-disabled bitmap (and then some). Make that obvious in > vmx_disable_intercept_msr_x2apic. > > Signed-off-by: Paolo Bonzini >

Re: [PATCH 1/4] KVM: VMX: split list of shadowed VMCS field to a separate file

2017-12-21 Thread Jim Mattson
Reviewed-by: Jim Mattson On Thu, Dec 21, 2017 at 4:43 AM, Paolo Bonzini wrote: > Prepare for multiple inclusions of the list. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/vmx.c | 64 +++- > arch/x86/kvm/vmx_sh

Re: [PATCH 2/4] KVM: nVMX: track dirty state of non-shadowed VMCS fields

2017-12-21 Thread Jim Mattson
Reviewed-by: Jim Mattson On Thu, Dec 21, 2017 at 4:43 AM, Paolo Bonzini wrote: > VMCS12 fields that are not handled through shadow VMCS are rarely > written, and thus they are also almost constant in the vmcs02. We can > thus optimize prepare_vmcs02 by skipping all the work for non

Re: [PATCH v2] KVM: VMX: Fix rflags cache during vCPU reset

2017-12-04 Thread Jim Mattson
That seems like a convoluted path to produce an illegal RFLAGS value. What's to prevent syzkaller from simply clearing bit 1 of RFLAGS with the KVM_SET_REGS ioctl? On Mon, Nov 20, 2017 at 4:34 PM, Wanpeng Li wrote: > 2017-11-21 7:09 GMT+08:00 Paolo Bonzini : >> On 20/11/2017 23:52, Wanpeng Li wro

Re: [PATCH v2] KVM: VMX: Fix rflags cache during vCPU reset

2017-12-05 Thread Jim Mattson
Sorry; I didn't mean to derail this patch thread. Setting bit 1 of RFLAGS on CPU reset is clearly correct. I was just noting that if syzkaller is complaining about illegal RFLAGS, it's trivial for userspace to set RFLAGS to an illegal value. User space can set all kinds of illegal RFLAGS state...b

Re: [PATCH RFC 2/7] KVM: nVMX: modify vmcs12 fields to match Hyper-V enlightened VMCS

2017-12-18 Thread Jim Mattson
Yikes! This breaks migration to/from older versions of kvm. Will you be submitting another change to handle dynamic conversion between formats? On Mon, Dec 18, 2017 at 9:17 AM, Vitaly Kuznetsov wrote: > From: Ladi Prosek > > Reorders existing fields and adds fields specific to Hyper-V. The layou

Re: [PATCH RFC 2/7] KVM: nVMX: modify vmcs12 fields to match Hyper-V enlightened VMCS

2017-12-18 Thread Jim Mattson
es to KVM_CAP_HYPERV_ENLIGHTENED_VMCS if you like, but kvm must be able to continue to service VMs using the previous layout and revision number in perpetuity. On Mon, Dec 18, 2017 at 12:23 PM, Jim Mattson wrote: > Yikes! This breaks migration to/from older versions of kvm. Will you > be submitting anothe

Re: [PATCH RFC 2/7] KVM: nVMX: modify vmcs12 fields to match Hyper-V enlightened VMCS

2017-12-19 Thread Jim Mattson
On Tue, Dec 19, 2017 at 4:37 AM, Paolo Bonzini wrote: > On 19/12/2017 13:25, Vitaly Kuznetsov wrote: >> >>> At this point in time, I don't think you can just blithely change the >>> virtual VMCS layout and revision number. Existing VMs using the old >>> layout and revision number must continue to

Re: [PATCH RFC 2/7] KVM: nVMX: modify vmcs12 fields to match Hyper-V enlightened VMCS

2017-12-19 Thread Jim Mattson
: > Jim Mattson writes: > >> At this point in time, I don't think you can just blithely change the >> virtual VMCS layout and revision number. Existing VMs using the old >> layout and revision number must continue to work on versions of kvm >> past this point. Yo

Re: [PATCH] KVM: vmx: speed up MSR bitmap merge

2017-12-19 Thread Jim Mattson
k cycles (30%) can be saved on a nested VMLAUNCH/VMRESUME. > > The resulting for loop only has four iterations, so it is cheap enough > to reinitialize the MSR write bitmaps on every iteration, and it makes > the code simpler. Thanks so much for doing this! > Suggested-by: Jim Matt

Re: [PATCH] KVM: x86: avoid unnecessary XSETBV on guest entry

2017-12-13 Thread Jim Mattson
Reviewed-by: Jim Mattson On Wed, Dec 13, 2017 at 4:51 AM, Paolo Bonzini wrote: > xsetbv can be expensive when running on nested virtualization, try to > avoid it. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 3 ++- > 1 file changed, 2 insertions(+), 1

Re: [PATCH] KVM: X86: Fix residual mmio emulation request to userspace

2017-08-10 Thread Jim Mattson
I'm not convinced that this plugs all of the mmio_needed/pio.count leaks, but it's a start. Syzkaller will eventually let us know about the others. On Thu, Aug 10, 2017 at 7:23 AM, Paolo Bonzini wrote: > On 10/08/2017 16:09, Dmitry Vyukov wrote: >> On Thu, Aug 10, 2017 at 3:44 PM, Paolo Bonzini

Re: [PATCH] KVM: MMU: speedup update_permission_bitmask

2017-08-28 Thread Jim Mattson
Looks okay to me, but I'm hoping Peter will chime in. Reviewed-by: Jim Mattson On Thu, Aug 24, 2017 at 8:56 AM, Paolo Bonzini wrote: > update_permission_bitmask currently does a 128-iteration loop to, > essentially, compute a constant array. Computing the 8 bits in parallel > re

Re: [PATCH 1/4] KVM: nVMX: move vmentry tasks from prepare_vmcs12 to enter_vmx_non_root_mode

2017-08-23 Thread Jim Mattson
On Wed, Aug 23, 2017 at 1:43 PM, Paolo Bonzini wrote: > Setting the VMCS12 to launched and clearing the vm_entry_intr_info_field > was done as part of L0->L1 exit in prepare_vmcs12. In order to simplify > prepare_vmcs12, move this to enter_vmx_non_root_mode since at this point > we've already com

Re: [PATCH 1/4] KVM: VMX: cache secondary exec controls

2017-08-24 Thread Jim Mattson
On Thu, Aug 24, 2017 at 6:37 AM, Paolo Bonzini wrote: > Currently, secondary execution controls are divided in three groups: > > - static, depending mostly on the module arguments or the processor > (vmx_secondary_exec_control) > > - static, depending on CPUID (vmx_cpuid_update) There should al

Re: [PATCH 4/4] kvm: vmx: Raise #UD on unsupported XSAVES/XRSTORS

2017-08-24 Thread Jim Mattson
On Thu, Aug 24, 2017 at 6:37 AM, Paolo Bonzini wrote: > A guest may not be configured to support XSAVES/XRSTORS, even when the host > does. If the guest does not support XSAVES/XRSTORS, clear the secondary > execution control so that the processor will raise #UD. > > Also clear the "allowed-1" bit

Re: [PATCH 1/4] KVM: VMX: cache secondary exec controls

2017-08-24 Thread Jim Mattson
On 24/08/2017 16:47, Jim Mattson wrote: >>> Currently, secondary execution controls are divided in three groups: >>> >>> - static, depending mostly on the module arguments or the processor >>> (vmx_secondary_exec_control) >>> >>> - static,

Re: [PATCH 1/4] KVM: VMX: cache secondary exec controls

2017-08-24 Thread Jim Mattson
SSE2 without SSE, or XSAVES without XSAVE, or RDTSCP without TSC, or DS-CPL without DS, or ...? On Thu, Aug 24, 2017 at 8:46 AM, Paolo Bonzini wrote: > On 24/08/2017 17:41, Jim Mattson wrote: >> Userspace can establish the value of the virtualized >> IA32_VMX_PROCBASED_CTLS2 MSR via th

Re: [PATCH v8 4/4] kvm: vmx: Raise #UD on unsupported XSAVES/XRSTORS

2017-08-24 Thread Jim Mattson
Reviewed-by: Jim Mattson On Thu, Aug 24, 2017 at 9:09 AM, Paolo Bonzini wrote: > A guest may not be configured to support XSAVES/XRSTORS, even when the host > does. If the guest does not support XSAVES/XRSTORS, clear the secondary > execution control so that the processor will

Re: [PATCH v3 2/5] KVM: MMU: check guest CR3 reserved bits based on its physical address width.

2017-09-15 Thread Jim Mattson
On Thu, Aug 24, 2017 at 5:27 AM, Yu Zhang wrote: > Currently, KVM uses CR3_L_MODE_RESERVED_BITS to check the > reserved bits in CR3. Yet the length of reserved bits in > guest CR3 should be based on the physical address width > exposed to the VM. This patch changes CR3 check logic to > calculate t

Re: [PATCH] KVM: x86: Fix the NULL pointer parameter in check_cr_write()

2017-09-18 Thread Jim Mattson
kvm_cpuid ultimately wants to write all four of the GPRs passed in by reference. I don't see any advantage to allowing some of these pointers to be NULL. Reviewed-by: Jim Mattson On Mon, Sep 18, 2017 at 5:19 AM, David Hildenbrand wrote: > On 18.09.2017 12:45, Yu Zhang wrote: &g

Re: [PATCH v3 2/2] KVM: VMX: Don't expose unrestricted_guest is enabled if ept is disabled

2017-10-10 Thread Jim Mattson
Reviewed-by: Jim Mattson On Mon, Oct 9, 2017 at 3:51 PM, Wanpeng Li wrote: > From: Wanpeng Li > > SDM mentioned: > > "If either the “unrestricted guest” VM-execution control or the “mode-based > execute control for EPT” VM- execution control is 1, the “enable EPT” &

Re: [PATCH RFC 00/10] Intel EPT-Based Sub-page Write Protection Support.

2017-10-13 Thread Jim Mattson
I'll ask before Paolo does: Can you please add kvm-unit-tests to exercise all of this new code? BTW, what generation of hardware do we need to exercise this code ourselves? On Fri, Oct 13, 2017 at 4:11 PM, Zhang Yi wrote: > From: Zhang Yi Z > > Hi All, > > Here is a patch-series which adding EP

Re: [PATCH 1/2] KVM: VMX: Don't expose unrestricted_guest is enabled if ept is disabled

2017-10-08 Thread Jim Mattson
If it were me, I'd apply De Morgan to that expression, but the logic looks fine. Reviewed-by: Jim Mattson On Sat, Oct 7, 2017 at 7:35 PM, Wanpeng Li wrote: > From: Wanpeng Li > > SDM mentioned: > > "If either the “unrestricted guest” VM-execution control or th

Re: [PATCH 2/2] KVM: X86: XCR0 should be set to the fixed value on vCPU reset

2017-10-08 Thread Jim Mattson
Reviewed-by: Jim Mattson On Sat, Oct 7, 2017 at 7:35 PM, Wanpeng Li wrote: > From: Wanpeng Li > > SDM section 2.6 mentioned: > > After reset, all bits (except bit 0) in XCR0 are cleared to zero; XCR0[0] is > set to 1. > > This patch sets XCRO to the 0x1 after vCPU rese

Re: [PATCH v2 2/2] KVM: VMX: Don't expose unrestricted_guest is enabled if ept is disabled

2017-10-09 Thread Jim Mattson
> parameter > and exec control fields will be amended. > > This patch fixes it by amending module parameter immediately during vmcs data > setup. > > Reviewed-by: Jim Mattson > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Jim Mattson > Signed-off-by: Wanpeng Li >

Re: [PATCH v1 1/4] KVM: MMU: check guest CR3 reserved bits based on its physical address width.

2017-08-14 Thread Jim Mattson
On Sat, Aug 12, 2017 at 6:35 AM, Yu Zhang wrote: > Currently, KVM uses CR3_L_MODE_RESERVED_BITS to check the > reserved bits in CR3. Yet the length of reserved bits in > guest CR3 should be based on the physical address width > exposed to the VM. This patch changes CR3 check logic to > calculate t

Re: [PATCH v2] KVM: X86: Fix load RFLAGS w/o the fixed bit

2017-12-06 Thread Jim Mattson
.rflags = 0, >> }; >> ioctl(r[4], KVM_SET_REGS, ®s); >> ioctl(r[4], KVM_RUN, 0); >> } >> >> X86 RFLAGS bit 1 is fixed set, userspace can simply clearing bit 1 >> of RFLAGS with KVM_SET_REGS ioctl which results in vmentry fai

Re: WARNING in x86_emulate_insn

2017-12-07 Thread Jim Mattson
Try disabling the module parameter, "unrestricted_guest." Make sure that the module parameter, "emulate_invalid_guest_state" is enabled. This combination allows userspace to feed invalid guest state into the in-kernel emulator. On Thu, Dec 7, 2017 at 2:40 AM, Wanpeng Li wrote: > 2017-12-07 15:52

Re: [PATCH v5 3/3] KVM: nVMX: Fix mmu context after VMLAUNCH/VMRESUME failure

2017-11-08 Thread Jim Mattson
since vmcs12 is not modified (except for the VM-instruction error field) >> if the checking of vmcs control area fails. However, the mmu context is >> switched to nested mmu in prepare_vmcs02() and it will not be reloaded >> since load_vmcs1

Re: [PATCH v5 3/3] KVM: nVMX: Fix mmu context after VMLAUNCH/VMRESUME failure

2017-11-09 Thread Jim Mattson
Will do. On Thu, Nov 9, 2017 at 2:40 AM, Paolo Bonzini wrote: > On 09/11/2017 01:37, Wanpeng Li wrote: >> 2017-11-09 5:47 GMT+08:00 Jim Mattson : >>> I realize now that there are actually many other problems with >>> deferring some control field checks to the hard

Re: [PATCH v2] KVM: VMX: Cache IA32_DEBUGCTL in memory

2017-11-29 Thread Jim Mattson
Thanks for doing this! Reviewed-by: Jim Mattson On Wed, Nov 29, 2017 at 1:31 AM, Wanpeng Li wrote: > From: Wanpeng Li > > MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT, so it is saved/restored > each time during world switch. Jim from Google pointed out that > when running

Re: [PATCH] KVM: VMX: Cache IA32_DEBUGCTL in memory

2017-11-29 Thread Jim Mattson
An alternative is to give the L1 guest read permission for this MSR in the MSR permission bitmaps. It's still going to be ~80 cycles, but that's better than the cost of a VM-exit/VM-entry round-trip. On Wed, Nov 29, 2017 at 10:20 AM, Andi Kleen wrote: > Wanpeng Li writes: > >> From: Wanpeng Li

Re: [PATCH] KVM: VMX: drop I/O permission bitmaps

2017-12-08 Thread Jim Mattson
permission bitmaps. > > Signed-off-by: Jim Mattson > Signed-off-by: Radim Krčmář > Signed-off-by: Quan Xu > --- > arch/x86/kvm/vmx.c | 17 + > 1 files changed, 1 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >

Re: [PATCH] KVM: VMX: drop I/O permission bitmaps

2017-12-11 Thread Jim Mattson
access them. On Sun, Dec 10, 2017 at 9:37 PM, Quan Xu wrote: > > > On 2017/12/09 01:31, Jim Mattson wrote: >> >> On Fri, Dec 8, 2017 at 2:22 AM, Quan Xu wrote: >>> >>> From: Quan Xu >>> >>> Since KVM removes the only I/O port 0x80 bypa

[tip: perf/core] perf/x86/kvm: Add Cascade Lake Xeon steppings to isolation_ucodes[]

2021-02-10 Thread tip-bot2 for Jim Mattson
The following commit has been merged into the perf/core branch of tip: Commit-ID: b3c3361fe325074d4144c29d46daae4fc5a268d5 Gitweb: https://git.kernel.org/tip/b3c3361fe325074d4144c29d46daae4fc5a268d5 Author:Jim Mattson AuthorDate:Fri, 05 Feb 2021 11:13:24 -08:00 Committer

<    1   2   3   4   5