Re: [PATCH 7/11] KVM: Remove redundant check in the kvm_get_dirty_log_protect()

2019-01-05 Thread Sean Christopherson
On Fri, Jan 04, 2019 at 07:50:36AM -0800, Sean Christopherson wrote: > On Fri, Jan 04, 2019 at 04:54:01PM +0800, lantianyu1...@gmail.com wrote: > > From: Lan Tianyu > > > > The dirty bits have already been checked in the previous check of > > "dirty_bitmap&

Re: [PATCH 7/11] KVM: Remove redundant check in the kvm_get_dirty_log_protect()

2019-01-04 Thread Sean Christopherson
On Fri, Jan 04, 2019 at 04:54:01PM +0800, lantianyu1...@gmail.com wrote: > From: Lan Tianyu > > The dirty bits have already been checked in the previous check of > "dirty_bitmap" and mask must be non-zero value at this point. > > Signed-off-by: Lan Tianyu > --- > virt/kvm/kvm_main.c | 8

Re: [PATCH 6/11] KVM/MMU: Flush tlb with range list in sync_page()

2019-01-04 Thread Sean Christopherson
On Fri, Jan 04, 2019 at 04:54:00PM +0800, lantianyu1...@gmail.com wrote: > From: Lan Tianyu > > This patch is to flush tlb via flush list function. More explanation of why this is beneficial would be nice. Without the context of the overall series it's not immediately obvious what

[PATCH v2 00/27] KVM: x86/mmu: Remove fast invalidate mechanism

2019-02-06 Thread Sean Christopherson
l sptes or all MMIO sptes [Paolo] - Add patches to clean up the memslots/MMIO generation code and fix a variety of theoretically corner case bugs Sean Christopherson (27): KVM: Call kvm_arch_memslots_updated() before updating memslots KVM: x86/mmu: Detect MMIO generation wrap in any addre

[PATCH v2 01/27] KVM: Call kvm_arch_memslots_updated() before updating memslots

2019-02-06 Thread Sean Christopherson
dereference the new memslots generation, e.g. 0, and incorrectly reuse an old MMIO spte that was created with (pre-wrap) generation==0. Fixes: e59dbe09f8e6 ("KVM: Introduce kvm_arch_memslots_updated()") Cc: Signed-off-by: Sean Christopherson --- arch/mips/include/asm/kvm_host.h|

Re: [PATCH 1/3] KVM: x86: Move mmu_memory_cache functions to common code

