[PATCH 08/18] KVM: Move prototypes for MMU notifier callbacks to generic code

2021-03-25 Thread Sean Christopherson
Move the prototypes for the MMU notifier callbacks out of arch code and into common code. There is no benefit to having each arch replicate the prototypes since any deviation from the invocation in common code will explode. No functional change intended. Signed-off-by: Sean Christopherson

[PATCH 07/18] KVM: x86/mmu: Use leaf-only loop for walking TDP SPTEs when changing SPTE

2021-03-25 Thread Sean Christopherson
can consolidate the core iterating logic. No real functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 7fe5004b1565

[PATCH 05/18] KVM: x86/mmu: Pass address space ID to __kvm_tdp_mmu_zap_gfn_range()

2021-03-25 Thread Sean Christopherson
g TLB flushes across multiple address spaces in kvm_zap_gfn_range(), and also optimizes the TDP MMU to utilize range-based flushing when running as L1 with Hyper-V enlightenments. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 10 -- arch/x86/kvm/mmu/mmu_internal.h

[PATCH 04/18] KVM: x86/mmu: Coalesce TLB flushes across address spaces for gfn range zap

2021-03-25 Thread Sean Christopherson
iteration to cover the legacy and TDP MMUs without introducing truly ugly code. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 17 - 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 37e2432c78ca..e6

[PATCH 01/18] KVM: x86/mmu: Coalesce TDP MMU TLB flushes when zapping collapsible SPTEs

2021-03-25 Thread Sean Christopherson
may have serviced a prior pending flush. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 22 +- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 08667e3cf091

[PATCH 02/18] KVM: x86/mmu: Move flushing for "slot" handlers to caller for legacy MMU

2021-03-25 Thread Sean Christopherson
-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 37 +++-- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 7a99e59c8c1c..d5c9fb34971a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm

[PATCH 03/18] KVM: x86/mmu: Coalesce TLB flushes when zapping collapsible SPTEs

2021-03-25 Thread Sean Christopherson
with Hyper-V enlightenments. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 6 -- arch/x86/kvm/mmu/tdp_mmu.c | 8 +++- arch/x86/kvm/mmu/tdp_mmu.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c

[PATCH 00/18] KVM: Consolidate and optimize MMU notifiers

2021-03-25 Thread Sean Christopherson
or our particular use case. :-/ Patches 17-18 are additional x86 cleanups. Sean Christopherson (18): KVM: x86/mmu: Coalesce TDP MMU TLB flushes when zapping collapsible SPTEs KVM: x86/mmu: Move flushing for "slot" handlers to caller for legacy MMU KVM: x86/mmu: Coalesce TLB fl

Re: [PATCH v2 3/3] KVM: x86/mmu: Don't allow TDP MMU to yield when recovering NX pages

