Re: [PATCH kvm-unit-tests] arm: prevent compiler from using unaligned accesses

2019-09-11 Thread Andre Przywara
On Tue, 10 Sep 2019 20:15:19 +0200 Thomas Huth wrote: Hi, > On 05/09/2019 19.15, Andre Przywara wrote: > > The ARM architecture requires all accesses to device memory to be > > naturally aligned[1][2]. Normal memory does not have this strict > > requirement, and in fact many systems do ignore un

Re: [PATCH kvm-unit-tests] arm: prevent compiler from using unaligned accesses

2019-09-11 Thread Thomas Huth
On 11/09/2019 10.16, Andre Przywara wrote: > On Tue, 10 Sep 2019 20:15:19 +0200 > Thomas Huth wrote: > > Hi, > >> On 05/09/2019 19.15, Andre Przywara wrote: >>> The ARM architecture requires all accesses to device memory to be >>> naturally aligned[1][2]. Normal memory does not have this strict

Re: [PATCH kvm-unit-tests] arm: prevent compiler from using unaligned accesses

2019-09-11 Thread Thomas Huth
On 05/09/2019 19.15, Andre Przywara wrote: > The ARM architecture requires all accesses to device memory to be > naturally aligned[1][2]. Normal memory does not have this strict > requirement, and in fact many systems do ignore unaligned accesses > (by the means of clearing the A bit in SCTLR and a

Re: [PATCH 2/2] KVM: arm/arm64: Print the EC hex value with its exact width

2019-09-11 Thread Marc Zyngier
On Wed, 11 Sep 2019 03:33:36 +0100, Zenghui Yu wrote: > > EC is the bits [31:26] of ESR_ELx on arm64 (HSR on arm). Print the > hex value with its exact width (8). > > Signed-off-by: Zenghui Yu > --- > virt/kvm/arm/trace.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git

Re: [PATCH 2/2] KVM: arm/arm64: Print the EC hex value with its exact width

2019-09-11 Thread Zenghui Yu
Hi Marc, On 2019/9/11 16:31, Marc Zyngier wrote: On Wed, 11 Sep 2019 03:33:36 +0100, Zenghui Yu wrote: EC is the bits [31:26] of ESR_ELx on arm64 (HSR on arm). Print the hex value with its exact width (8). Signed-off-by: Zenghui Yu --- virt/kvm/arm/trace.h | 2 +- 1 file changed, 1 inser

Re: [PATCH 2/2] KVM: arm/arm64: Print the EC hex value with its exact width

2019-09-11 Thread Marc Zyngier
On Wed, 11 Sep 2019 10:19:05 +0100, Zenghui Yu wrote: > > Hi Marc, > > On 2019/9/11 16:31, Marc Zyngier wrote: > > On Wed, 11 Sep 2019 03:33:36 +0100, > > Zenghui Yu wrote: > >> > >> EC is the bits [31:26] of ESR_ELx on arm64 (HSR on arm). Print the > >> hex value with its exact width (8). > >

Re: [PATCH 1/2] KVM: arm/arm64: vgic: Use the appropriate TRACE_INCLUDE_PATH

2019-09-11 Thread Marc Zyngier
On Wed, 11 Sep 2019 03:33:35 +0100, Zenghui Yu wrote: > > Commit 49dfe94fe5ad ("KVM: arm/arm64: Fix TRACE_INCLUDE_PATH") fixes > TRACE_INCLUDE_PATH to the correct relative path to the define_trace.h > and explains why did the old one work. > > The same fix should be applied to virt/kvm/arm/vgic/

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

2019-09-11 Thread Sean Christopherson
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 memslots. On x86, each memslot consumes 88 bytes, and so with 2 address spaces of 512

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

2019-09-11 Thread Sean Christopherson
Remove kvm_arch_create_memslot() now that all arch implementations are effectively nops. Explicitly free an allocated-but-unused dirty bitmap instead of relying on kvm_free_memslot() now that setting a memslot can no longer fail after arch code has allocated memory. In practice this was already t

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

2019-09-11 Thread Sean Christopherson
Rework kvm_get_dirty_log() so that it "returns" the associated memslot on success. A future patch will rework memslot handling such that id_to_memslot() can return NULL, returning the memslot makes it more obvious that the validity of the memslot has been verified, i.e. precludes the need to add v

[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
Reinstall the old memslots if preparing the new memory region fails after invalidating a to-be-{re}moved memslot. Remove the superfluous 'old_memslots' variable so that it's somewhat clear that the error handling path needs to free the unused memslots, not simply the 'old' memslots. Fixes: bc6678

[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 10/13] KVM: Provide common implementation for generic dirty log functions

2019-09-11 Thread Sean Christopherson
Move the implementations of KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG for CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT into common KVM code. The arch specific implemenations are extremely similar, differing only in whether the dirty log needs to be sync'd from hardware (x86) and how the TLBs are flushe

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

2019-09-11 Thread Sean Christopherson
Move memslot deletion into its own routine so that the success path for other memslot updates does not need to use kvm_free_memslot(), i.e. can explicitly destroy the dirty bitmap when necessary. This paves the way for dropping @dont from kvm_free_memslot(), i.e. all callers now pass NULL for @don

[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 deleti

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

2019-09-11 Thread Sean Christopherson
Now that the memslot logic doesn't assume memslots are always non-NULL, dynamically size the array of memslots instead of unconditionally allocating memory for the maximum number of memslots. Note, because a to-be-deleted memslot must first be invalidated, the array size cannot be immediately redu

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

2019-09-11 Thread Sean Christopherson
Allocate the various metadata structures associated with a memslot during during kvm_arch_prepare_memory_region(), which paves the way for removing kvm_arch_create_memslot() altogether. Moving x86's memory allocation only changes the order of kernel memory allocations between x86 and common KVM co

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

2019-09-11 Thread Sean Christopherson
Allocate the rmap array during kvm_arch_prepare_memory_region() to pave the way for removing kvm_arch_create_memslot() altogether. Moving PPC's memory allocation only changes the order of kernel memory allocations between PPC and common KVM code. No functional change intended. Signed-off-by: Sea

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

2019-09-11 Thread Sean Christopherson
Refactor memslot handling to treat the number of used slots as the de facto size of the memslot array, e.g. return NULL from id_to_memslot() when an invalid index is provided instead of relying on npages==0 to detect an invalid memslot. Rework the sorting and walking of memslots in advance of dyna

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

2019-09-11 Thread Sean Christopherson
Clean up __kvm_set_memory_region() to achieve several goals: - Remove local variables that serve no real purpose - Improve the readability of the code - Better show the relationship between the 'old' and 'new' memslot - Prepare for dynamically sizing memslots. Note, using 'tmp' to hold th