2019-01-29 Thread Sean Christopherson
On Mon, Jan 28, 2019 at 03:48:41PM +0100, Christoffer Dall wrote: > We are currently duplicating the mmu memory cache functionality quite > heavily between the architectures that support KVM. As a first step, > move the x86 implementation (which seems to have the most recently > maintained

Re: [kvm-unit-tests PATCH] lib: arm: Use correct halt() prototype from smp.h

2019-04-08 Thread Sean Christopherson
On Mon, Apr 08, 2019 at 04:11:25PM +0100, Alexandru Elisei wrote: > The prototype for the halt() function is incorrect, because halt() doesn't > take any arguments. Fix it by using the prototype from smp.h. > > Signed-off-by: Alexandru Elisei > --- Reviewed-by: Sean

[PATCH] KVM: Directly return result from kvm_arch_check_processor_compat()

2019-04-19 Thread Sean Christopherson
where the out-param was not pre-initialized by the caller. Opportunistically annotate svm_check_processor_compat() with __init. Signed-off-by: Sean Christopherson --- Tested on VMX only. arch/mips/kvm/mips.c | 4 ++-- arch/powerpc/kvm/powerpc.c | 4 ++-- arch/s390/include/asm

Re: [PATCH v3 04/10] KVM: Implement kvm_put_guest()

2019-08-22 Thread Sean Christopherson
On Wed, Aug 21, 2019 at 04:36:50PM +0100, Steven Price wrote: > kvm_put_guest() is analogous to put_user() - it writes a single value to > the guest physical address. The implementation is built upon put_user() > and so it has the same single copy atomic properties. What you mean by "single copy

Re: [PATCH v3 04/10] KVM: Implement kvm_put_guest()

2019-08-22 Thread Sean Christopherson
On Thu, Aug 22, 2019 at 04:46:10PM +0100, Steven Price wrote: > On 22/08/2019 16:28, Sean Christopherson wrote: > > On Wed, Aug 21, 2019 at 04:36:50PM +0100, Steven Price wrote: > >> kvm_put_guest() is analogous to put_user() - it writes a single value to > >>

[PATCH 00/13] KVM: Dynamically size memslot arrays

2019-09-11 Thread Sean Christopherson
, but that's it. In theory, the vast majority of the functional changes are arch agnostic, in theory... Sean Christopherson (13): KVM: Reinstall old memslots if arch preparation fails KVM: PPC: Move memslot memory allocation into prepare_memory_region() KVM: x86: Allocate memslot resources

[PATCH 04/13] KVM: Drop kvm_arch_create_memslot()

2019-09-11 Thread Sean Christopherson
on kvm_free_memslot() paves the way for simplify kvm_free_memslot(), i.e. dropping its @dont param. Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 6 -- arch/powerpc/kvm/powerpc.c | 6 -- arch/s390/kvm/kvm-s390.c | 6 -- arch/x86/kvm/x86.c | 6 -- include

[PATCH 11/13] KVM: Ensure validity of memslot with respect to kvm_get_dirty_log()

2019-09-11 Thread Sean Christopherson
eed to add validity checks in the arch code that are technically unnecessary. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_pr.c | 6 +- arch/s390/kvm/kvm-s390.c | 12 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c

[PATCH 08/13] KVM: Simplify kvm_free_memslot() and all its descendents

2019-09-11 Thread Sean Christopherson
Now that all callers of kvm_free_memslot() pass NULL for @dont, remove the param from the top-level routine and all arch's implementations. No functional change intended. Signed-off-by: Sean Christopherson --- arch/mips/include/asm/kvm_host.h | 2 +- arch/powerpc/include/asm/kvm_ppc.h

[PATCH 01/13] KVM: Reinstall old memslots if arch preparation fails

2019-09-11 Thread Sean Christopherson
: bc6678a33d9b9 ("KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update") Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 23 --- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm

[PATCH 10/13] KVM: Provide common implementation for generic dirty log functions

2019-09-11 Thread Sean Christopherson
by the dirty log, i.e. to make it obvious in the code that the validity of the memslot is guaranteed, as a future patch will rework memslot handling such that id_to_memslot() can return NULL. Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 62 ++--- arch

[PATCH 07/13] KVM: Move memslot deletion to helper function

2019-09-11 Thread Sean Christopherson
a memslot or changing its flags, i.e. implement logic similar to the dirty bitmap handling, if such functionality is needed in the future. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 73 +++-- 1 file changed, 44 insertions(+), 29 deletions

[PATCH 06/13] KVM: Move setting of memslot into helper routine

2019-09-11 Thread Sean Christopherson
Split out the core functionality of setting a memslot into a separate helper in preparation for moving memslot deletion into its own routine. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 106 ++-- 1 file changed, 63 insertions(+), 43

[PATCH 13/13] KVM: Dynamically size memslot array based on number of used slots

2019-09-11 Thread Sean Christopherson
reduced when deleting a memslot. However, consecutive deletions will realize the memory savings, i.e. a second deletion will trim the entry. Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 5 - virt/kvm/kvm_main.c | 31 --- 2 files changed, 32

[PATCH 03/13] KVM: x86: Allocate memslot resources during prepare_memory_region()

2019-09-11 Thread Sean Christopherson
code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b4cfd786d0b6..72ec6272d7cb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9484,6

[PATCH 02/13] KVM: PPC: Move memslot memory allocation into prepare_memory_region()

2019-09-11 Thread Sean Christopherson
-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 8 ++-- arch/powerpc/kvm/book3s.c | 12 arch/powerpc/kvm/book3s_hv.c | 25 - arch/powerpc/kvm/book3s_pr.c | 11 ++- arch/powerpc/kvm/booke.c | 9

[PATCH 05/13] KVM: Refactor error handling for setting memory region

2019-09-11 Thread Sean Christopherson
Replace a big pile o' gotos with returns to make it more obvious what error code is being returned, and to prepare for refactoring the functional, i.e. post-checks, portion of __kvm_set_memory_region(). Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 40

[PATCH 12/13] KVM: Terminate memslot walks via used_slots

2019-09-11 Thread Sean Christopherson
be susceptible to casting shenanigans. Add function comments to update_memslots() and search_memslots() to explicitly (and loudly) state how memslots are sorted. No functional change intended. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_hv.c | 2 +- arch/x86/kvm/x86.c

[PATCH 09/13] KVM: Clean up local variable usage in __kvm_set_memory_region()

2019-09-11 Thread Sean Christopherson
the initial memslot is not strictly necessary at this juncture, e.g. 'old' could be directly copied from id_to_memslot(), but keep the pointer usage as id_to_memslot() will be able to return a NULL pointer once memslots are dynamically sized. Signed-off-by: Sean Christopherson --- virt/kvm

Re: [PATCH 10/13] KVM: Provide common implementation for generic dirty log functions

2019-09-19 Thread Sean Christopherson
On Thu, Sep 19, 2019 at 10:22:42AM +1000, Paul Mackerras wrote: > On Wed, Sep 11, 2019 at 11:50:35AM -0700, Sean Christopherson wrote: > > Move the implementations of KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG > > for CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT into common KVM cod

Re: [PATCH v3 00/15] KVM: Dynamically size memslot arrays

2019-12-13 Thread Sean Christopherson
On Tue, Dec 03, 2019 at 02:14:33PM -0800, Sean Christopherson wrote: > On Thu, Oct 24, 2019 at 04:07:29PM -0700, Sean Christopherson wrote: > > The end goal of this series is to dynamically size the memslot array so > > that KVM allocates memory based on the number of

Re: [PATCH v3 00/15] KVM: Dynamically size memslot arrays

2019-12-17 Thread Sean Christopherson
On Mon, Dec 16, 2019 at 09:25:24AM +0100, Christian Borntraeger wrote: > > On 13.12.19 21:01, Sean Christopherson wrote: > > Applies cleanly on the current kvm/queue and nothing caught fire in > > testing (though I only re-tested the series as a whole). > > Do you

Re: [PATCH v4 01/19] KVM: x86: Allocate new rmap and large page tracking when moving memslot

2019-12-17 Thread Sean Christopherson
, Dec 17, 2019 at 12:40:23PM -0800, Sean Christopherson wrote: > Reallocate a rmap array and recalcuate large page compatibility when > moving an existing memslot to correctly handle the alignment properties > of the new memslot. The number of rmap entries required at each level >

[PATCH v4 14/19] KVM: Clean up local variable usage in __kvm_set_memory_region()

2019-12-17 Thread Sean Christopherson
the initial memslot is not strictly necessary at this juncture, e.g. 'old' could be directly copied from id_to_memslot(), but keep the pointer usage as id_to_memslot() will be able to return a NULL pointer once memslots are dynamically sized. Signed-off-by: Sean Christopherson --- virt/kvm

[PATCH v4 06/19] KVM: Drop kvm_arch_create_memslot()

2019-12-17 Thread Sean Christopherson
Acked-by: Christian Borntraeger Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 6 -- arch/powerpc/kvm/powerpc.c | 6 -- arch/s390/kvm/kvm-s390.c | 6 -- arch/x86/kvm/x86.c | 6 -- include/linux/kvm_host.h | 2 -- virt/kvm/arm/mmu.c

[PATCH v4 00/19] KVM: Dynamically size memslot arrays

2019-12-17 Thread Sean Christopherson
x86: fix ...") - Collect an Acked-by and a Reviewed-by Sean Christopherson (19): KVM: x86: Allocate new rmap and large page tracking when moving memslot KVM: Reinstall old memslots if arch preparation fails KVM: Don't free new memslot if allocation of said memslot fails

[PATCH v4 11/19] KVM: x86: Free arrays for old memslot when moving memslot's base gfn

2019-12-17 Thread Sean Christopherson
ode in kvm_free_memslot() that conditionally frees structures based on its @dont param. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 4 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0911b2f634c5..5f890812fac3 100644 --- a/arch/x86/kvm/x86.c ++

[PATCH v4 03/19] KVM: Don't free new memslot if allocation of said memslot fails

2019-12-17 Thread Sean Christopherson
in this case as there are no resources to be freed. No functional change intended. Acked-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f14bde936c09

[PATCH v4 18/19] KVM: Dynamically size memslot array based on number of used slots

2019-12-17 Thread Sean Christopherson
reduced when deleting a memslot. However, consecutive deletions will realize the memory savings, i.e. a second deletion will trim the entry. Tested-by: Christoffer Dall Tested-by: Marc Zyngier Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c | 31

[PATCH v4 02/19] KVM: Reinstall old memslots if arch preparation fails

2019-12-17 Thread Sean Christopherson
: bc6678a33d9b9 ("KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update") Reviewed-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 23 --- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/virt/kvm/kvm_

[PATCH v4 08/19] KVM: Refactor error handling for setting memory region

2019-12-17 Thread Sean Christopherson
Replace a big pile o' gotos with returns to make it more obvious what error code is being returned, and to prepare for refactoring the functional, i.e. post-checks, portion of __kvm_set_memory_region(). Reviewed-by: Janosch Frank Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Sean

[PATCH v4 10/19] KVM: Drop "const" attribute from old memslot in commit_memory_region()

2019-12-17 Thread Sean Christopherson
ee_memslot() by eliminating the last usage of its @dont param. Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 2 +- arch/powerpc/kvm/powerpc.c | 2 +- arch/s390/kvm/kvm-s390.c | 2 +- arch/x86/kvm/x86.c | 2 +- include/linux/kvm_host.h | 2 +- virt/kvm/arm/mmu.c

[PATCH v4 13/19] KVM: Simplify kvm_free_memslot() and all its descendents

2019-12-17 Thread Sean Christopherson
Now that all callers of kvm_free_memslot() pass NULL for @dont, remove the param from the top-level routine and all arch's implementations. No functional change intended. Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/mips/include/asm/kvm_host.h | 2 +- arch

[PATCH v4 01/19] KVM: x86: Allocate new rmap and large page tracking when moving memslot

2019-12-17 Thread Sean Christopherson
s, which can lead to memory corruption and/or leaking data to guest/userspace. Note, the arrays for the old memslot are freed by the unconditional call to kvm_free_memslot() in __kvm_set_memory_region(). Fixes: 05da45583de9b ("KVM: MMU: large page support") Cc: sta...@vger.kernel.o

[PATCH v4 16/19] KVM: Ensure validity of memslot with respect to kvm_get_dirty_log()

2019-12-17 Thread Sean Christopherson
eed to add validity checks in the arch code that are technically unnecessary. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_pr.c | 6 +- arch/s390/kvm/kvm-s390.c | 12 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c

[PATCH v4 15/19] KVM: Provide common implementation for generic dirty log functions

2019-12-17 Thread Sean Christopherson
by the dirty log, i.e. to make it obvious in the code that the validity of the memslot is guaranteed, as a future patch will rework memslot handling such that id_to_memslot() can return NULL. Acked-by: Christoffer Dall Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/mips

[PATCH v4 19/19] KVM: selftests: Add test for KVM_SET_USER_MEMORY_REGION

2019-12-17 Thread Sean Christopherson
Add a KVM selftest to test moving the base gfn of a userspace memory region. The test is primarily targeted at x86 to verify its memslot metadata is correctly updated, but also provides basic functionality coverage on other architectures. Signed-off-by: Sean Christopherson --- tools/testing

[PATCH v4 09/19] KVM: Move setting of memslot into helper routine

2019-12-17 Thread Sean Christopherson
Split out the core functionality of setting a memslot into a separate helper in preparation for moving memslot deletion into its own routine. Tested-by: Christoffer Dall Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 106

[PATCH v4 17/19] KVM: Terminate memslot walks via used_slots

2019-12-17 Thread Sean Christopherson
be susceptible to casting shenanigans. Add function comments to update_memslots() and search_memslots() to explicitly (and loudly) state how memslots are sorted. No functional change intended. Tested-by: Christoffer Dall Tested-by: Marc Zyngier Signed-off-by: Sean Christopherson --- arch/powerpc

[PATCH v4 12/19] KVM: Move memslot deletion to helper function

2019-12-17 Thread Sean Christopherson
a memslot or changing its flags, e.g. x86 frees its arch specific memslot metadata during commit_memory_region(). Acked-by: Christoffer Dall Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 73 +++-- 1 file changed, 44

[PATCH v4 04/19] KVM: PPC: Move memslot memory allocation into prepare_memory_region()

2019-12-17 Thread Sean Christopherson
Mackerras Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 11 --- arch/powerpc/kvm/book3s.c | 12 arch/powerpc/kvm/book3s_hv.c | 25 - arch/powerpc/kvm/book3s_pr.c | 11 ++- arch/powerpc/kvm

[PATCH v4 05/19] KVM: x86: Allocate memslot resources during prepare_memory_region()

2019-12-17 Thread Sean Christopherson
. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 13 + 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 04d1bf89da0e..8c815b3587b4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm

[PATCH v4 07/19] KVM: Explicitly free allocated-but-unused dirty bitmap

2019-12-17 Thread Sean Christopherson
is guaranteed to succeed. Arch code can still fail, but it's responsible for its own cleanup in that case. Eliminating the error path's abuse of kvm_free_memslot() paves the way for simplifying kvm_free_memslot(), i.e. dropping its @dont param. Signed-off-by: Sean Christopherson --- virt/kvm

Re: [PATCH v4 01/19] KVM: x86: Allocate new rmap and large page tracking when moving memslot

2019-12-17 Thread Sean Christopherson
On Tue, Dec 17, 2019 at 04:56:40PM -0500, Peter Xu wrote: > On Tue, Dec 17, 2019 at 12:40:23PM -0800, Sean Christopherson wrote: > > Reallocate a rmap array and recalcuate large page compatibility when > > moving an existing memslot to correctly handle the alignment properties

Re: [PATCH v4 07/19] KVM: Explicitly free allocated-but-unused dirty bitmap

2019-12-17 Thread Sean Christopherson
On Tue, Dec 17, 2019 at 05:24:46PM -0500, Peter Xu wrote: > On Tue, Dec 17, 2019 at 12:40:29PM -0800, Sean Christopherson wrote: > > Explicitly free an allocated-but-unused dirty bitmap instead of relying > > on kvm_free_memslot() if an error occurs in __kvm_se

Re: [PATCH v3 00/15] KVM: Dynamically size memslot arrays

2019-12-03 Thread Sean Christopherson
On Thu, Oct 24, 2019 at 04:07:29PM -0700, Sean Christopherson wrote: > The end goal of this series is to dynamically size the memslot array so > that KVM allocates memory based on the number of memslots in use, as > opposed to unconditionally allocating memory for the maximum number of &

[PATCH v2 10/15] KVM: Simplify kvm_free_memslot() and all its descendents

2019-10-21 Thread Sean Christopherson
Now that all callers of kvm_free_memslot() pass NULL for @dont, remove the param from the top-level routine and all arch's implementations. No functional change intended. Signed-off-by: Sean Christopherson --- arch/mips/include/asm/kvm_host.h | 2 +- arch/powerpc/include/asm/kvm_ppc.h

[PATCH v2 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap

2019-10-21 Thread Sean Christopherson
is guaranteed to succeed. Arch code can still fail, but it's responsible for its own cleanup in that case. Eliminating the error path's abuse of kvm_free_memslot() paves the way for simplifying kvm_free_memslot(), i.e. dropping its @dont param. Signed-off-by: Sean Christopherson --- virt/kvm

[PATCH v2 12/15] KVM: Provide common implementation for generic dirty log functions

2019-10-21 Thread Sean Christopherson
by the dirty log, i.e. to make it obvious in the code that the validity of the memslot is guaranteed, as a future patch will rework memslot handling such that id_to_memslot() can return NULL. Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 62 ++--- arch

[PATCH v2 08/15] KVM: Move setting of memslot into helper routine

2019-10-21 Thread Sean Christopherson
Split out the core functionality of setting a memslot into a separate helper in preparation for moving memslot deletion into its own routine. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 106 ++-- 1 file changed, 63 insertions(+), 43

[PATCH v2 15/15] KVM: Dynamically size memslot array based on number of used slots

2019-10-21 Thread Sean Christopherson
reduced when deleting a memslot. However, consecutive deletions will realize the memory savings, i.e. a second deletion will trim the entry. Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 5 - virt/kvm/kvm_main.c | 31 --- 2 files changed, 32

[PATCH v2 03/15] KVM: PPC: Move memslot memory allocation into prepare_memory_region()

2019-10-21 Thread Sean Christopherson
Mackerras Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 8 ++-- arch/powerpc/kvm/book3s.c | 12 arch/powerpc/kvm/book3s_hv.c | 25 - arch/powerpc/kvm/book3s_pr.c | 11 ++- arch/powerpc/kvm/booke.c

[PATCH v2 05/15] KVM: Drop kvm_arch_create_memslot()

2019-10-21 Thread Sean Christopherson
Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 6 -- arch/powerpc/kvm/powerpc.c | 6 -- arch/s390/kvm/kvm-s390.c | 6 -- arch/x86/kvm/x86.c | 6 -- include/linux/kvm_host.h | 2 -- virt/kvm/arm/mmu.c | 6 -- virt/kvm/kvm_main.c

[PATCH v2 01/15] KVM: Reinstall old memslots if arch preparation fails

2019-10-21 Thread Sean Christopherson
: bc6678a33d9b9 ("KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update") Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 23 --- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm

[PATCH v2 00/15] KVM: Dynamically size memslot arrays

2019-10-21 Thread Sean Christopherson
are arch agnostic, in theory... v2: - Split "Drop kvm_arch_create_memslot()" into three patches to move minor functional changes to standalone patches [Janosch]. - Rebase to latest kvm/queue (f0574a1cea5b, "KVM: x86: fix ...") - Collect an Acked-by and a Reviewed-by Sea

[PATCH v2 04/15] KVM: x86: Allocate memslot resources during prepare_memory_region()

2019-10-21 Thread Sean Christopherson
code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f26f8be4e621..fa80f07ba501 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9601,6

[PATCH v2 09/15] KVM: Move memslot deletion to helper function

2019-10-21 Thread Sean Christopherson
a memslot or changing its flags, i.e. implement logic similar to the dirty bitmap is handling, if such functionality is needed in the future. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 73 +++-- 1 file changed, 44 insertions(+), 29 deletions

[PATCH v2 07/15] KVM: Refactor error handling for setting memory region

2019-10-21 Thread Sean Christopherson
Replace a big pile o' gotos with returns to make it more obvious what error code is being returned, and to prepare for refactoring the functional, i.e. post-checks, portion of __kvm_set_memory_region(). Reviewed-by: Janosch Frank Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 40

[PATCH v2 02/15] KVM: Don't free new memslot if allocation of said memslot fails

2019-10-21 Thread Sean Christopherson
in this case as there are no resources to be freed. No functional change intended. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9afd706dc038..2cb38b2148cb 100644

[PATCH v2 13/15] KVM: Ensure validity of memslot with respect to kvm_get_dirty_log()

2019-10-21 Thread Sean Christopherson
eed to add validity checks in the arch code that are technically unnecessary. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_pr.c | 6 +- arch/s390/kvm/kvm-s390.c | 12 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c

[PATCH v2 11/15] KVM: Clean up local variable usage in __kvm_set_memory_region()

2019-10-21 Thread Sean Christopherson
the initial memslot is not strictly necessary at this juncture, e.g. 'old' could be directly copied from id_to_memslot(), but keep the pointer usage as id_to_memslot() will be able to return a NULL pointer once memslots are dynamically sized. Signed-off-by: Sean Christopherson --- virt/kvm

[PATCH v2 14/15] KVM: Terminate memslot walks via used_slots

2019-10-21 Thread Sean Christopherson
be susceptible to casting shenanigans. Add function comments to update_memslots() and search_memslots() to explicitly (and loudly) state how memslots are sorted. No functional change intended. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_hv.c | 2 +- arch/x86/kvm/x86.c

[PATCH v3 13/15] KVM: Ensure validity of memslot with respect to kvm_get_dirty_log()

2019-10-24 Thread Sean Christopherson
eed to add validity checks in the arch code that are technically unnecessary. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_pr.c | 6 +- arch/s390/kvm/kvm-s390.c | 12 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c

[PATCH v3 12/15] KVM: Provide common implementation for generic dirty log functions

2019-10-24 Thread Sean Christopherson
by the dirty log, i.e. to make it obvious in the code that the validity of the memslot is guaranteed, as a future patch will rework memslot handling such that id_to_memslot() can return NULL. Acked-by: Christoffer Dall Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/mips

[PATCH v3 00/15] KVM: Dynamically size memslot arrays

2019-10-24 Thread Sean Christopherson
ed-by and a Reviewed-by Sean Christopherson (15): KVM: Reinstall old memslots if arch preparation fails KVM: Don't free new memslot if allocation of said memslot fails KVM: PPC: Move memslot memory allocation into prepare_memory_region() KVM: x86: Allocate memslot resources during prepare_m

[PATCH v3 15/15] KVM: Dynamically size memslot array based on number of used slots

2019-10-24 Thread Sean Christopherson
reduced when deleting a memslot. However, consecutive deletions will realize the memory savings, i.e. a second deletion will trim the entry. Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c | 31

[PATCH v3 14/15] KVM: Terminate memslot walks via used_slots

2019-10-24 Thread Sean Christopherson
be susceptible to casting shenanigans. Add function comments to update_memslots() and search_memslots() to explicitly (and loudly) state how memslots are sorted. No functional change intended. Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_hv.c | 2

[PATCH v3 03/15] KVM: PPC: Move memslot memory allocation into prepare_memory_region()

2019-10-24 Thread Sean Christopherson
Mackerras Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 11 --- arch/powerpc/kvm/book3s.c | 12 arch/powerpc/kvm/book3s_hv.c | 25 - arch/powerpc/kvm/book3s_pr.c | 11 ++- arch/powerpc/kvm

[PATCH v3 01/15] KVM: Reinstall old memslots if arch preparation fails

2019-10-24 Thread Sean Christopherson
: bc6678a33d9b9 ("KVM: introduce kvm->srcu and convert kvm_set_memory_region to SRCU update") Reviewed-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 23 --- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/virt/kvm/kvm_

[PATCH v3 08/15] KVM: Move setting of memslot into helper routine

2019-10-24 Thread Sean Christopherson
Split out the core functionality of setting a memslot into a separate helper in preparation for moving memslot deletion into its own routine. Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 106 ++-- 1 file

[PATCH v3 09/15] KVM: Move memslot deletion to helper function

2019-10-24 Thread Sean Christopherson
a memslot or changing its flags, i.e. implement logic similar to the dirty bitmap handling, if such functionality is needed in the future. Acked-by: Christoffer Dall Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 73

[PATCH v3 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap

2019-10-24 Thread Sean Christopherson
is guaranteed to succeed. Arch code can still fail, but it's responsible for its own cleanup in that case. Eliminating the error path's abuse of kvm_free_memslot() paves the way for simplifying kvm_free_memslot(), i.e. dropping its @dont param. Signed-off-by: Sean Christopherson --- virt/kvm

[PATCH v3 04/15] KVM: x86: Allocate memslot resources during prepare_memory_region()

2019-10-24 Thread Sean Christopherson
code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 19a0dc96beca..fc63b1f07ba9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9628,6

[PATCH v3 10/15] KVM: Simplify kvm_free_memslot() and all its descendents

2019-10-24 Thread Sean Christopherson
Now that all callers of kvm_free_memslot() pass NULL for @dont, remove the param from the top-level routine and all arch's implementations. No functional change intended. Tested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/mips/include/asm/kvm_host.h | 2 +- arch

[PATCH v3 07/15] KVM: Refactor error handling for setting memory region

2019-10-24 Thread Sean Christopherson
Replace a big pile o' gotos with returns to make it more obvious what error code is being returned, and to prepare for refactoring the functional, i.e. post-checks, portion of __kvm_set_memory_region(). Reviewed-by: Janosch Frank Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 40

[PATCH v3 11/15] KVM: Clean up local variable usage in __kvm_set_memory_region()

2019-10-24 Thread Sean Christopherson
the initial memslot is not strictly necessary at this juncture, e.g. 'old' could be directly copied from id_to_memslot(), but keep the pointer usage as id_to_memslot() will be able to return a NULL pointer once memslots are dynamically sized. Signed-off-by: Sean Christopherson --- virt/kvm

[PATCH v3 05/15] KVM: Drop kvm_arch_create_memslot()

2019-10-24 Thread Sean Christopherson
Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 6 -- arch/powerpc/kvm/powerpc.c | 6 -- arch/s390/kvm/kvm-s390.c | 6 -- arch/x86/kvm/x86.c | 6 -- include/linux/kvm_host.h | 2 -- virt/kvm/arm/mmu.c | 6 -- virt/kvm/kvm_main.c

[PATCH v3 02/15] KVM: Don't free new memslot if allocation of said memslot fails

2019-10-24 Thread Sean Christopherson
in this case as there are no resources to be freed. No functional change intended. Acked-by: Christoffer Dall Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 52deb5621501

Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots

2019-10-24 Thread Sean Christopherson
On Thu, Oct 24, 2019 at 10:24:09PM +0200, Paolo Bonzini wrote: > On 24/10/19 21:38, Sean Christopherson wrote: > > only > > * its new index into the array is update. > > s/update/tracked/? Ya, tracked is better. Waffled between updated and tracked, chose poorly :-) &g

Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots

2019-10-24 Thread Sean Christopherson
On Tue, Oct 22, 2019 at 05:53:27PM +0200, Paolo Bonzini wrote: > On 22/10/19 17:52, Sean Christopherson wrote: > > > > Anyways, I'm not at all opposed to adding comments, just want to make sure > > I'm not forgetting something. If it's ok with you, I'll comment the code

Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots

2019-10-24 Thread Sean Christopherson
On Thu, Oct 24, 2019 at 12:38:56PM -0700, Sean Christopherson wrote: > On Tue, Oct 22, 2019 at 05:53:27PM +0200, Paolo Bonzini wrote: > > On 22/10/19 17:52, Sean Christopherson wrote: > > > > > > Anyways, I'm not at all opposed to adding comments, just want to make su

Re: [PATCH v2 15/15] KVM: Dynamically size memslot array based on number of used slots

2019-10-22 Thread Sean Christopherson
On Tue, Oct 22, 2019 at 04:04:21PM +0200, Paolo Bonzini wrote: > On 22/10/19 02:35, Sean Christopherson wrote: > > + struct kvm_memory_slot memslots[]; > > + /* > > +* WARNING: 'memslots' is dynamically-sized. It *MUST* be at the end. > > +*/ > > Isn

Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots

2019-10-22 Thread Sean Christopherson
On Tue, Oct 22, 2019 at 05:30:58PM +0200, Paolo Bonzini wrote: > On 22/10/19 17:28, Sean Christopherson wrote: > > On Tue, Oct 22, 2019 at 04:04:18PM +0200, Paolo Bonzini wrote: > >> On 22/10/19 02:35, Sean Christopherson wrote: > >>> +static inline int kvm

Re: [PATCH v2 14/15] KVM: Terminate memslot walks via used_slots

2019-10-22 Thread Sean Christopherson
On Tue, Oct 22, 2019 at 04:04:18PM +0200, Paolo Bonzini wrote: > On 22/10/19 02:35, Sean Christopherson wrote: > > +static inline int kvm_shift_memslots_forward(struct kvm_memslots *slots, > > +struct kvm_memory_slot *new) > &

Re: [PATCH 42/45] KVM: arm64: Free sve_state via arm specific hook

2019-10-22 Thread Sean Christopherson
On Tue, Oct 22, 2019 at 01:43:42PM +0200, Christoffer Dall wrote: > On Mon, Oct 21, 2019 at 06:59:22PM -0700, Sean Christopherson wrote: > > Add an arm specific hook to free the arm64-only sve_state. Doing so > > eliminates the last functional code from kvm_arch_vcpu_uninit()

[PATCH 05/45] KVM: VMX: Use direct vcpu pointer during vCPU create/free

2019-10-21 Thread Sean Christopherson
off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 42 ++ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 501e88bd6204..70b8d15eb2c5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/

[PATCH 11/45] KVM: PPC: e500mc: Add build-time assert that vcpu is at offset 0

2019-10-21 Thread Sean Christopherson
for adding the extra assert is to provide visual confirmation of the correctness of moving vcpu allocation to common code. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/e500mc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c

[PATCH 12/45] KVM: PPC: Allocate vcpu struct in common PPC code

2019-10-21 Thread Sean Christopherson
. Remove the message from the build-time assertion regarding placement of the struct, as compatibility with the arch usercopy region is no longer the sole dependent on 'struct kvm_vcpu' being at offset zero. Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 7 --- arch

[PATCH 16/45] KVM: MIPS: Use kvm_vcpu_cache to allocate vCPUs

2019-10-21 Thread Sean Christopherson
For reasons unknown, MIPS configures the vCPU allocation cache but allocates vCPUs via kzalloc(). Allocate from the vCPU cache in preparation for moving vCPU allocation to common KVM code. Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 6 +++--- 1 file changed, 3 insertions

[PATCH 04/45] KVM: VMX: Allocate VPID after initializing VCPU

2019-10-21 Thread Sean Christopherson
. Note, the VPID is not consumed until KVM_RUN, slightly delaying its allocation should have no real function impact. VPID allocation was arbitrarily placed in the original patch, commit 2384d2b326408 ("KVM: VMX: Enable Virtual Processor Identification (VPID)"). Signed-off-by: Sean Chri

[PATCH 09/45] KVM: x86: Move allocation of pio_data page down a few lines

2019-10-21 Thread Sean Christopherson
consumed when KVM_RUN is invoked, i.e. moving its allocation has no real functional impact. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 33 + 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index

[PATCH 13/45] KVM: PPC: Book3S PR: Allocate book3s and shadow vcpu after common init

2019-10-21 Thread Sean Christopherson
the allocation has no real functional impact. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_pr.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index 1e6b83908668..a933ba60bc7c 100644

[PATCH 06/45] KVM: SVM: Use direct vcpu pointer during vCPU create/free

2019-10-21 Thread Sean Christopherson
off-by: Sean Christopherson --- arch/x86/kvm/svm.c | 30 -- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index e479ea9bc9da..2f66c52e1b5d 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2140,6 +214

[PATCH 10/45] KVM: x86: Move kvm_vcpu_init() invocation to common code

2019-10-21 Thread Sean Christopherson
by kvm_arch_destroy_vm(). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 13 +++-- arch/x86/kvm/vmx/vmx.c | 19 ++- arch/x86/kvm/x86.c | 20 +++- 4 files

[PATCH 17/45] KVM: MIPS: Drop kvm_arch_vcpu_free()

2019-10-21 Thread Sean Christopherson
Remove the superfluous kvm_arch_vcpu_free() as it is no longer called from commmon KVM code. Note, kvm_arch_vcpu_destroy() *is* called from common code, i.e. choosing which function to whack is not completely arbitrary. Signed-off-by: Sean Christopherson --- arch/mips/kvm/mips.c | 9

  1   2   3   4   5   6   7   8   9   >