2021-03-25 Thread Sean Christopherson
On Thu, Mar 25, 2021, Ben Gardon wrote: > On Thu, Mar 25, 2021 at 1:01 PM Sean Christopherson wrote: > > +static inline bool kvm_tdp_mmu_zap_gfn_range(struct kvm *kvm, gfn_t start, > > +gfn_t end) > > +{ > > + return

[PATCH v2 3/3] KVM: x86/mmu: Don't allow TDP MMU to yield when recovering NX pages

2021-03-25 Thread Sean Christopherson
holding mmu_lock for read would break as the TDP MMU wouldn't be guaranteed to see the present shadow page, and thus could step sideways at a lower level. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 4 +--- arch/x86/kvm/mmu/tdp_mmu.c | 5 +++-- arch/x86/kvm

[PATCH v2 2/3] KVM: x86/mmu: Ensure TLBs are flushed for TDP MMU during NX zapping

2021-03-25 Thread Sean Christopherson
n no flush will occur. Fixes: 29cf0f5007a2 ("kvm: x86/mmu: NX largepage recovery for TDP MMU") Cc: sta...@vger.kernel.org Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 11 +++ 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch

[PATCH v2 1/3] KVM: x86/mmu: Ensure TLBs are flushed when yielding during GFN range zap

2021-03-25 Thread Sean Christopherson
wed-by: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 23 --- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index f0c99fa04ef2..6cf08c3c537f 100644 --- a/arch/x86/kvm/mm

[PATCH v2 0/3] KVM: x86/mmu: Fix TLB flushing bugs in TDP MMU

2021-03-25 Thread Sean Christopherson
atch since it's not strictly a bug fix and it's standalone anyways (the flush feedback loop was not). v1: - https://lkml.kernel.org/r/20210319232006.3468382-1-sea...@google.com Sean Christopherson (3): KVM: x86/mmu: Ensure TLBs are flushed when yielding during GFN range zap KVM: x86/m

Re: [PATCH 2/2] KVM: x86/mmu: Ensure TLBs are flushed when yielding during NX zapping

2021-03-25 Thread Sean Christopherson
On Tue, Mar 23, 2021, Ben Gardon wrote: > On Tue, Mar 23, 2021 at 11:58 AM Sean Christopherson > wrote: > > > > On Tue, Mar 23, 2021, Ben Gardon wrote: > > > On Mon, Mar 22, 2021 at 5:15 PM Sean Christopherson > > > wrote: > > > >

Re: [PATCH] KVM: VMX: Check the corresponding bits according to the intel sdm

2021-03-25 Thread Sean Christopherson
On Thu, Mar 25, 2021, Haiwei Li wrote: > On Tue, Mar 23, 2021 at 10:37 AM wrote: > > > > From: Haiwei Li > > > > According to IA-32 SDM Vol.3D "A.1 BASIC VMX INFORMATION", two inspections > > are missing. > > * Bit 31 is always 0. Earlier versions of this manual specified that the > > VMCS

Re: [PATCH] kbuild: Merge module sections if and only if CONFIG_LTO_CLANG is enabled

2021-03-24 Thread Sean Christopherson
On Tue, Mar 23, 2021, Sami Tolvanen wrote: > On Tue, Mar 23, 2021 at 9:36 AM Sean Christopherson wrote: > > > > On Tue, Mar 23, 2021, Sami Tolvanen wrote: > > > On Mon, Mar 22, 2021 at 4:44 PM Sean Christopherson > > > wrote: > > > > > >

Re: [PATCH 2/2] KVM: x86/mmu: Ensure TLBs are flushed when yielding during NX zapping

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Ben Gardon wrote: > On Mon, Mar 22, 2021 at 5:15 PM Sean Christopherson wrote: > > > > On Mon, Mar 22, 2021, Ben Gardon wrote: > > > It could be fixed by forbidding kvm_tdp_mmu_zap_gfn_range from > > > yielding. Since we should only need

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Paolo Bonzini wrote: > On 23/03/21 18:02, Sean Christopherson wrote: > > > That's important, but it's even more important *to developers* that the > > > commit message spells out why this would be a kernel bug more often than > > > not. I for o

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Paolo Bonzini wrote: > On 23/03/21 17:06, Borislav Petkov wrote: > > > Practically speaking, "basic" deployments of SGX VMs will be insulated > > > from > > > this bug. KVM doesn't support EPC oversubscription, so even if all EPC is > > > exhausted, new VMs will fail to

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Borislav Petkov wrote: > On Tue, Mar 23, 2021 at 04:21:47PM +0000, Sean Christopherson wrote: > > I like the idea of pointing at the documentation. The documentation should > > probably emphasize that something is very, very wrong. > > Yap, bec

Re: [PATCH] kbuild: Merge module sections if and only if CONFIG_LTO_CLANG is enabled

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Sami Tolvanen wrote: > On Mon, Mar 22, 2021 at 4:44 PM Sean Christopherson wrote: > > > > Merge module sections only when using Clang LTO. With gcc-10, merging > > sections does not appear to update the symbol tables for the module, > > e.g. '

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Borislav Petkov wrote: > On Tue, Mar 23, 2021 at 03:45:14PM +0000, Sean Christopherson wrote: > > Practically speaking, "basic" deployments of SGX VMs will be insulated from > > this bug. KVM doesn't support EPC oversubscription, so even if all EPC

Re: [PATCH] KVM: nSVM: Additions to optimizing L12 to L2 vmcb.save copies

2021-03-23 Thread Sean Christopherson
On Wed, Mar 17, 2021, Cathy Avery wrote: > Extend using the vmcb12 control clean field to determine which > vmcb12.save registers were marked dirty in order to minimize > register copies by including the CR bit. > > This patch also fixes the init of last_vmcb12_gpa by using an invalid > physical

Re: [RFC PATCH v5 00/10] KVM: selftests: some improvement and a new test for kvm page table

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Yanan Wang wrote: > Hi, > This v5 series can mainly include two parts. > Based on kvm queue branch: > https://git.kernel.org/pub/scm/virt/kvm/kvm.git/log/?h=queue Given the number of Reviewed-by tags, I'm pretty sure you can drop the "RFC" :-)

Re: [PATCH v4 1/3] KVM: nVMX: Sync L2 guest CET states between L1/L2

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Yang Weijiang wrote: > On Tue, Mar 16, 2021 at 05:03:47PM +0800, Yang Weijiang wrote: > > Hi, Sean, > Could you respond my below rely? I'm not sure how to proceed, thanks! > > > On Mon, Mar 15, 2021 at 09:45:11AM -0700, Sean Christopherson wrote: >

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-23 Thread Sean Christopherson
On Tue, Mar 23, 2021, Kai Huang wrote: > On Mon, 22 Mar 2021 23:37:26 +0100 Borislav Petkov wrote: > > "The instruction fails if the operand is not properly aligned or does > > not refer to an EPC page or the page is in use by another thread, or > > other threads are running in the enclave to

Re: [PATCH 2/2] KVM: x86/mmu: Ensure TLBs are flushed when yielding during NX zapping

2021-03-22 Thread Sean Christopherson
On Mon, Mar 22, 2021, Ben Gardon wrote: > On Fri, Mar 19, 2021 at 4:20 PM Sean Christopherson wrote: > > @@ -5960,19 +5963,21 @@ static void kvm_recover_nx_lpages(struct kvm *kvm) > > lpage_disallowed_link); > >

[PATCH] kbuild: Merge module sections if and only if CONFIG_LTO_CLANG is enabled

2021-03-22 Thread Sean Christopherson
, and presumably other things, e.g. gdb -batch -ex "file arch/x86/kvm/kvm.ko" -ex "disassemble kvm_init" reads the wrong bytes and dumps garbage. Fixes: dd2776222abb ("kbuild: lto: merge module sections") Cc: Nick Desaulniers Cc: Sami Tolvanen Cc: Kees Cook Sign

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Sean Christopherson
On Mon, Mar 22, 2021, Borislav Petkov wrote: > On Mon, Mar 22, 2021 at 11:56:37AM -0700, Sean Christopherson wrote: > > Not necessarily. This can only trigger in the host, and thus require a host > > reboot, if the host is also running enclaves. If the CSP is not runni

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Sean Christopherson
On Mon, Mar 22, 2021, Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:22:19PM +1300, Kai Huang wrote: > > +/** > > + * sgx_encl_free_epc_page - free EPC page assigned to an enclave > > + * @page: EPC page to be freed > > + * > > + * Free EPC page assigned to an enclave. It does EREMOVE for

Re: [PATCH V4 06/10] x86/fault: Adjust WARN_ON for PKey fault

2021-03-22 Thread Sean Christopherson
On Sun, Mar 21, 2021, ira.we...@intel.com wrote: > From: Ira Weiny > > PKey faults may now happen on kernel mappings if the feature is enabled. > Remove the warning in the fault path if PKS is enabled. When/why can they happen? I read through all the changelogs, as well as the cover letters

[PATCH 2/2] KVM: x86/mmu: Ensure TLBs are flushed when yielding during NX zapping

2021-03-19 Thread Sean Christopherson
ds a flush. This fixes the case where the TDP MMU yields, but it iteslf does not require a flush. Fixes: 29cf0f5007a2 ("kvm: x86/mmu: NX largepage recovery for TDP MMU") Cc: sta...@vger.kernel.org Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 15 ++---

[PATCH 1/2] KVM: x86/mmu: Ensure TLBs are flushed when yielding during GFN range zap

2021-03-19 Thread Sean Christopherson
nt flushes. zap_gfn_range() preserves and return the incoming "flush", unless of course the flush was performed prior to yielding and no new flush was triggered. Fixes: 1af4a96025b3 ("KVM: x86/mmu: Yield in TDU MMU iter even if no SPTES changed") Cc: sta...@vger.kernel.org Cc: B

[PATCH 0/2] KVM: x86/mmu: Fix TLB flushing bugs in TDP MMU

2021-03-19 Thread Sean Christopherson
that was required from a previous root. Patch 2 fixes a much more egregious bug where it fails to handle TDP MMU flushes in NX huge page recovery, as well as a similar bug to patch 1 where KVM can yield without correctly handling a previously triggered pending TLB flush. Sean Christopherson (2): KVM

Re: [PATCH v1 1/1] x86/tdx: Add tdcall() and tdvmcall() helper functions

2021-03-19 Thread Sean Christopherson
On Thu, Mar 18, 2021, Kuppuswamy Sathyanarayanan wrote: > diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c > index e44e55d1e519..7ae1d25e272b 100644 > --- a/arch/x86/kernel/tdx.c > +++ b/arch/x86/kernel/tdx.c > @@ -4,6 +4,58 @@ > #include > #include > > +void tdcall(u64 leafid,

[PATCH v2 3/4] KVM: VMX: Macrofy the MSR bitmap getters and setters

2021-03-18 Thread Sean Christopherson
Add builder macros to generate the MSR bitmap helpers to reduce the amount of copy-paste code, especially with respect to all the magic numbers needed to calc the correct bit location. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.h | 77

[PATCH v2 2/4] KVM: nVMX: Handle dynamic MSR intercept toggling

2021-03-18 Thread Sean Christopherson
possible") Cc: sta...@vger.kernel.org Cc: Alexander Graf Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 108 +- arch/x86/kvm/vmx/vmx.c| 67 ++- arch/x86/kvm/vmx/vmx.h| 63 ++ 3 files changed,

[PATCH v2 4/4] KVM: nVMX: Clean up x2APIC MSR handling for L2

2021-03-18 Thread Sean Christopherson
comment was flat out wrong for x2APIC behavior). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 53 +++ arch/x86/kvm/vmx/vmx.h| 8 ++ 2 files changed, 22 insertions(+), 39 deletions(-) diff --git

[PATCH v2 1/4] KVM: x86: Protect userspace MSR filter with SRCU, and set atomically-ish

2021-03-18 Thread Sean Christopherson
onzini Reviewed-by: Alexander Graf Reported-by: Yuan Yao Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/api.rst | 6 +- arch/x86/include/asm/kvm_host.h | 17 ++--- arch/x86/kvm/x86.c | 109 +++- 3 files changed, 78 insertions(+), 54 deletion

[PATCH v2 0/4] KVM: x86: MSR filtering and related fixes

2021-03-18 Thread Sean Christopherson
[Paolo, Alex]. - Make the macro insanity slightly less insane. [Paolo] v1: https://lkml.kernel.org/r/20210316184436.2544875-1-sea...@google.com Sean Christopherson (4): KVM: x86: Protect userspace MSR filter with SRCU, and set atomically-ish KVM: nVMX: Handle dynamic MSR intercept toggli

[PATCH] KVM: x86/mmu: Rename the special lm_root to pml4_root

2021-03-18 Thread Sean Christopherson
and will need to be updated if AMD ever gains 5-level paging. No functional change intended. Suggested-by: Paolo Bonzini Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/mmu/mmu.c | 20 ++-- 2 files changed, 11 insertions(+), 11

Re: [PATCH] selftests/kvm: add get_msr_index_features

2021-03-18 Thread Sean Christopherson
On Thu, Mar 18, 2021, Paolo Bonzini wrote: > On 18/03/21 18:03, Andrew Jones wrote: > > > > > > TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test > > > +TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features > > > > Maybe we should give up trying to keep an alphabetic order. > > FWIW I had

Re: [PATCH 3/3] KVM: SVM: allow to intercept all exceptions for debug

2021-03-18 Thread Sean Christopherson
On Thu, Mar 18, 2021, Maxim Levitsky wrote: > On Thu, 2021-03-18 at 16:35 +0000, Sean Christopherson wrote: > > Skipping SEV-ES guests should not be difficult; KVM could probably even > > print a message stating that the debug hook is being ignored. One thought > > wou

Re: [PATCH 3/3] KVM: SVM: allow to intercept all exceptions for debug

2021-03-18 Thread Sean Christopherson
On Thu, Mar 18, 2021, Joerg Roedel wrote: > On Thu, Mar 18, 2021 at 11:24:25AM +0200, Maxim Levitsky wrote: > > But again this is a debug feature, and it is intended to allow the user > > to shoot himself in the foot. > > And one can't debug SEV-ES guests with it, so what is the point of >

Re: [PATCH] x86/cpu/AMD: Adjust x86_phys_bits to account for reduced PA in SEV-* guests

2021-03-17 Thread Sean Christopherson
On Wed, Mar 17, 2021, Sean Christopherson wrote: > On Wed, Mar 17, 2021, Borislav Petkov wrote: > > IOW, you have c_bit so your valid address space is [0 .. c_bit-1] no? > > I haven't found anything in the GHCB that dictates that MAXPHYADDR == C_BIT-1, > or more specifical

Re: [PATCH 2/4] KVM: nVMX: Handle dynamic MSR intercept toggling

2021-03-17 Thread Sean Christopherson
On Wed, Mar 17, 2021, Sean Christopherson wrote: > On Wed, Mar 17, 2021, Paolo Bonzini wrote: > > On 17/03/21 17:50, Sean Christopherson wrote: > > > > Feel free to squash patch 3 in this one or reorder it before; it makes > > > > sense > > > >

Re: [PATCH] x86/cpu/AMD: Adjust x86_phys_bits to account for reduced PA in SEV-* guests

2021-03-17 Thread Sean Christopherson
On Wed, Mar 17, 2021, Borislav Petkov wrote: > On Wed, Mar 17, 2021 at 11:32:43AM -0700, Sean Christopherson wrote: > > Note, early kernel boot code for SEV-*, e.g. get_sev_encryption_bit(), > > _requires_ the SEV feature flag to be set in CPUID in order to identify > > SEV (t

[PATCH] x86/cpu/AMD: Adjust x86_phys_bits to account for reduced PA in SEV-* guests

2021-03-17 Thread Sean Christopherson
Cc: Tom Lendacky Cc: Brijesh Singh Cc: Peter Gonda Signed-off-by: Sean Christopherson --- Regarding clearing SME, SEV, SEV_ES, etc..., it's obviously not required, but to avoid false postives, identifying "SEV guest" within the kernel must be done with sev_active(). And if we wa

Re: [PATCH 2/4] KVM: nVMX: Handle dynamic MSR intercept toggling

2021-03-17 Thread Sean Christopherson
On Wed, Mar 17, 2021, Paolo Bonzini wrote: > On 17/03/21 17:50, Sean Christopherson wrote: > > > Feel free to squash patch 3 in this one or reorder it before; it makes > > > sense > > > to make them macros when you go from 4 to 6 functions. > > I put them in

Re: [PATCH 2/4] KVM: nVMX: Handle dynamic MSR intercept toggling

2021-03-17 Thread Sean Christopherson
On Wed, Mar 17, 2021, Paolo Bonzini wrote: > On 16/03/21 19:44, Sean Christopherson wrote: > > Always check vmcs01's MSR bitmap when merging L0 and L1 bitmaps for L2, > > and always update the relevant bits in vmcs02. This fixes two distinct, > > but intertwined bugs related

Re: [PATCH 3/4] KVM: VMX: Macrofy the MSR bitmap getters and setters

2021-03-17 Thread Sean Christopherson
On Wed, Mar 17, 2021, Paolo Bonzini wrote: > On 16/03/21 19:44, Sean Christopherson wrote: > > + return (ret)true; \ > > I'm not sure if (void)true is amazing or disgusting, but anyway... Definitely both. > > +BUILD_

[PATCH 2/4] KVM: nVMX: Handle dynamic MSR intercept toggling

2021-03-16 Thread Sean Christopherson
possible") Cc: sta...@vger.kernel.org Cc: Alexander Graf Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 108 +- arch/x86/kvm/vmx/vmx.c| 67 ++- arch/x86/kvm/vmx/vmx.h| 63 ++ 3 files changed,

[PATCH 4/4] KVM: nVMX: Clean up x2APIC MSR handling for L2

2021-03-16 Thread Sean Christopherson
comment was flat out wrong for x2APIC behavior). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 53 +++ arch/x86/kvm/vmx/vmx.h| 7 ++ 2 files changed, 21 insertions(+), 39 deletions(-) diff --git

[PATCH 1/4] KVM: x86: Protect userspace MSR filter with SRCU, and set atomically-ish

2021-03-16 Thread Sean Christopherson
ted-by: Yuan Yao Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/api.rst | 6 +- arch/x86/include/asm/kvm_host.h | 17 ++--- arch/x86/kvm/x86.c | 109 +++- 3 files changed, 78 insertions(+), 54 deletions(-) diff --git a/Documentation/vi

[PATCH 0/4] KVM: x86: MSR filtering and related fixes

2021-03-16 Thread Sean Christopherson
the before and after binary output for vmx_set_intercept_for_msr() was identical (this required wrapping "if (msr <= 0x1fff)" with (un)likely in both the before and after versions; gcc made seemingly random choices without forcing it to favor a specific branch). Sean Christopherson (4

[PATCH 3/4] KVM: VMX: Macrofy the MSR bitmap getters and setters

2021-03-16 Thread Sean Christopherson
Add builder macros to generate the MSR bitmap helpers to reduce the amount of copy-paste code, especially with respect to all the magic numbers needed to calc the correct bit location. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.h | 82

Re: [RFC] KVM: x86: Support KVM VMs sharing SEV context

2021-03-16 Thread Sean Christopherson
On Tue, Mar 16, 2021, Paolo Bonzini wrote: > On 16/03/21 18:52, Sean Christopherson wrote: > > > I don't > > > know that holding the fd instead of the kvm makes that much better though, > > > are there advantages to that I'm not seeing? > > If there's no k

Re: [PATCH v3 3/4] KVM: x86/mmu: Factor out tdp_iter_return_to_root

2021-03-16 Thread Sean Christopherson
On Mon, Mar 15, 2021, Ben Gardon wrote: > No functional change intended. I want royalties. > Signed-off-by: Ben Gardon > --- Reviewed-by: Sean Christopherson

Re: [PATCH v3 2/4] KVM: x86/mmu: Fix RCU usage when atomically zapping SPTEs

2021-03-16 Thread Sean Christopherson
On Mon, Mar 15, 2021, Ben Gardon wrote: > Fix a missing rcu_dereference in tdp_mmu_zap_spte_atomic. > > Reported-by: kernel test robot > Signed-off-by: Ben Gardon > --- Reviewed-by: Sean Christopherson

Re: [RFC] KVM: x86: Support KVM VMs sharing SEV context

2021-03-16 Thread Sean Christopherson
On Fri, Mar 12, 2021, Nathan Tempelman wrote: > On Wed, Feb 24, 2021 at 9:37 AM Sean Christopherson wrote: > > > @@ -1282,6 +1299,65 @@ int svm_unregister_enc_region(struct kvm *kvm, > > > return ret; > > > } > > > > > > +int svm_vm_copy_asi

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Sean Christopherson
On Tue, Mar 16, 2021, Jan Kiszka wrote: > On 16.03.21 17:50, Sean Christopherson wrote: > > Rather than block all events in KVM, what about having QEMU "pause" the > > timer? > > E.g. save MSR_TSC_DEADLINE and APIC_TMICT (or inspect the guest to find out > >

Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E

2021-03-16 Thread Sean Christopherson
On Tue, Mar 16, 2021, Borislav Petkov wrote: > On Tue, Mar 16, 2021 at 03:42:23PM +0800, Feng Tang wrote: > > Also I'm wondering for some basic leaf and extended leaf which > > may has different definition for different vendors, do we need > > to seprate the csv to a general one and vendor

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Sean Christopherson
gt; I have no objections though to use this patch as is, or at least make this > the new default with a new flag to override this. That's less bad, but IMO still violates the principle of least surprise, e.g. someone that is single-stepping a guest and is expecting an IRQ to fire will be all kinds of confu

Re: [PATCH v2 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-15 Thread Sean Christopherson
On Tue, Mar 16, 2021, Jarkko Sakkinen wrote: > On Tue, Mar 16, 2021 at 01:05:05AM +0200, Jarkko Sakkinen wrote: > > The way I've understood it is that given that KVM can support SGX > > without FLC, vEPC should be available even if driver cannot be > > enabled. > > > > This is also exactly what

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-15 Thread Sean Christopherson
On Tue, Mar 16, 2021, Maxim Levitsky wrote: > This change greatly helps with two issues: > > * Resuming from a breakpoint is much more reliable. > > When resuming execution from a breakpoint, with interrupts enabled, more > often > than not, KVM would inject an interrupt and make the CPU

Re: [PATCH v2 2/4] KVM: x86/mmu: Fix RCU usage when atomically zapping SPTEs

2021-03-15 Thread Sean Christopherson
On Mon, Mar 15, 2021, Ben Gardon wrote: > Fix a missing rcu_dereference in tdp_mmu_zap_spte_atomic. > > Reported-by: kernel test robot > Signed-off-by: Ben Gardon > --- Reviewed-by: Sean Christopherson

Re: [PATCH v2 3/4] KVM: x86/mmu: Factor out tdp_iter_return_to_root

2021-03-15 Thread Sean Christopherson
> tdp_mmu_iter_cond_resched and tdp_iter_start. > > No functional change intended. > > Signed-off-by: Ben Gardon > --- Very nice, sooo much easier to read. Reviewed-by: Sean Christopherson

Re: [PATCH v2 4/4] KVM: x86/mmu: Store the address space ID in the TDP iterator

2021-03-15 Thread Sean Christopherson
On Mon, Mar 15, 2021, Ben Gardon wrote: Missing "From: Sean Christopherson ", i.e. the commit in your local tree needs "git commit --amend --author="Sean Christopherson ". Alternatively, you could just erase my SOB ;-) > Store the address space ID in the

Re: [PATCH v4 1/3] KVM: nVMX: Sync L2 guest CET states between L1/L2

2021-03-15 Thread Sean Christopherson
one blank line and add minor fix for MPX. > > Suggested-by: Sean Christopherson > Signed-off-by: Yang Weijiang > --- > arch/x86/kvm/cpuid.c | 1 - > arch/x86/kvm/vmx/nested.c | 35 +-- > arch/x86/kvm/vmx/vmx.h| 3 +++ > 3 files

Re: [PATCH] kvm: lapic: add module parameters for LAPIC_TIMER_ADVANCE_ADJUST_MAX/MIN

2021-03-12 Thread Sean Christopherson
On Wed, Mar 10, 2021, Haiwei Li wrote: > On Wed, Mar 10, 2021 at 7:42 AM Sean Christopherson wrote: > > > > On Wed, Mar 03, 2021, Haiwei Li wrote: > > > On 21/3/3 10:09, lihaiwei.ker...@gmail.com wrote: > > > > From: Haiwei Li > > > > >

Re: [PATCH 04/15] KVM: selftests: Force stronger HVA alignment (1gb) for hugepages

2021-03-12 Thread Sean Christopherson
On Thu, Feb 25, 2021, wangyanan (Y) wrote: > > On 2021/2/11 7:06, Sean Christopherson wrote: > > Align the HVA for hugepage memslots to 1gb, as opposed to incorrectly > > assuming all architectures' hugepages are 512*page_size. > > > > For x86, multiplying by 51

Re: [PATCH 03/15] KVM: selftests: Align HVA for HugeTLB-backed memslots

2021-03-12 Thread Sean Christopherson
On Thu, Feb 25, 2021, wangyanan (Y) wrote: > Hi Sean, > > On 2021/2/11 7:06, Sean Christopherson wrote: > > Align the HVA for HugeTLB memslots, not just THP memslots. Add an > > assert so any future backing types are forced to assess whether or not > > they need to b

Re: [PATCH v3 1/3] KVM: nVMX: Sync L2 guest CET states between L1/L2

2021-03-12 Thread Sean Christopherson
On Mon, Mar 08, 2021, Yang Weijiang wrote: > On Thu, Mar 04, 2021 at 08:46:45AM -0800, Sean Christopherson wrote: > > On Thu, Mar 04, 2021, Yang Weijiang wrote: > > > @@ -3375,6 +3391,12 @@ enum nvmx_vmentry_status > > > nested_vmx_enter_non_root

Re: [PATCH v2 00/25] KVM SGX virtualization support

2021-03-12 Thread Sean Christopherson
On Tue, Mar 09, 2021, Paolo Bonzini wrote: > On 09/03/21 10:30, Borislav Petkov wrote: > > On Tue, Mar 09, 2021 at 02:38:49PM +1300, Kai Huang wrote: > > > This series adds KVM SGX virtualization support. The first 14 patches > > > starting > > > with x86/sgx or x86/cpu.. are necessary changes to

Re: [PATCH v2 08/25] x86/sgx: Expose SGX architectural definitions to the kernel

2021-03-12 Thread Sean Christopherson
On Tue, Mar 09, 2021, Kai Huang wrote: > From: Sean Christopherson > > Expose SGX architectural structures, as KVM will use many of the > architectural constants and structs to virtualize SGX. > > Name the new header file as asm/sgx.h, rather than asm/sgx_arch.h, to &g

Re: [PATCH v2 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-12 Thread Sean Christopherson
* > + * Error out only if both fail to initialize. > + */ > + ret = !!sgx_drv_init() & !!sgx_vepc_init(); I love this code. Reviewed-by: Sean Christopherson > if (ret) > goto err_kthread; > > -- > 2.29.2 >

Re: [PATCH v2 06/25] x86/cpu/intel: Allow SGX virtualization without Launch Control support

2021-03-12 Thread Sean Christopherson
On Tue, Mar 09, 2021, Kai Huang wrote: > + if (cpu_has(c, X86_FEATURE_SGX) && IS_ENABLED(CONFIG_X86_SGX)) { > + /* > + * Separate out SGX driver enabling from KVM. This allows KVM > + * guests to use SGX even if the kernel SGX driver refuses to > +

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-12 Thread Sean Christopherson
bug during copy/paste which results in SECS page and va pages are not >correctly freed in sgx_encl_release() (sorry for the mistake). > - Added Jarkko's Acked-by. That Acked-by should either be dropped or moved above Co-developed-by to make checkpatch happy. Reviewed-by: Sean Christopherson

Re: [PATCH v2 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features

2021-03-12 Thread Sean Christopherson
On Tue, Mar 09, 2021, Kai Huang wrote: > @@ -290,6 +290,8 @@ > #define X86_FEATURE_FENCE_SWAPGS_KERNEL (11*32+ 5) /* "" LFENCE in > kernel entry SWAPGS path */ > #define X86_FEATURE_SPLIT_LOCK_DETECT(11*32+ 6) /* #AC for split > lock */ > #define X86_FEATURE_PER_THREAD_MBA

Re: [PATCH v2 01/25] x86/cpufeatures: Make SGX_LC feature bit depend on SGX bit

2021-03-12 Thread Sean Christopherson
On Tue, Mar 09, 2021, Kai Huang wrote: > Move SGX_LC feature bit to CPUID dependency table to make clearing all > SGX feature bits easier. Also remove clear_sgx_caps() since it is just > a wrapper of setup_clear_cpu_cap(X86_FEATURE_SGX) now. > > Suggested-by: Sean Christopherson &

Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller

2021-03-12 Thread Sean Christopherson
On Fri, Mar 12, 2021, Vipin Sharma wrote: > On Thu, Mar 11, 2021 at 07:59:03PM +0100, Michal Koutný wrote: > > > +#ifndef CONFIG_KVM_AMD_SEV > > > +/* > > > + * When this config is not defined, SEV feature is not supported and > > > APIs in > > > + * this file are not used but this file still

Re: [PATCH 4/4] KVM: x86/mmu: Factor out tdp_iter_return_to_root

2021-03-12 Thread Sean Christopherson
On Thu, Mar 11, 2021, Ben Gardon wrote: > In tdp_mmu_iter_cond_resched there is a call to tdp_iter_start which > causes the iterator to continue its walk over the paging structure from > the root. This is needed after a yield as paging structure could have > been freed in the interim. > > The

Re: [PATCH 3/4] KVM: x86/mmu: Fix RCU usage when atomically zapping SPTEs

2021-03-12 Thread Sean Christopherson
On Thu, Mar 11, 2021, Ben Gardon wrote: > Fix a missing rcu_dereference in tdp_mmu_zap_spte_atomic. > > Reported-by: kernel test robot s/x/intel.com Reviewed-by: Sean Christopherson > Signed-off-by: Ben Gardon

Re: [PATCH 2/4] KVM: x86/mmu: Fix RCU usage for tdp_iter_root_pt

2021-03-12 Thread Sean Christopherson
necessary in some cases, it will be a net win when setting multiple sptes, e.g. in mmu_notifier callbacks. Compile tested only... >From 02fb9cd2aa52d0afd318e93661d0212ccdb54218 Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Fri, 12 Mar 2021 08:12:21 -0800 Subject: [PATCH] KVM

Re: [PATCH 1/4] KVM: x86/mmu: Fix RCU usage in handle_removed_tdp_mmu_page

2021-03-12 Thread Sean Christopherson
out a proper rcu_derefrence. Fix this by > passing the pt as a tdp_ptep_t and then rcu_dereferencing it in > the function. > > Suggested-by: Sean Christopherson > Reported-by: kernel test robot Should be . Looks like you've been taking pointers from Paolo :-) https://lkml.org

[PATCH v2] mm/mmu_notifiers: Esnure range_end() is paired with range_start()

2021-03-11 Thread Sean Christopherson
avid Rientjes Cc: Ben Gardon Cc: Michal Hocko Cc: "Jérôme Glisse" Cc: Andrea Arcangeli Cc: Johannes Weiner Cc: Dimitri Sivanich Signed-off-by: Sean Christopherson --- v2: Reimplemented as suggested by Jason. Only functional change relative to Jason's suggestion is t

Re: [PATCH] x86/kvm: Fix broken irq restoration in kvm_wait

2021-03-11 Thread Sean Christopherson
On Tue, Feb 23, 2021, Wanpeng Li wrote: > On Tue, 23 Feb 2021 at 13:25, Wanpeng Li wrote: > > > > From: Wanpeng Li > > > > After commit 997acaf6b4b59c (lockdep: report broken irq restoration), the > > guest > > splatting below during boot: > > > > raw_local_irq_restore() called with IRQs

[tip: perf/urgent] x86/perf: Use RET0 as default for guest_get_msrs to handle "no PMU" case

2021-03-11 Thread tip-bot2 for Sean Christopherson
The following commit has been merged into the perf/urgent branch of tip: Commit-ID: c8e2fe13d1d1f3a02842b7b909d4e4846a4b6a2c Gitweb: https://git.kernel.org/tip/c8e2fe13d1d1f3a02842b7b909d4e4846a4b6a2c Author:Sean Christopherson AuthorDate:Tue, 09 Mar 2021 09:10:19 -08:00

Re: [PATCH] mm/oom_kill: Ensure MMU notifier range_end() is paired with range_start()

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Jason Gunthorpe wrote: > On Wed, Mar 10, 2021 at 05:20:01PM -0800, Sean Christopherson wrote: > > > > Which I believe is fatal to kvm? These notifiers certainly do not only > > > happen at process exit. > > > > My point about the pr

Re: [PATCH] mm/oom_kill: Ensure MMU notifier range_end() is paired with range_start()

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Jason Gunthorpe wrote: > On Wed, Mar 10, 2021 at 01:31:17PM -0800, Sean Christopherson wrote: > > Invoke the MMU notifier's .invalidate_range_end() callbacks even if one > > of the .invalidate_range_start() callbacks failed. If there are multiple > > no

[PATCH] mm/oom_kill: Ensure MMU notifier range_end() is paired with range_start()

2021-03-10 Thread Sean Christopherson
notifier count. Fixes: 93065ac753e4 ("mm, oom: distinguish blockable mode for mmu notifiers") Cc: sta...@vger.kernel.org Cc: David Rientjes Cc: Ben Gardon Cc: Jason Gunthorpe Cc: Michal Hocko Cc: "Jérôme Glisse" Cc: Andrea Arcangeli Cc: Johannes Weiner Cc: Dimitri Sivanich

Re: [PATCH] KVM: x86/mmu: Skip !MMU-present SPTEs when removing SP in exclusive mode

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Paolo Bonzini wrote: > On 10/03/21 01:30, Sean Christopherson wrote: > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > > index 50ef757c5586..f0c99fa04ef2 100644 > > --- a/arch/x86/kvm/mmu/tdp_mmu.c > > +++ b/arch/x86/kvm/

Re: [PATCH v2] x86/perf: Use RET0 as default for guest_get_msrs to handle "no PMU" case

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Peter Zijlstra wrote: > On Tue, Mar 09, 2021 at 09:10:19AM -0800, Sean Christopherson wrote: > > > @@ -2024,9 +2021,6 @@ static int __init init_hw_perf_events(void) > > if (!x86_pmu.read) > > x86_

Re: [PATCH v2 5/7] x86/boot/compressed/64: Add CPUID sanity check to 32-bit boot-path

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Martin Radev wrote: > On Wed, Mar 10, 2021 at 08:08:37AM -0800, Sean Christopherson wrote: > > On Wed, Mar 10, 2021, Joerg Roedel wrote: > > > + /* > > > + * Sanity check CPUID results from the Hypervisor. See comment in > > > + * do_

Re: [PATCH v2 5/7] x86/boot/compressed/64: Add CPUID sanity check to 32-bit boot-path

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Joerg Roedel wrote: > From: Joerg Roedel > > The 32-bit #VC handler has no GHCB and can only handle CPUID exit codes. > It is needed by the early boot code to handle #VC exceptions raised in > verify_cpu() and to get the position of the C bit. > > But the CPUID information

Re: [PATCH v3 1/5] x86/sgx: Fix a resource leak in sgx_init()

2021-03-10 Thread Sean Christopherson
On Wed, Mar 10, 2021, Jarkko Sakkinen wrote: > On Wed, Mar 03, 2021 at 08:56:52AM -0800, Dave Hansen wrote: > > On 3/3/21 7:03 AM, Jarkko Sakkinen wrote: > > > If sgx_page_cache_init() fails in the middle, a trivial return > > > statement causes unused memory and virtual address space reserved for

[PATCH] KVM: x86/mmu: Skip !MMU-present SPTEs when removing SP in exclusive mode

2021-03-09 Thread Sean Christopherson
big function), as well as several conditional branches before bailing out. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 50ef757c5586

Re: [PATCH] kvm: lapic: add module parameters for LAPIC_TIMER_ADVANCE_ADJUST_MAX/MIN

2021-03-09 Thread Sean Christopherson
On Wed, Mar 03, 2021, Haiwei Li wrote: > On 21/3/3 10:09, lihaiwei.ker...@gmail.com wrote: > > From: Haiwei Li > > > > In my test environment, advance_expire_delta is frequently greater than > > the fixed LAPIC_TIMER_ADVANCE_ADJUST_MAX. And this will hinder the > > adjustment. > > Supplementary

[PATCH v2 4/4] KVM: x86/mmu: Mark the PAE roots as decrypted for shadow paging

2021-03-09 Thread Sean Christopherson
c: Brijesh Singh Cc: Tom Lendacky Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 22 +- arch/x86/kvm/svm/svm.c | 5 ++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 6b0576ff2846..c6

[PATCH v2 3/4] KVM: x86/mmu: Use '0' as the one and only value for an invalid PAE root

2021-03-09 Thread Sean Christopherson
-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 24 +--- arch/x86/kvm/mmu/mmu_audit.c| 2 +- arch/x86/kvm/mmu/mmu_internal.h | 10 ++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c

<    1   2   3   4   5   6   7   8   9   10   >